puma 3.9.1 → 4.3.1
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 +232 -0
- data/README.md +162 -224
- 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 +38 -0
- data/docs/restart.md +41 -0
- data/docs/signals.md +56 -3
- data/docs/systemd.md +130 -37
- data/docs/tcp_mode.md +96 -0
- data/ext/puma_http11/PumaHttp11Service.java +2 -0
- data/ext/puma_http11/extconf.rb +13 -0
- data/ext/puma_http11/http11_parser.c +115 -140
- data/ext/puma_http11/http11_parser.java.rl +21 -37
- data/ext/puma_http11/http11_parser.rl +9 -9
- data/ext/puma_http11/http11_parser_common.rl +3 -3
- data/ext/puma_http11/mini_ssl.c +104 -8
- data/ext/puma_http11/org/jruby/puma/Http11.java +106 -114
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +90 -108
- data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +21 -4
- data/ext/puma_http11/puma_http11.c +2 -0
- data/lib/puma.rb +16 -0
- data/lib/puma/accept_nonblock.rb +7 -1
- data/lib/puma/app/status.rb +40 -26
- data/lib/puma/binder.rb +57 -74
- data/lib/puma/cli.rb +26 -7
- data/lib/puma/client.rb +243 -190
- data/lib/puma/cluster.rb +78 -34
- data/lib/puma/commonlogger.rb +2 -0
- data/lib/puma/configuration.rb +24 -16
- data/lib/puma/const.rb +36 -18
- data/lib/puma/control_cli.rb +46 -19
- data/lib/puma/detect.rb +2 -0
- data/lib/puma/dsl.rb +329 -68
- data/lib/puma/events.rb +6 -1
- data/lib/puma/io_buffer.rb +3 -6
- data/lib/puma/jruby_restart.rb +2 -1
- data/lib/puma/launcher.rb +120 -58
- data/lib/puma/minissl.rb +69 -27
- data/lib/puma/minissl/context_builder.rb +76 -0
- data/lib/puma/null_io.rb +2 -0
- data/lib/puma/plugin.rb +7 -2
- data/lib/puma/plugin/tmp_restart.rb +2 -1
- 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 +224 -34
- data/lib/puma/runner.rb +25 -4
- data/lib/puma/server.rb +148 -62
- 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 +61 -38
- data/lib/puma/util.rb +2 -6
- data/lib/rack/handler/puma.rb +10 -4
- data/tools/docker/Dockerfile +16 -0
- 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 -2
- metadata +29 -56
- data/.github/issue_template.md +0 -20
- data/Gemfile +0 -14
- data/Manifest.txt +0 -78
- data/Rakefile +0 -165
- data/Release.md +0 -9
- data/gemfiles/2.1-Gemfile +0 -12
- data/lib/puma/compat.rb +0 -14
- data/lib/puma/convenient.rb +0 -23
- data/lib/puma/daemon_ext.rb +0 -31
- data/lib/puma/delegation.rb +0 -11
- data/lib/puma/java_io_buffer.rb +0 -45
- data/lib/puma/rack/backports/uri/common_193.rb +0 -33
- data/puma.gemspec +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0c3e9fdfe5225baf88ff5ee9ec6f58201a220a482d72e5217309964a22b7ccc0
|
4
|
+
data.tar.gz: 541ad3a7311662ca31e3de234870b03d6aac3eb925c8ad04e7a857bac097edc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dc3a1d604212819aa8dc549b767cf00e3c237c95f0053ec61f6750666097980a1fbd2c350b1c47e59a1047d1a0bb35451914629f2829a66ded20a930939a60e
|
7
|
+
data.tar.gz: f906230de96dd55841faaf6968939b4a096acb9933e91b34c8aada201e1c5e259c567ce8dce744490093072f6cb9d9553b7d83752e07ec7502973c72990563d4
|
data/History.md
CHANGED
@@ -1,3 +1,226 @@
|
|
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.3.1 and 3.12.2 / 2019-12-05
|
10
|
+
|
11
|
+
* Security
|
12
|
+
* Fix: a poorly-behaved client could use keepalive requests to monopolize Puma's reactor and create a denial of service attack. CVE-2019-16770.
|
13
|
+
|
14
|
+
## 4.3.0 / 2019-11-07
|
15
|
+
|
16
|
+
* Features
|
17
|
+
* Strip whitespace at end of HTTP headers (#2010)
|
18
|
+
* Optimize HTTP parser for JRuby (#2012)
|
19
|
+
* Add SSL support for the control app and cli (#2046, #2052)
|
20
|
+
|
21
|
+
* Bugfixes
|
22
|
+
* Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564)
|
23
|
+
* Fix pumactl defaulting puma to development if an environment was not specified (#2035)
|
24
|
+
* Fix closing file stream when reading pid from pidfile (#2048)
|
25
|
+
* Fix a typo in configuration option `--extra_runtime_dependencies` (#2050)
|
26
|
+
|
27
|
+
## 4.2.1 / 2019-10-07
|
28
|
+
|
29
|
+
* 3 bugfixes
|
30
|
+
* Fix socket activation of systemd (pre-existing) unix binder files (#1842, #1988)
|
31
|
+
* Deal with multiple calls to bind correctly (#1986, #1994, #2006)
|
32
|
+
* Accepts symbols for `verify_mode` (#1222)
|
33
|
+
|
34
|
+
## 4.2.0 / 2019-09-23
|
35
|
+
|
36
|
+
* 6 features
|
37
|
+
* Pumactl has a new -e environment option and reads `config/puma/<environment>.rb` config files (#1885)
|
38
|
+
* Semicolons are now allowed in URL paths (MRI only), useful for Angular or Redmine (#1934)
|
39
|
+
* Allow extra dependencies to be defined when using prune_bundler (#1105)
|
40
|
+
* Puma now reports the correct port when binding to port 0, also reports other listeners when binding to localhost (#1786)
|
41
|
+
* Sending SIGINFO to any Puma worker now prints currently active threads and their backtraces (#1320)
|
42
|
+
* Puma threads all now have their name set on Ruby 2.3+ (#1968)
|
43
|
+
* 4 bugfixes
|
44
|
+
* Fix some misbehavior with phased restart and externally SIGTERMed workers (#1908, #1952)
|
45
|
+
* Fix socket closing on error (#1941)
|
46
|
+
* Removed unnecessary SIGINT trap for JRuby that caused some race conditions (#1961)
|
47
|
+
* Fix socket files being left around after process stopped (#1970)
|
48
|
+
* Absolutely thousands of lines of test improvements and fixes thanks to @MSP-Greg
|
49
|
+
|
50
|
+
## 4.1.1 / 2019-09-05
|
51
|
+
|
52
|
+
* 3 bugfixes
|
53
|
+
* Revert our attempt to not dup STDOUT/STDERR (#1946)
|
54
|
+
* Fix socket close on error (#1941)
|
55
|
+
* Fix workers not shutting down correctly (#1908)
|
56
|
+
|
57
|
+
## 4.1.0 / 2019-08-08
|
58
|
+
|
59
|
+
* 4 features
|
60
|
+
* Add REQUEST_PATH on parse error message (#1831)
|
61
|
+
* You can now easily add custom log formatters with the `log_formatter` config option (#1816)
|
62
|
+
* Puma.stats now provides process start times (#1844)
|
63
|
+
* Add support for disabling TLSv1.1 (#1836)
|
64
|
+
|
65
|
+
* 7 bugfixes
|
66
|
+
* Fix issue where Puma was creating zombie process entries (#1887)
|
67
|
+
* Fix bugs with line-endings and chunked encoding (#1812)
|
68
|
+
* RACK_URL_SCHEME is now set correctly in all conditions (#1491)
|
69
|
+
* We no longer mutate global STDOUT/STDERR, particularly the sync setting (#1837)
|
70
|
+
* SSL read_nonblock no longer blocks (#1857)
|
71
|
+
* Swallow connection errors when sending early hints (#1822)
|
72
|
+
* Backtrace no longer dumped when invalid pumactl commands are run (#1863)
|
73
|
+
|
74
|
+
* 5 other
|
75
|
+
* Avoid casting worker_timeout twice (#1838)
|
76
|
+
* Removed a call to private that wasn't doing anything (#1882)
|
77
|
+
* README, Rakefile, docs and test cleanups (#1848, #1847, #1846, #1853, #1859, #1850, #1866, #1870, #1872, #1833, #1888)
|
78
|
+
* Puma.io has proper documentation now (https://puma.io/puma/)
|
79
|
+
* Added the Contributor Covenant CoC
|
80
|
+
|
81
|
+
* 1 known issue
|
82
|
+
* Some users are still experiencing issues surrounding socket activation and Unix sockets (#1842)
|
83
|
+
|
84
|
+
## 4.0.1 / 2019-07-11
|
85
|
+
|
86
|
+
* 2 bugfixes
|
87
|
+
* Fix socket removed after reload - should fix problems with systemd socket activation. (#1829)
|
88
|
+
* 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)
|
89
|
+
* 1 other
|
90
|
+
* Removed unnecessary RUBY_VERSION checks. (#1827)
|
91
|
+
|
92
|
+
## 4.0.0 / 2019-06-25
|
93
|
+
|
94
|
+
* 9 features
|
95
|
+
* Add support for disabling TLSv1.0 (#1562)
|
96
|
+
* Request body read time metric (#1569)
|
97
|
+
* Add out_of_band hook (#1648)
|
98
|
+
* Re-implement (native) IOBuffer for JRuby (#1691)
|
99
|
+
* Min worker timeout (#1716)
|
100
|
+
* Add option to suppress SignalException on SIGTERM (#1690)
|
101
|
+
* Allow mutual TLS CA to be set using `ssl_bind` DSL (#1689)
|
102
|
+
* Reactor now uses nio4r instead of `select` (#1728)
|
103
|
+
* Add status to pumactl with pidfile (#1824)
|
104
|
+
|
105
|
+
* 10 bugfixes
|
106
|
+
* Do not accept new requests on shutdown (#1685, #1808)
|
107
|
+
* Fix 3 corner cases when request body is chunked (#1508)
|
108
|
+
* Change pid existence check's condition branches (#1650)
|
109
|
+
* Don't call .stop on a server that doesn't exist (#1655)
|
110
|
+
* Implemented NID_X9_62_prime256v1 (P-256) curve over P-521 (#1671)
|
111
|
+
* Fix @notify.close can't modify frozen IOError (RuntimeError) (#1583)
|
112
|
+
* Fix Java 8 support (#1773)
|
113
|
+
* Fix error `uninitialized constant Puma::Cluster` (#1731)
|
114
|
+
* Fix `not_token` being able to be set to true (#1803)
|
115
|
+
* Fix "Hang on SIGTERM with ruby 2.6 in clustered mode" ([PR #1741], [#1674], [#1720], [#1730], [#1755])
|
116
|
+
|
117
|
+
[PR #1741]: https://github.com/puma/puma/pull/1741
|
118
|
+
[#1674]: https://github.com/puma/puma/issues/1674
|
119
|
+
[#1720]: https://github.com/puma/puma/issues/1720
|
120
|
+
[#1730]: https://github.com/puma/puma/issues/1730
|
121
|
+
[#1755]: https://github.com/puma/puma/issues/1755
|
122
|
+
|
123
|
+
## 3.12.1 / 2019-03-19
|
124
|
+
|
125
|
+
* 1 features
|
126
|
+
* Internal strings are frozen (#1649)
|
127
|
+
* 3 bugfixes
|
128
|
+
* Fix chunked ending check (#1607)
|
129
|
+
* Rack handler should use provided default host (#1700)
|
130
|
+
* Better support for detecting runtimes that support `fork` (#1630)
|
131
|
+
|
132
|
+
## 3.12.0 / 2018-07-13
|
133
|
+
|
134
|
+
* 5 features:
|
135
|
+
* You can now specify which SSL ciphers the server should support, default is unchanged (#1478)
|
136
|
+
* The setting for Puma's `max_threads` is now in `Puma.stats` (#1604)
|
137
|
+
* Pool capacity is now in `Puma.stats` (#1579)
|
138
|
+
* Installs restricted to Ruby 2.2+ (#1506)
|
139
|
+
* `--control` is now deprecated in favor of `--control-url` (#1487)
|
140
|
+
|
141
|
+
* 2 bugfixes:
|
142
|
+
* 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)
|
143
|
+
* In a test env puma now emits the stack on an exception (#1557)
|
144
|
+
|
145
|
+
## 3.11.4 / 2018-04-12
|
146
|
+
|
147
|
+
* 2 features:
|
148
|
+
* Manage puma as a service using rc.d (#1529)
|
149
|
+
* Server stats are now available from a top level method (#1532)
|
150
|
+
* 5 bugfixes:
|
151
|
+
* Fix parsing CLI options (#1482)
|
152
|
+
* Order of stderr and stdout is made before redirecting to a log file (#1511)
|
153
|
+
* Init.d fix of `ps -p` to check if pid exists (#1545)
|
154
|
+
* Early hints bugfix (#1550)
|
155
|
+
* Purge interrupt queue when closing socket fails (#1553)
|
156
|
+
|
157
|
+
## 3.11.3 / 2018-03-05
|
158
|
+
|
159
|
+
* 3 bugfixes:
|
160
|
+
* Add closed? to MiniSSL::Socket for use in reactor (#1510)
|
161
|
+
* Handle EOFError at the toplevel of the server threads (#1524) (#1507)
|
162
|
+
* Deal with zero sized bodies when using SSL (#1483)
|
163
|
+
|
164
|
+
## 3.11.2 / 2018-01-19
|
165
|
+
|
166
|
+
* 1 bugfix:
|
167
|
+
* Deal with read\_nonblock returning nil early
|
168
|
+
|
169
|
+
## 3.11.1 / 2018-01-18
|
170
|
+
|
171
|
+
* 1 bugfix:
|
172
|
+
* Handle read\_nonblock returning nil when the socket close (#1502)
|
173
|
+
|
174
|
+
## 3.11.0 / 2017-11-20
|
175
|
+
|
176
|
+
* 2 features:
|
177
|
+
* HTTP 103 Early Hints (#1403)
|
178
|
+
* 421/451 status codes now have correct status messages attached (#1435)
|
179
|
+
|
180
|
+
* 9 bugfixes:
|
181
|
+
* Environment config files (/config/puma/<ENV>.rb) load correctly (#1340)
|
182
|
+
* Specify windows dependencies correctly (#1434, #1436)
|
183
|
+
* puma/events required in test helper (#1418)
|
184
|
+
* Correct control CLI's option help text (#1416)
|
185
|
+
* Remove a warning for unused variable in mini_ssl (#1409)
|
186
|
+
* Correct pumactl docs argument ordering (#1427)
|
187
|
+
* Fix an uninitialized variable warning in server.rb (#1430)
|
188
|
+
* Fix docs typo/error in Launcher init (#1429)
|
189
|
+
* Deal with leading spaces in RUBYOPT (#1455)
|
190
|
+
|
191
|
+
* 2 other:
|
192
|
+
* Add docs about internals (#1425, #1452)
|
193
|
+
* Tons of test fixes from @MSP-Greg (#1439, #1442, #1464)
|
194
|
+
|
195
|
+
## 3.10.0 / 2017-08-17
|
196
|
+
|
197
|
+
* 3 features:
|
198
|
+
* The status server has a new /gc and /gc-status command. (#1384)
|
199
|
+
* The persistent and first data timeouts are now configurable (#1111)
|
200
|
+
* Implemented RFC 2324 (#1392)
|
201
|
+
|
202
|
+
* 12 bugfixes:
|
203
|
+
* 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)
|
204
|
+
* Fix hangups with SSL and persistent connections. (#1334)
|
205
|
+
* Fix Rails double-binding to a port (#1383)
|
206
|
+
* Fix incorrect thread names (#1368)
|
207
|
+
* Fix issues with /etc/hosts and JRuby where localhost addresses were not correct. (#1318)
|
208
|
+
* Fix compatibility with RUBYOPT="--enable-frozen-string-literal" (#1376)
|
209
|
+
* Fixed some compiler warnings (#1388)
|
210
|
+
* We actually run the integration tests in CI now (#1390)
|
211
|
+
* No longer shipping unnecessary directories in the gemfile (#1391)
|
212
|
+
* If RUBYOPT is nil, we no longer blow up on restart. (#1385)
|
213
|
+
* Correct response to SIGINT (#1377)
|
214
|
+
* Proper exit code returned when we receive a TERM signal (#1337)
|
215
|
+
|
216
|
+
* 3 refactors:
|
217
|
+
* Various test improvements from @grosser
|
218
|
+
* Rubocop (#1325)
|
219
|
+
* Hoe has been removed (#1395)
|
220
|
+
|
221
|
+
* 1 known issue:
|
222
|
+
* Socket activation doesn't work in JRuby. Their fault, not ours. (#1367)
|
223
|
+
|
1
224
|
## 3.9.1 / 2017-06-03
|
2
225
|
|
3
226
|
* 2 bugfixes:
|
@@ -1303,3 +1526,12 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
1303
1526
|
## 1.0.0 / 2012-03-29
|
1304
1527
|
|
1305
1528
|
* Released!
|
1529
|
+
|
1530
|
+
## Ignore - this is for maintainers to copy-paste during release
|
1531
|
+
## Master
|
1532
|
+
|
1533
|
+
* Features
|
1534
|
+
* Your feature goes here (#Github Number)
|
1535
|
+
|
1536
|
+
* Bugfixes
|
1537
|
+
* Your bugfix goes here (#Github Number)
|
data/README.md
CHANGED
@@ -1,179 +1,136 @@
|
|
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://
|
5
|
-
[![
|
6
|
-
[![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
|
8
|
+
[![Actions Build Status](https://github.com/puma/puma/workflows/Puma/badge.svg)](https://github.com/puma/puma/actions)
|
9
|
+
[![Travis Build Status](https://travis-ci.org/puma/puma.svg?branch=master)](https://travis-ci.org/puma/puma)
|
7
10
|
|
8
|
-
|
11
|
+
[![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
|
12
|
+
[![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)
|
9
13
|
|
10
|
-
Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications
|
14
|
+
Puma is a **simple, fast, multi-threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications**.
|
11
15
|
|
12
16
|
## Built For Speed & Concurrency
|
13
17
|
|
14
|
-
Puma
|
15
|
-
|
16
|
-
Under the hood, 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 in a thread from an internal thread pool (which you can control). This allows Puma to provide real concurrency for your web application!
|
18
|
+
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.
|
17
19
|
|
18
|
-
|
20
|
+
Puma was designed to be the go-to server for [Rubinius](https://rubinius.com), but also works well with JRuby and MRI.
|
19
21
|
|
20
|
-
On MRI, there is a Global
|
22
|
+
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
23
|
|
22
24
|
## Quick Start
|
23
25
|
|
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.
|
26
|
+
```
|
27
|
+
$ gem install puma
|
28
|
+
$ puma
|
29
|
+
```
|
48
30
|
|
49
|
-
|
31
|
+
Without arguments, puma will look for a rackup (.ru) file in the current working directory called `config.ru`.
|
50
32
|
|
51
|
-
|
33
|
+
## Frameworks
|
52
34
|
|
53
|
-
|
35
|
+
### Rails
|
54
36
|
|
55
|
-
|
37
|
+
Puma is the default server for Rails, included in the generated Gemfile.
|
56
38
|
|
57
|
-
|
39
|
+
Start your server with the `rails` command:
|
58
40
|
|
59
|
-
|
41
|
+
```
|
42
|
+
$ rails server
|
43
|
+
```
|
60
44
|
|
45
|
+
Many configuration options and Puma features are not available when using `rails server`. It is recommended that you use Puma's executable instead:
|
61
46
|
|
62
|
-
|
47
|
+
```
|
48
|
+
$ bundle exec puma
|
49
|
+
```
|
63
50
|
|
64
51
|
### Sinatra
|
65
52
|
|
66
53
|
You can run your Sinatra application with Puma from the command line like this:
|
67
54
|
|
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
|
55
|
+
```
|
56
|
+
$ ruby app.rb -s Puma
|
57
|
+
```
|
92
58
|
|
93
|
-
|
59
|
+
Or you can configure your Sinatra application to always use Puma:
|
94
60
|
|
95
|
-
|
61
|
+
```ruby
|
62
|
+
require 'sinatra'
|
63
|
+
configure { set :server, :puma }
|
64
|
+
```
|
96
65
|
|
97
66
|
## Configuration
|
98
67
|
|
99
|
-
Puma provides numerous options
|
68
|
+
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).
|
69
|
+
|
70
|
+
You can also find several configuration examples as part of the
|
71
|
+
[test](test/config) suite.
|
100
72
|
|
101
73
|
### Thread Pool
|
102
74
|
|
103
|
-
Puma
|
75
|
+
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:
|
104
76
|
|
105
|
-
|
77
|
+
```
|
78
|
+
$ puma -t 8:32
|
79
|
+
```
|
106
80
|
|
107
|
-
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
|
81
|
+
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).
|
108
82
|
|
109
|
-
|
83
|
+
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.
|
110
84
|
|
111
|
-
|
85
|
+
### Clustered mode
|
112
86
|
|
113
|
-
|
87
|
+
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:
|
114
88
|
|
115
|
-
|
116
|
-
|
89
|
+
```
|
90
|
+
$ puma -t 8:32 -w 3
|
91
|
+
```
|
117
92
|
|
118
|
-
|
93
|
+
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
94
|
|
120
|
-
|
121
|
-
$ puma -t 8:32 -w 3 --preload
|
95
|
+
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
96
|
|
123
|
-
|
97
|
+
```
|
98
|
+
$ puma -w 3 --preload
|
99
|
+
```
|
124
100
|
|
125
|
-
|
101
|
+
If you're using a configuration file, use the `preload_app!` method:
|
126
102
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
103
|
+
```ruby
|
104
|
+
# config/puma.rb
|
105
|
+
workers 3
|
106
|
+
preload_app!
|
107
|
+
```
|
131
108
|
|
132
109
|
Additionally, you can specify a block in your configuration file that will be run on boot of each worker:
|
133
110
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
111
|
+
```ruby
|
112
|
+
# config/puma.rb
|
113
|
+
on_worker_boot do
|
114
|
+
# configuration here
|
115
|
+
end
|
116
|
+
```
|
138
117
|
|
139
118
|
This code can be used to setup the process before booting the application, allowing
|
140
119
|
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.
|
143
|
-
|
144
|
-
If you're preloading your application and using ActiveRecord, it's recommended that you setup your connection pool here:
|
145
|
-
|
146
|
-
# config/puma.rb
|
147
|
-
on_worker_boot do
|
148
|
-
ActiveSupport.on_load(:active_record) do
|
149
|
-
ActiveRecord::Base.establish_connection
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
On top of that, you can specify a block in your configuration file that will be run before workers are forked
|
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.
|
120
|
+
For instance, you could fire a log notification that a worker booted or send something to statsd. This can be called multiple times.
|
162
121
|
|
163
|
-
|
122
|
+
`before_fork` specifies a block to be run before workers are forked:
|
164
123
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
When you use preload_app, all of your new code goes into the master process, and is then copied into the workers (meaning it’s only compatible with cluster mode). General rule is to use preload_app when your workers die often and need fast starts. If you don’t have many workers, you probably should not use preload_app.
|
124
|
+
```ruby
|
125
|
+
# config/puma.rb
|
126
|
+
before_fork do
|
127
|
+
# configuration here
|
128
|
+
end
|
129
|
+
```
|
173
130
|
|
174
|
-
|
131
|
+
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
132
|
|
176
|
-
### Error
|
133
|
+
### Error handling
|
177
134
|
|
178
135
|
If puma encounters an error outside of the context of your application, it will respond with a 500 and a simple
|
179
136
|
textual error message (see `lowlevel_error` in [this file](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
|
@@ -189,165 +146,146 @@ end
|
|
189
146
|
|
190
147
|
### Binding TCP / Sockets
|
191
148
|
|
192
|
-
|
149
|
+
Bind Puma to a socket with the `-b` (or `--bind`) flag:
|
193
150
|
|
194
|
-
|
151
|
+
```
|
152
|
+
$ puma -b tcp://127.0.0.1:9292
|
153
|
+
```
|
195
154
|
|
196
|
-
|
155
|
+
To use a UNIX Socket instead of TCP:
|
197
156
|
|
198
|
-
|
157
|
+
```
|
158
|
+
$ puma -b unix:///var/run/puma.sock
|
159
|
+
```
|
199
160
|
|
200
161
|
If you need to change the permissions of the UNIX socket, just add a umask parameter:
|
201
162
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
|
207
|
-
|
208
|
-
### Control/Status Server
|
209
|
-
|
210
|
-
Puma comes with a builtin status/control app that can be used to query and control Puma itself. Here is an example of starting Puma with the control server:
|
211
|
-
|
212
|
-
$ puma --control tcp://127.0.0.1:9293 --control-token foo
|
213
|
-
|
214
|
-
This directs Puma to start the control server on localhost port 9293. Additionally, all requests to the control server will need to include `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 app has available.
|
163
|
+
```
|
164
|
+
$ puma -b 'unix:///var/run/puma.sock?umask=0111'
|
165
|
+
```
|
215
166
|
|
216
|
-
|
167
|
+
Need a bit of security? Use SSL sockets:
|
217
168
|
|
218
|
-
|
169
|
+
```
|
170
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
|
171
|
+
```
|
219
172
|
|
220
|
-
|
173
|
+
#### Controlling SSL Cipher Suites
|
221
174
|
|
222
|
-
|
175
|
+
To use or avoid specific SSL cipher suites, use `ssl_cipher_filter` or `ssl_cipher_list` options.
|
223
176
|
|
224
|
-
|
177
|
+
##### Ruby:
|
225
178
|
|
226
|
-
|
179
|
+
```
|
180
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA'
|
181
|
+
```
|
227
182
|
|
228
|
-
|
183
|
+
##### JRuby:
|
229
184
|
|
230
|
-
|
185
|
+
```
|
186
|
+
$ 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'
|
187
|
+
```
|
231
188
|
|
232
|
-
|
189
|
+
See https://www.openssl.org/docs/man1.0.2/apps/ciphers.html for cipher filter format and full list of cipher suites.
|
233
190
|
|
234
|
-
|
191
|
+
Disable TLS v1 with the `no_tlsv1` option:
|
235
192
|
|
236
|
-
|
193
|
+
```
|
194
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true'
|
195
|
+
```
|
237
196
|
|
238
|
-
|
197
|
+
### Control/Status Server
|
239
198
|
|
240
|
-
|
199
|
+
Puma has a built-in status and control app that can be used to query and control Puma.
|
241
200
|
|
242
|
-
|
243
|
-
|
201
|
+
```
|
202
|
+
$ puma --control-url tcp://127.0.0.1:9293 --control-token foo
|
203
|
+
```
|
244
204
|
|
245
|
-
|
205
|
+
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.
|
246
206
|
|
247
|
-
|
207
|
+
You can also interact with the control server via `pumactl`. This command will restart Puma:
|
248
208
|
|
249
|
-
|
209
|
+
```
|
210
|
+
$ pumactl --control-url 'tcp://127.0.0.1:9293' --control-token foo restart
|
211
|
+
```
|
250
212
|
|
251
|
-
|
213
|
+
To see a list of `pumactl` options, use `pumactl --help`.
|
252
214
|
|
253
|
-
|
215
|
+
### Configuration File
|
254
216
|
|
255
|
-
|
217
|
+
You can also provide a configuration file with the `-C` (or `--config`) flag:
|
256
218
|
|
257
|
-
|
219
|
+
```
|
220
|
+
$ puma -C /path/to/config
|
221
|
+
```
|
258
222
|
|
259
|
-
If
|
223
|
+
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`.
|
260
224
|
|
261
|
-
|
225
|
+
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:
|
262
226
|
|
263
|
-
|
227
|
+
```
|
228
|
+
$ puma -C "-"
|
229
|
+
```
|
264
230
|
|
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`
|
231
|
+
The other side-effects of setting the environment are whether to show stack traces (in `development` or `test`), and setting RACK_ENV may potentially affect middleware looking for this value to change their behavior. The default puma RACK_ENV value is `development`. You can see all config default values [here](https://github.com/puma/puma/blob/12d1706ddc71b89ed2ee26275e31c788e94ff541/lib/puma/configuration.rb#L170).
|
273
232
|
|
274
|
-
|
233
|
+
Check out [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb) to see all available options.
|
275
234
|
|
276
|
-
|
235
|
+
## Restart
|
277
236
|
|
278
|
-
|
237
|
+
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.
|
279
238
|
|
280
|
-
|
281
|
-
# config/puma.rb
|
239
|
+
For more, see the [restart documentation](https://github.com/puma/puma/blob/master/docs/restart.md).
|
282
240
|
|
283
|
-
|
284
|
-
```
|
241
|
+
## Signals
|
285
242
|
|
286
|
-
|
243
|
+
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).
|
287
244
|
|
288
|
-
|
245
|
+
## Platform Constraints
|
289
246
|
|
290
|
-
|
247
|
+
Some platforms do not support all Puma features.
|
291
248
|
|
292
|
-
|
249
|
+
* **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).
|
250
|
+
* **Windows**: Cluster mode is not supported due to a lack of fork(2).
|
293
251
|
|
294
|
-
|
252
|
+
## Known Bugs
|
295
253
|
|
296
|
-
|
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)
|
254
|
+
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:
|
299
255
|
|
300
|
-
|
256
|
+
```ruby
|
257
|
+
if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
|
258
|
+
begin
|
259
|
+
require 'stopgap_13632'
|
260
|
+
rescue LoadError
|
261
|
+
end
|
262
|
+
end
|
263
|
+
```
|
301
264
|
|
302
|
-
|
265
|
+
## Deployment
|
303
266
|
|
304
|
-
|
267
|
+
Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
|
305
268
|
|
306
|
-
|
307
|
-
|
308
|
-
further provide continuous monitoring and restarts for increased
|
269
|
+
It is common to use process monitors with Puma. Modern process monitors like systemd or upstart
|
270
|
+
provide continuous monitoring and restarts for increased
|
309
271
|
reliability in production environments:
|
310
272
|
|
311
273
|
* [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for sysvinit (init.d) and upstart
|
312
274
|
* [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
|
313
275
|
|
314
|
-
##
|
315
|
-
|
316
|
-
Puma has support for Capistrano3 with an [external gem](https://github.com/seuros/capistrano-puma), you just need require that in Gemfile:
|
317
|
-
|
318
|
-
```ruby
|
319
|
-
gem 'capistrano3-puma'
|
320
|
-
```
|
321
|
-
And then execute:
|
322
|
-
|
323
|
-
```bash
|
324
|
-
bundle
|
325
|
-
```
|
326
|
-
|
327
|
-
Then add to Capfile
|
328
|
-
|
329
|
-
```ruby
|
330
|
-
require 'capistrano/puma'
|
331
|
-
```
|
276
|
+
## Community Plugins
|
332
277
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
$ bundle exec cap puma:restart
|
338
|
-
$ bundle exec cap puma:stop
|
339
|
-
$ bundle exec cap puma:phased-restart
|
340
|
-
```
|
278
|
+
* [puma-heroku](https://github.com/evanphx/puma-heroku) — default Puma configuration for running on Heroku
|
279
|
+
* [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
|
280
|
+
* [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
|
281
|
+
* [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog
|
341
282
|
|
342
283
|
## Contributing
|
343
284
|
|
344
|
-
|
285
|
+
Find details for contributing in the [contribution guide].
|
345
286
|
|
346
|
-
|
347
|
-
$ bundle install
|
348
|
-
$ bundle exec rake
|
349
|
-
```
|
287
|
+
[contribution guide]: https://github.com/puma/puma/blob/master/CONTRIBUTING.md
|
350
288
|
|
351
289
|
## License
|
352
290
|
|
353
|
-
Puma is copyright
|
291
|
+
Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.
|