puma 3.7.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puma might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/History.md +229 -1
- data/README.md +179 -212
- data/docs/architecture.md +37 -0
- data/{DEPLOYMENT.md → docs/deployment.md} +24 -4
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/plugins.md +28 -0
- data/docs/restart.md +41 -0
- data/docs/signals.md +56 -3
- data/docs/systemd.md +130 -37
- data/ext/puma_http11/PumaHttp11Service.java +2 -0
- data/ext/puma_http11/extconf.rb +8 -0
- data/ext/puma_http11/http11_parser.c +84 -84
- data/ext/puma_http11/http11_parser.rl +9 -9
- data/ext/puma_http11/mini_ssl.c +105 -9
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +13 -16
- data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +30 -6
- data/lib/puma.rb +10 -0
- data/lib/puma/accept_nonblock.rb +2 -0
- data/lib/puma/app/status.rb +13 -0
- data/lib/puma/binder.rb +33 -18
- data/lib/puma/cli.rb +48 -33
- data/lib/puma/client.rb +94 -22
- data/lib/puma/cluster.rb +69 -21
- data/lib/puma/commonlogger.rb +2 -0
- data/lib/puma/configuration.rb +134 -136
- data/lib/puma/const.rb +16 -2
- data/lib/puma/control_cli.rb +31 -18
- data/lib/puma/convenient.rb +5 -3
- data/lib/puma/daemon_ext.rb +2 -0
- data/lib/puma/delegation.rb +2 -0
- data/lib/puma/detect.rb +2 -0
- data/lib/puma/dsl.rb +349 -113
- data/lib/puma/events.rb +8 -4
- data/lib/puma/io_buffer.rb +3 -6
- data/lib/puma/jruby_restart.rb +2 -1
- data/lib/puma/launcher.rb +60 -36
- data/lib/puma/minissl.rb +85 -28
- data/lib/puma/null_io.rb +2 -0
- data/lib/puma/plugin.rb +2 -0
- data/lib/puma/plugin/tmp_restart.rb +3 -2
- data/lib/puma/rack/builder.rb +4 -1
- data/lib/puma/rack/urlmap.rb +2 -0
- data/lib/puma/rack_default.rb +2 -0
- data/lib/puma/reactor.rb +218 -30
- data/lib/puma/runner.rb +18 -4
- data/lib/puma/server.rb +149 -56
- data/lib/puma/single.rb +16 -5
- data/lib/puma/state_file.rb +2 -0
- data/lib/puma/tcp_logger.rb +2 -0
- data/lib/puma/thread_pool.rb +59 -6
- data/lib/puma/util.rb +2 -6
- data/lib/rack/handler/puma.rb +58 -19
- data/tools/jungle/README.md +12 -2
- data/tools/jungle/init.d/README.md +2 -0
- data/tools/jungle/init.d/puma +8 -8
- data/tools/jungle/init.d/run-puma +1 -1
- data/tools/jungle/rc.d/README.md +74 -0
- data/tools/jungle/rc.d/puma +61 -0
- data/tools/jungle/rc.d/puma.conf +10 -0
- data/tools/trickletest.rb +1 -1
- metadata +25 -85
- data/.github/issue_template.md +0 -20
- data/Gemfile +0 -12
- data/Manifest.txt +0 -77
- data/Rakefile +0 -158
- data/gemfiles/2.1-Gemfile +0 -12
- data/lib/puma/compat.rb +0 -14
- data/lib/puma/java_io_buffer.rb +0 -45
- data/lib/puma/rack/backports/uri/common_193.rb +0 -33
- data/puma.gemspec +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4564625669c77dfcd7e4096c40f8b24cb3b7b5a938b97309bbb193566ae0869e
|
4
|
+
data.tar.gz: 88ae06dc5193587a114ef4f6cec79ad8001333ef9b3fff5c839fd3eea75cf746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec7c5afdb5cb46e8827ad83c189240e426efab3aaf7b4ac9ef5b2d7977203a30495dd082c08b96299b6c050022da57af28065dfe37f5271e50138ab34e81512f
|
7
|
+
data.tar.gz: 81728699a0f8c0c135f72bd03b6fbb76c405f7bcc138a2f918a4abb6978334528e0e004851fa58da254e6c6abb074cc35401835d61d2a3b2e5d9f2134fd10dff
|
data/History.md
CHANGED
@@ -1,3 +1,222 @@
|
|
1
|
+
## Master
|
2
|
+
|
3
|
+
* Features
|
4
|
+
* Your feature goes here (#Github Number)
|
5
|
+
|
6
|
+
* Bugfixes
|
7
|
+
* Your bugfix goes here (#Github Number)
|
8
|
+
|
9
|
+
## 4.1.0 / 2019-08-08
|
10
|
+
|
11
|
+
* 4 features
|
12
|
+
* Add REQUEST_PATH on parse error message (#1831)
|
13
|
+
* You can now easily add custom log formatters with the `log_formatter` config option (#1816)
|
14
|
+
* Puma.stats now provides process start times (#1844)
|
15
|
+
* Add support for disabling TLSv1.1 (#1836)
|
16
|
+
|
17
|
+
* 7 bugfixes
|
18
|
+
* Fix issue where Puma was creating zombie process entries (#1887)
|
19
|
+
* Fix bugs with line-endings and chunked encoding (#1812)
|
20
|
+
* RACK_URL_SCHEME is now set correctly in all conditions (#1491)
|
21
|
+
* We no longer mutate global STDOUT/STDERR, particularly the sync setting (#1837)
|
22
|
+
* SSL read_nonblock no longer blocks (#1857)
|
23
|
+
* Swallow connection errors when sending early hints (#1822)
|
24
|
+
* Backtrace no longer dumped when invalid pumactl commands are run (#1863)
|
25
|
+
|
26
|
+
* 5 other
|
27
|
+
* Avoid casting worker_timeout twice (#1838)
|
28
|
+
* Removed a call to private that wasn't doing anything (#1882)
|
29
|
+
* README, Rakefile, docs and test cleanups (#1848, #1847, #1846, #1853, #1859, #1850, #1866, #1870, #1872, #1833, #1888)
|
30
|
+
* Puma.io has proper documentation now (https://puma.io/puma/)
|
31
|
+
* Added the Contributor Covenant CoC
|
32
|
+
|
33
|
+
* 1 known issue
|
34
|
+
* Some users are still experiencing issues surrounding socket activation and Unix sockets (#1842)
|
35
|
+
|
36
|
+
## 4.0.1 / 2019-07-11
|
37
|
+
|
38
|
+
* 2 bugfixes
|
39
|
+
* Fix socket removed after reload - should fix problems with systemd socket activation. (#1829)
|
40
|
+
* Add extconf tests for DTLS_method & TLS_server_method, use in minissl.rb. Should fix "undefined symbol: DTLS_method" when compiling against old OpenSSL versions. (#1832)
|
41
|
+
* 1 other
|
42
|
+
* Removed unnecessary RUBY_VERSION checks. (#1827)
|
43
|
+
|
44
|
+
## 4.0.0 / 2019-06-25
|
45
|
+
|
46
|
+
* 9 features
|
47
|
+
* Add support for disabling TLSv1.0 (#1562)
|
48
|
+
* Request body read time metric (#1569)
|
49
|
+
* Add out_of_band hook (#1648)
|
50
|
+
* Re-implement (native) IOBuffer for JRuby (#1691)
|
51
|
+
* Min worker timeout (#1716)
|
52
|
+
* Add option to suppress SignalException on SIGTERM (#1690)
|
53
|
+
* Allow mutual TLS CA to be set using `ssl_bind` DSL (#1689)
|
54
|
+
* Reactor now uses nio4r instead of `select` (#1728)
|
55
|
+
* Add status to pumactl with pidfile (#1824)
|
56
|
+
|
57
|
+
* 9 bugfixes
|
58
|
+
* Do not accept new requests on shutdown (#1685, #1808)
|
59
|
+
* Fix 3 corner cases when request body is chunked (#1508)
|
60
|
+
* Change pid existence check's condition branches (#1650)
|
61
|
+
* Don't call .stop on a server that doesn't exist (#1655)
|
62
|
+
* Implemented NID_X9_62_prime256v1 (P-256) curve over P-521 (#1671)
|
63
|
+
* Fix @notify.close can't modify frozen IOError (RuntimeError) (#1583)
|
64
|
+
* Fix Java 8 support (#1773)
|
65
|
+
* Fix error `uninitialized constant Puma::Cluster` (#1731)
|
66
|
+
* Fix `not_token` being able to be set to true (#1803)
|
67
|
+
|
68
|
+
## 3.12.1 / 2019-03-19
|
69
|
+
|
70
|
+
* 1 features
|
71
|
+
* Internal strings are frozen (#1649)
|
72
|
+
* 3 bugfixes
|
73
|
+
* Fix chunked ending check (#1607)
|
74
|
+
* Rack handler should use provided default host (#1700)
|
75
|
+
* Better support for detecting runtimes that support `fork` (#1630)
|
76
|
+
|
77
|
+
## 3.12.0 / 2018-07-13
|
78
|
+
|
79
|
+
* 5 features:
|
80
|
+
* You can now specify which SSL ciphers the server should support, default is unchanged (#1478)
|
81
|
+
* The setting for Puma's `max_threads` is now in `Puma.stats` (#1604)
|
82
|
+
* Pool capacity is now in `Puma.stats` (#1579)
|
83
|
+
* Installs restricted to Ruby 2.2+ (#1506)
|
84
|
+
* `--control` is now deprecated in favor of `--control-url` (#1487)
|
85
|
+
|
86
|
+
* 2 bugfixes:
|
87
|
+
* Workers will no longer accept more web requests than they have capacity to process. This prevents an issue where one worker would accept lots of requests while starving other workers (#1563)
|
88
|
+
* In a test env puma now emits the stack on an exception (#1557)
|
89
|
+
|
90
|
+
## 3.11.4 / 2018-04-12
|
91
|
+
|
92
|
+
* 2 features:
|
93
|
+
* Manage puma as a service using rc.d (#1529)
|
94
|
+
* Server stats are now available from a top level method (#1532)
|
95
|
+
* 5 bugfixes:
|
96
|
+
* Fix parsing CLI options (#1482)
|
97
|
+
* Order of stderr and stdout is made before redirecting to a log file (#1511)
|
98
|
+
* Init.d fix of `ps -p` to check if pid exists (#1545)
|
99
|
+
* Early hints bugfix (#1550)
|
100
|
+
* Purge interrupt queue when closing socket fails (#1553)
|
101
|
+
|
102
|
+
## 3.11.3 / 2018-03-05
|
103
|
+
|
104
|
+
* 3 bugfixes:
|
105
|
+
* Add closed? to MiniSSL::Socket for use in reactor (#1510)
|
106
|
+
* Handle EOFError at the toplevel of the server threads (#1524) (#1507)
|
107
|
+
* Deal with zero sized bodies when using SSL (#1483)
|
108
|
+
|
109
|
+
## 3.11.2 / 2018-01-19
|
110
|
+
|
111
|
+
* 1 bugfix:
|
112
|
+
* Deal with read\_nonblock returning nil early
|
113
|
+
|
114
|
+
## 3.11.1 / 2018-01-18
|
115
|
+
|
116
|
+
* 1 bugfix:
|
117
|
+
* Handle read\_nonblock returning nil when the socket close (#1502)
|
118
|
+
|
119
|
+
## 3.11.0 / 2017-11-20
|
120
|
+
|
121
|
+
* 2 features:
|
122
|
+
* HTTP 103 Early Hints (#1403)
|
123
|
+
* 421/451 status codes now have correct status messages attached (#1435)
|
124
|
+
|
125
|
+
* 9 bugfixes:
|
126
|
+
* Environment config files (/config/puma/<ENV>.rb) load correctly (#1340)
|
127
|
+
* Specify windows dependencies correctly (#1434, #1436)
|
128
|
+
* puma/events required in test helper (#1418)
|
129
|
+
* Correct control CLI's option help text (#1416)
|
130
|
+
* Remove a warning for unused variable in mini_ssl (#1409)
|
131
|
+
* Correct pumactl docs argument ordering (#1427)
|
132
|
+
* Fix an uninitialized variable warning in server.rb (#1430)
|
133
|
+
* Fix docs typo/error in Launcher init (#1429)
|
134
|
+
* Deal with leading spaces in RUBYOPT (#1455)
|
135
|
+
|
136
|
+
* 2 other:
|
137
|
+
* Add docs about internals (#1425, #1452)
|
138
|
+
* Tons of test fixes from @MSP-Greg (#1439, #1442, #1464)
|
139
|
+
|
140
|
+
## 3.10.0 / 2017-08-17
|
141
|
+
|
142
|
+
* 3 features:
|
143
|
+
* The status server has a new /gc and /gc-status command. (#1384)
|
144
|
+
* The persistent and first data timeouts are now configurable (#1111)
|
145
|
+
* Implemented RFC 2324 (#1392)
|
146
|
+
|
147
|
+
* 12 bugfixes:
|
148
|
+
* Not really a Puma bug, but @NickolasVashchenko created a gem to workaround a Ruby bug that some users of Puma may be experiencing. See README for more. (#1347)
|
149
|
+
* Fix hangups with SSL and persistent connections. (#1334)
|
150
|
+
* Fix Rails double-binding to a port (#1383)
|
151
|
+
* Fix incorrect thread names (#1368)
|
152
|
+
* Fix issues with /etc/hosts and JRuby where localhost addresses were not correct. (#1318)
|
153
|
+
* Fix compatibility with RUBYOPT="--enable-frozen-string-literal" (#1376)
|
154
|
+
* Fixed some compiler warnings (#1388)
|
155
|
+
* We actually run the integration tests in CI now (#1390)
|
156
|
+
* No longer shipping unnecessary directories in the gemfile (#1391)
|
157
|
+
* If RUBYOPT is nil, we no longer blow up on restart. (#1385)
|
158
|
+
* Correct response to SIGINT (#1377)
|
159
|
+
* Proper exit code returned when we receive a TERM signal (#1337)
|
160
|
+
|
161
|
+
* 3 refactors:
|
162
|
+
* Various test improvements from @grosser
|
163
|
+
* Rubocop (#1325)
|
164
|
+
* Hoe has been removed (#1395)
|
165
|
+
|
166
|
+
* 1 known issue:
|
167
|
+
* Socket activation doesn't work in JRuby. Their fault, not ours. (#1367)
|
168
|
+
|
169
|
+
## 3.9.1 / 2017-06-03
|
170
|
+
|
171
|
+
* 2 bugfixes:
|
172
|
+
* Fixed compatibility with older Bundler versions (#1314)
|
173
|
+
* Some internal test/development cleanup (#1311, #1313)
|
174
|
+
|
175
|
+
## 3.9.0 / 2017-06-01
|
176
|
+
|
177
|
+
* 2 features:
|
178
|
+
* The ENV is now reset to its original values when Puma restarts via USR1/USR2 (#1260) (MRI only, no JRuby support)
|
179
|
+
* Puma will no longer accept more clients than the maximum number of threads. (#1278)
|
180
|
+
|
181
|
+
* 9 bugfixes:
|
182
|
+
* Reduce information leakage by preventing HTTP parse errors from writing environment hashes to STDERR (#1306)
|
183
|
+
* Fix SSL/WebSocket compatibility (#1274)
|
184
|
+
* HTTP headers with empty values are no longer omitted from responses. (#1261)
|
185
|
+
* Fix a Rack env key which was set to nil. (#1259)
|
186
|
+
* peercert has been implemented for JRuby (#1248)
|
187
|
+
* Fix port settings when using rails s (#1277, #1290)
|
188
|
+
* Fix compat w/LibreSSL (#1285)
|
189
|
+
* Fix restarting Puma w/symlinks and a new Gemfile (#1282)
|
190
|
+
* Replace Dir.exists? with Dir.exist? (#1294)
|
191
|
+
|
192
|
+
* 1 known issue:
|
193
|
+
* A bug in MRI 2.2+ can result in IOError: stream closed. See #1206. This issue has existed since at least Puma 3.6, and probably further back.
|
194
|
+
|
195
|
+
* 1 refactor:
|
196
|
+
* Lots of test fixups from @grosser.
|
197
|
+
|
198
|
+
## 3.8.2 / 2017-03-14
|
199
|
+
|
200
|
+
* 1 bugfix:
|
201
|
+
* Deal with getsockopt with TCP\_INFO failing for sockets that say they're TCP but aren't really. (#1241)
|
202
|
+
|
203
|
+
## 3.8.1 / 2017-03-10
|
204
|
+
|
205
|
+
* 1 bugfix:
|
206
|
+
* Remove method call to method that no longer exists (#1239)
|
207
|
+
|
208
|
+
## 3.8.0 / 2017-03-09
|
209
|
+
|
210
|
+
* 2 bugfixes:
|
211
|
+
* Port from rack handler does not take precedence over config file in Rails 5.1.0.beta2+ and 5.0.1.rc3+ (#1234)
|
212
|
+
* The `tmp/restart.txt` plugin no longer restricts the user from running more than one server from the same folder at a time (#1226)
|
213
|
+
|
214
|
+
* 1 feature:
|
215
|
+
* Closed clients are aborted to save capacity (#1227)
|
216
|
+
|
217
|
+
* 1 refactor:
|
218
|
+
* Bundler is no longer a dependency from tests (#1213)
|
219
|
+
|
1
220
|
## 3.7.1 / 2017-02-20
|
2
221
|
|
3
222
|
* 2 bugfixes:
|
@@ -19,7 +238,7 @@
|
|
19
238
|
* Minor refactor on Thread pool (#1088)
|
20
239
|
* Removed a ton of unused constants, variables and files.
|
21
240
|
* Use MRI macros when allocating heap memory
|
22
|
-
* Use hooks for
|
241
|
+
* Use hooks for on\_booted event. (#1160)
|
23
242
|
|
24
243
|
* 14 bugfixes:
|
25
244
|
* Add eof? method to NullIO? (#1169)
|
@@ -1252,3 +1471,12 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
1252
1471
|
## 1.0.0 / 2012-03-29
|
1253
1472
|
|
1254
1473
|
* Released!
|
1474
|
+
|
1475
|
+
## Ignore - this is for maintainers to copy-paste during release
|
1476
|
+
## Master
|
1477
|
+
|
1478
|
+
* Features
|
1479
|
+
* Your feature goes here (#Github Number)
|
1480
|
+
|
1481
|
+
* Bugfixes
|
1482
|
+
* Your bugfix goes here (#Github Number)
|
data/README.md
CHANGED
@@ -1,179 +1,146 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<img src="https://puma.io/images/logos/puma-logo-large.png">
|
3
|
+
</p>
|
4
|
+
|
1
5
|
# Puma: A Ruby Web Server Built For Concurrency
|
2
6
|
|
3
7
|
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/puma/puma?utm\_source=badge&utm\_medium=badge&utm\_campaign=pr-badge)
|
4
|
-
[![Build Status](https://secure.travis-ci.org/puma/puma.svg)](
|
5
|
-
[![
|
8
|
+
[![Travis Build Status](https://secure.travis-ci.org/puma/puma.svg)](https://travis-ci.org/puma/puma)
|
9
|
+
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/0xnxc7a26u9b2bub/branch/master?svg=true)](https://ci.appveyor.com/project/puma/puma/branch/master)
|
6
10
|
[![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
|
11
|
+
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=puma&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=puma&package-manager=bundler&version-scheme=semver)
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications. Puma is intended for use in both development and production environments. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like Rubinius or JRuby.
|
13
|
+
Puma is a **simple, fast, multi-threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications**.
|
11
14
|
|
12
15
|
## Built For Speed & Concurrency
|
13
16
|
|
14
|
-
Puma
|
17
|
+
Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request using a thread pool. Each request is served in a separate thread, so truly concurrent Ruby implementations (JRuby, Rubinius) will use all available CPU cores.
|
15
18
|
|
16
|
-
|
19
|
+
Puma was designed to be the go-to server for [Rubinius](https://rubini.us), but also works well with JRuby and MRI.
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
On MRI, there is a Global Interpreter Lock (GIL) that ensures only one thread can be run at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing blocking IO to be run concurrently (EventMachine-based servers such as Thin turn off this ability, requiring you to use special libraries). Your mileage may vary. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like [Rubinius](http://rubini.us) or [JRuby](http://jruby.org).
|
21
|
+
On MRI, there is a Global VM Lock (GVL) that ensures only one thread can run Ruby code at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing IO waiting to be done in parallel.
|
21
22
|
|
22
23
|
## Quick Start
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Now you should have the `puma` command available in your PATH, so just do the following in the root folder of your Rack application:
|
29
|
-
|
30
|
-
$ puma app.ru
|
31
|
-
|
32
|
-
## Plugins
|
33
|
-
|
34
|
-
Puma 3.0 added support for plugins that can augment configuration and service operations.
|
35
|
-
|
36
|
-
2 canonical plugins to look to aid in development of further plugins:
|
37
|
-
|
38
|
-
* [tmp\_restart](https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb): Restarts the server if the file `tmp/restart.txt` is touched
|
39
|
-
* [heroku](https://github.com/puma/puma-heroku/blob/master/lib/puma/plugin/heroku.rb): Packages up the default configuration used by puma on Heroku
|
40
|
-
|
41
|
-
Plugins are activated in a puma configuration file (such as `config/puma.rb'`) by adding `plugin "name"`, such as `plugin "heroku"`.
|
42
|
-
|
43
|
-
Plugins are activated based simply on path requirements so, activating the `heroku` plugin will simply be doing `require "puma/plugin/heroku"`. This allows gems to provide multiple plugins (as well as unrelated gems to provide puma plugins).
|
44
|
-
|
45
|
-
The `tmp_restart` plugin is bundled with puma, so it can always be used.
|
46
|
-
|
47
|
-
To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
|
25
|
+
```
|
26
|
+
$ gem install puma
|
27
|
+
$ puma
|
28
|
+
```
|
48
29
|
|
49
|
-
|
30
|
+
Without arguments, puma will look for a rackup (.ru) file in the current working directory called `config.ru`.
|
50
31
|
|
51
|
-
|
32
|
+
## Frameworks
|
52
33
|
|
53
|
-
|
34
|
+
### Rails
|
54
35
|
|
55
|
-
|
36
|
+
Puma is the default server for Rails, included in the generated Gemfile.
|
56
37
|
|
57
|
-
|
38
|
+
Start your server with the `rails` command:
|
58
39
|
|
59
|
-
|
40
|
+
```
|
41
|
+
$ rails server
|
42
|
+
```
|
60
43
|
|
44
|
+
Many configuration options and Puma features are not available when using `rails server`. It is recommended that you use Puma's executable instead:
|
61
45
|
|
62
|
-
|
46
|
+
```
|
47
|
+
$ bundle exec puma
|
48
|
+
```
|
63
49
|
|
64
50
|
### Sinatra
|
65
51
|
|
66
52
|
You can run your Sinatra application with Puma from the command line like this:
|
67
53
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
require 'sinatra'
|
73
|
-
configure { set :server, :puma }
|
74
|
-
|
75
|
-
If you use Bundler, make sure you add Puma to your Gemfile (see below).
|
76
|
-
|
77
|
-
### Rails
|
78
|
-
|
79
|
-
First, make sure Puma is in your Gemfile:
|
80
|
-
|
81
|
-
gem 'puma'
|
82
|
-
|
83
|
-
Then start your server with the `rails` command:
|
84
|
-
|
85
|
-
$ rails s Puma
|
86
|
-
|
87
|
-
### Rackup
|
88
|
-
|
89
|
-
You can pass it as an option to `rackup`:
|
90
|
-
|
91
|
-
$ rackup -s Puma
|
54
|
+
```
|
55
|
+
$ ruby app.rb -s Puma
|
56
|
+
```
|
92
57
|
|
93
|
-
|
58
|
+
Or you can configure your Sinatra application to always use Puma:
|
94
59
|
|
95
|
-
|
60
|
+
```ruby
|
61
|
+
require 'sinatra'
|
62
|
+
configure { set :server, :puma }
|
63
|
+
```
|
96
64
|
|
97
65
|
## Configuration
|
98
66
|
|
99
|
-
Puma provides numerous options
|
67
|
+
Puma provides numerous options. Consult `puma -h` (or `puma --help`) for a full list of CLI options, or see [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb).
|
68
|
+
|
69
|
+
You can also find several configuration examples as part of the
|
70
|
+
[test](test/config) suite.
|
100
71
|
|
101
72
|
### Thread Pool
|
102
73
|
|
103
|
-
Puma
|
74
|
+
Puma uses a thread pool. You can set the minimum and maximum number of threads that are available in the pool with the `-t` (or `--threads`) flag:
|
75
|
+
|
76
|
+
```
|
77
|
+
$ puma -t 8:32
|
78
|
+
```
|
104
79
|
|
105
|
-
|
80
|
+
Puma will automatically scale the number of threads, from the minimum until it caps out at the maximum, based on how much traffic is present. The current default is `0:16`. Feel free to experiment, but be careful not to set the number of maximum threads to a large number, as you may exhaust resources on the system (or cause contention for the Global VM Lock, when using MRI).
|
106
81
|
|
107
|
-
|
82
|
+
Be aware that additionally Puma creates threads on its own for internal purposes (e.g. handling slow clients). So, even if you specify -t 1:1, expect around 7 threads created in your application.
|
108
83
|
|
109
84
|
### Clustered mode
|
110
85
|
|
111
|
-
Puma
|
86
|
+
Puma also offers "clustered mode". Clustered mode `fork`s workers from a master process. Each child process still has its own thread pool. You can tune the number of workers with the `-w` (or `--workers`) flag:
|
112
87
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
Note that threads are still used in clustered mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will be 32 threads.
|
88
|
+
```
|
89
|
+
$ puma -t 8:32 -w 3
|
90
|
+
```
|
117
91
|
|
118
|
-
|
92
|
+
Note that threads are still used in clustered mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will spawn 32 threads in total, with 16 in each worker process.
|
119
93
|
|
120
|
-
|
121
|
-
$ puma -t 8:32 -w 3 --preload
|
94
|
+
In clustered mode, Puma can "preload" your application. This loads all the application code *prior* to forking. Preloading reduces total memory usage of your application via an operating system feature called [copy-on-write](https://en.wikipedia.org/wiki/Copy-on-write) (Ruby 2.0+ only). Use the `--preload` flag from the command line:
|
122
95
|
|
123
|
-
|
96
|
+
```
|
97
|
+
$ puma -w 3 --preload
|
98
|
+
```
|
124
99
|
|
125
|
-
|
100
|
+
If you're using a configuration file, use the `preload_app!` method:
|
126
101
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
102
|
+
```ruby
|
103
|
+
# config/puma.rb
|
104
|
+
workers 3
|
105
|
+
preload_app!
|
106
|
+
```
|
131
107
|
|
132
108
|
Additionally, you can specify a block in your configuration file that will be run on boot of each worker:
|
133
109
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
110
|
+
```ruby
|
111
|
+
# config/puma.rb
|
112
|
+
on_worker_boot do
|
113
|
+
# configuration here
|
114
|
+
end
|
115
|
+
```
|
138
116
|
|
139
117
|
This code can be used to setup the process before booting the application, allowing
|
140
118
|
you to do some Puma-specific things that you don't want to embed in your application.
|
141
|
-
For instance, you could fire a log notification that a worker booted or send something to statsd.
|
142
|
-
This can be called multiple times to add hooks.
|
119
|
+
For instance, you could fire a log notification that a worker booted or send something to statsd. This can be called multiple times.
|
143
120
|
|
144
121
|
If you're preloading your application and using ActiveRecord, it's recommended that you setup your connection pool here:
|
145
122
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
# config/puma.rb
|
156
|
-
before_fork do
|
157
|
-
# configuration here
|
158
|
-
end
|
159
|
-
|
160
|
-
This code can be used to clean up before forking to clients, allowing
|
161
|
-
you to do some Puma-specific things that you don't want to embed in your application.
|
162
|
-
|
163
|
-
If you're preloading your application and using ActiveRecord, it's recommended that you close any connections to the database here to prevent connection leakage:
|
164
|
-
|
165
|
-
# config/puma.rb
|
166
|
-
before_fork do
|
167
|
-
ActiveRecord::Base.connection_pool.disconnect!
|
168
|
-
end
|
123
|
+
```ruby
|
124
|
+
# config/puma.rb
|
125
|
+
on_worker_boot do
|
126
|
+
ActiveSupport.on_load(:active_record) do
|
127
|
+
ActiveRecord::Base.establish_connection
|
128
|
+
end
|
129
|
+
end
|
130
|
+
```
|
169
131
|
|
170
|
-
|
132
|
+
`before_fork` specifies a block to be run before workers are forked:
|
171
133
|
|
172
|
-
|
134
|
+
```ruby
|
135
|
+
# config/puma.rb
|
136
|
+
before_fork do
|
137
|
+
# configuration here
|
138
|
+
end
|
139
|
+
```
|
173
140
|
|
174
|
-
|
141
|
+
Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preload_app copies the code of master into the workers.
|
175
142
|
|
176
|
-
### Error
|
143
|
+
### Error handling
|
177
144
|
|
178
145
|
If puma encounters an error outside of the context of your application, it will respond with a 500 and a simple
|
179
146
|
textual error message (see `lowlevel_error` in [this file](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
|
@@ -189,165 +156,165 @@ end
|
|
189
156
|
|
190
157
|
### Binding TCP / Sockets
|
191
158
|
|
192
|
-
|
159
|
+
Bind Puma to a socket with the `-b` (or `--bind`) flag:
|
193
160
|
|
194
|
-
|
161
|
+
```
|
162
|
+
$ puma -b tcp://127.0.0.1:9292
|
163
|
+
```
|
195
164
|
|
196
|
-
|
165
|
+
To use a UNIX Socket instead of TCP:
|
197
166
|
|
198
|
-
|
167
|
+
```
|
168
|
+
$ puma -b unix:///var/run/puma.sock
|
169
|
+
```
|
199
170
|
|
200
171
|
If you need to change the permissions of the UNIX socket, just add a umask parameter:
|
201
172
|
|
202
|
-
|
173
|
+
```
|
174
|
+
$ puma -b 'unix:///var/run/puma.sock?umask=0111'
|
175
|
+
```
|
203
176
|
|
204
|
-
Need a bit of security? Use SSL sockets
|
177
|
+
Need a bit of security? Use SSL sockets:
|
205
178
|
|
206
|
-
|
179
|
+
```
|
180
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
|
181
|
+
```
|
207
182
|
|
208
|
-
|
183
|
+
#### Controlling SSL Cipher Suites
|
209
184
|
|
210
|
-
|
185
|
+
To use or avoid specific SSL cipher suites, use `ssl_cipher_filter` or `ssl_cipher_list` options.
|
211
186
|
|
212
|
-
|
187
|
+
##### Ruby:
|
213
188
|
|
214
|
-
|
189
|
+
```
|
190
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA'
|
191
|
+
```
|
215
192
|
|
216
|
-
|
193
|
+
##### JRuby:
|
217
194
|
|
218
|
-
|
195
|
+
```
|
196
|
+
$ puma -b 'ssl://127.0.0.1:9292?keystore=path_to_keystore&keystore-pass=keystore_password&ssl_cipher_list=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA'
|
197
|
+
```
|
219
198
|
|
220
|
-
|
199
|
+
See https://www.openssl.org/docs/man1.0.2/apps/ciphers.html for cipher filter format and full list of cipher suites.
|
221
200
|
|
222
|
-
|
201
|
+
Disable TLS v1 with the `no_tlsv1` option:
|
223
202
|
|
224
|
-
|
203
|
+
```
|
204
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true'
|
205
|
+
```
|
225
206
|
|
226
|
-
|
207
|
+
### Control/Status Server
|
227
208
|
|
228
|
-
|
209
|
+
Puma has a built-in status and control app that can be used to query and control Puma.
|
229
210
|
|
230
|
-
|
211
|
+
```
|
212
|
+
$ puma --control-url tcp://127.0.0.1:9293 --control-token foo
|
213
|
+
```
|
231
214
|
|
232
|
-
|
215
|
+
Puma will start the control server on localhost port 9293. All requests to the control server will need to include control token (in this case, `token=foo`) as a query parameter. This allows for simple authentication. Check out [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the status app has available.
|
233
216
|
|
234
|
-
|
217
|
+
You can also interact with the control server via `pumactl`. This command will restart Puma:
|
235
218
|
|
236
|
-
|
219
|
+
```
|
220
|
+
$ pumactl --control-url 'tcp://127.0.0.1:9293' --control-token foo restart
|
221
|
+
```
|
237
222
|
|
238
|
-
|
223
|
+
To see a list of `pumactl` options, use `pumactl --help`.
|
239
224
|
|
240
|
-
|
225
|
+
### Configuration File
|
241
226
|
|
242
|
-
|
243
|
-
* Use the status server and issue `/restart`
|
227
|
+
You can also provide a configuration file with the `-C` (or `--config`) flag:
|
244
228
|
|
245
|
-
|
229
|
+
```
|
230
|
+
$ puma -C /path/to/config
|
231
|
+
```
|
232
|
+
|
233
|
+
If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` environment variable, Puma looks for configuration at `config/puma/<environment_name>.rb`.
|
246
234
|
|
247
|
-
If
|
235
|
+
If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:
|
248
236
|
|
249
|
-
|
237
|
+
```
|
238
|
+
$ puma -C "-"
|
239
|
+
```
|
250
240
|
|
251
|
-
|
241
|
+
Check out [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb) to see all available options.
|
252
242
|
|
253
|
-
|
243
|
+
## Restart
|
254
244
|
|
255
|
-
|
245
|
+
Puma includes the ability to restart itself. When available (MRI, Rubinius, JRuby), Puma performs a "hot restart". This is the same functionality available in *Unicorn* and *NGINX* which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.
|
256
246
|
|
257
|
-
|
247
|
+
For more, see the [restart documentation](https://github.com/puma/puma/blob/master/docs/restart.md).
|
258
248
|
|
259
|
-
|
249
|
+
## Signals
|
260
250
|
|
261
|
-
|
251
|
+
Puma responds to several signals. A detailed guide to using UNIX signals with Puma can be found in the [signals documentation](https://github.com/puma/puma/blob/master/docs/signals.md).
|
262
252
|
|
263
|
-
|
253
|
+
## Platform Constraints
|
264
254
|
|
265
|
-
|
266
|
-
- `TTOU` decrement the worker count by 1
|
267
|
-
- `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
|
268
|
-
- `USR2` restart workers
|
269
|
-
- `USR1` restart workers in phases, a rolling restart.
|
270
|
-
- `HUP` reopen log files defined in stdout_redirect configuration parameter
|
271
|
-
- `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
|
272
|
-
- `CHLD`
|
255
|
+
Some platforms do not support all Puma features.
|
273
256
|
|
274
|
-
|
257
|
+
* **JRuby**, **Windows**: server sockets are not seamless on restart, they must be closed and reopened. These platforms have no way to pass descriptors into a new process that is exposed to Ruby. Also, cluster mode is not supported due to a lack of fork(2).
|
258
|
+
* **Windows**: Cluster mode is not supported due to a lack of fork(2).
|
275
259
|
|
276
|
-
|
260
|
+
## Known Bugs
|
277
261
|
|
278
|
-
|
262
|
+
For MRI versions 2.2.7, 2.2.8, 2.2.9, 2.2.10 2.3.4 and 2.4.1, you may see ```stream closed in another thread (IOError)```. It may be caused by a [Ruby bug](https://bugs.ruby-lang.org/issues/13632). It can be fixed with the gem https://rubygems.org/gems/stopgap_13632:
|
279
263
|
|
280
264
|
```ruby
|
281
|
-
|
282
|
-
|
283
|
-
|
265
|
+
if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
|
266
|
+
begin
|
267
|
+
require 'stopgap_13632'
|
268
|
+
rescue LoadError
|
269
|
+
end
|
270
|
+
end
|
284
271
|
```
|
285
272
|
|
286
|
-
|
287
|
-
|
288
|
-
Puma isn't able to understand all the resources that your app may use, so it provides a hook in the configuration file you pass to `-C` called `on_restart`. The block passed to `on_restart` will be called, unsurprisingly, just before Puma restarts itself.
|
289
|
-
|
290
|
-
You should place code to close global log files, redis connections, etc in this block so that their file descriptors don't leak into the restarted process. Failure to do so will result in slowly running out of descriptors and eventually obscure crashes as the server is restarted many times.
|
273
|
+
## Deployment
|
291
274
|
|
292
|
-
|
275
|
+
Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
|
293
276
|
|
294
|
-
|
295
|
-
|
296
|
-
* **JRuby**, **Windows**: server sockets are not seamless on restart, they must be closed and reopened. These platforms have no way to pass descriptors into a new process that is exposed to ruby
|
297
|
-
* **JRuby**, **Windows**: cluster mode is not supported due to a lack of fork(2)
|
298
|
-
* **Windows**: daemon mode is not supported due to a lack of fork(2)
|
299
|
-
|
300
|
-
## pumactl
|
301
|
-
|
302
|
-
`pumactl` is a simple CLI frontend to the control/status app described above. Please refer to `pumactl --help` for available commands.
|
303
|
-
|
304
|
-
## Process Monitors
|
305
|
-
|
306
|
-
Process monitors or supervisors will at minimum provide start of Puma
|
307
|
-
on system boot. Modern process monitors like systemd or upstart
|
308
|
-
further provide continuous monitoring and restarts for increased
|
277
|
+
It is common to use process monitors with Puma. Modern process monitors like systemd or upstart
|
278
|
+
provide continuous monitoring and restarts for increased
|
309
279
|
reliability in production environments:
|
310
280
|
|
311
281
|
* [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for sysvinit (init.d) and upstart
|
312
282
|
* [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
|
313
283
|
|
314
|
-
##
|
284
|
+
## Community Plugins
|
315
285
|
|
316
|
-
|
286
|
+
* [puma-heroku](https://github.com/evanphx/puma-heroku) — default Puma configuration for running on Heroku
|
287
|
+
* [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
|
288
|
+
* [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
|
289
|
+
* [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog
|
317
290
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
And then execute:
|
291
|
+
## Contributing
|
292
|
+
|
293
|
+
To run the test suite:
|
322
294
|
|
323
295
|
```bash
|
324
|
-
bundle
|
296
|
+
$ bundle install
|
297
|
+
$ bundle exec rake
|
325
298
|
```
|
326
299
|
|
327
|
-
|
300
|
+
To run a single test file, use the `TEST` environment variable:
|
328
301
|
|
329
|
-
```
|
330
|
-
|
302
|
+
```bash
|
303
|
+
$ TEST=test/test_binder.rb bundle exec rake test
|
331
304
|
```
|
332
305
|
|
333
|
-
|
306
|
+
Or use [`m`](https://github.com/qrush/m):
|
334
307
|
|
335
|
-
```
|
336
|
-
$ bundle exec
|
337
|
-
$ bundle exec cap puma:restart
|
338
|
-
$ bundle exec cap puma:stop
|
339
|
-
$ bundle exec cap puma:phased-restart
|
308
|
+
```
|
309
|
+
$ bundle exec m test/test_binder.rb
|
340
310
|
```
|
341
311
|
|
342
|
-
|
343
|
-
|
344
|
-
To run the test suite:
|
312
|
+
Which can also be used to run a single test case:
|
345
313
|
|
346
|
-
```
|
347
|
-
$ bundle
|
348
|
-
$ bundle exec rake
|
314
|
+
```
|
315
|
+
$ bundle exec m test/test_binder.rb:37
|
349
316
|
```
|
350
317
|
|
351
318
|
## License
|
352
319
|
|
353
|
-
Puma is copyright
|
320
|
+
Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.
|