puma 5.1.1 → 5.3.2

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.

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +138 -10
  3. data/README.md +24 -2
  4. data/docs/architecture.md +22 -18
  5. data/docs/compile_options.md +6 -6
  6. data/docs/deployment.md +2 -2
  7. data/docs/jungle/rc.d/README.md +1 -1
  8. data/docs/kubernetes.md +66 -0
  9. data/docs/plugins.md +2 -2
  10. data/docs/rails_dev_mode.md +29 -0
  11. data/docs/restart.md +1 -1
  12. data/docs/stats.md +142 -0
  13. data/docs/systemd.md +1 -1
  14. data/ext/puma_http11/extconf.rb +14 -0
  15. data/ext/puma_http11/http11_parser.c +19 -21
  16. data/ext/puma_http11/http11_parser.h +1 -1
  17. data/ext/puma_http11/http11_parser.java.rl +1 -1
  18. data/ext/puma_http11/http11_parser.rl +1 -1
  19. data/ext/puma_http11/mini_ssl.c +162 -84
  20. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +5 -7
  21. data/ext/puma_http11/puma_http11.c +2 -2
  22. data/lib/puma.rb +34 -8
  23. data/lib/puma/binder.rb +51 -44
  24. data/lib/puma/client.rb +7 -4
  25. data/lib/puma/cluster.rb +40 -8
  26. data/lib/puma/cluster/worker.rb +8 -1
  27. data/lib/puma/cluster/worker_handle.rb +4 -0
  28. data/lib/puma/configuration.rb +6 -1
  29. data/lib/puma/const.rb +3 -3
  30. data/lib/puma/control_cli.rb +5 -1
  31. data/lib/puma/detect.rb +14 -10
  32. data/lib/puma/dsl.rb +57 -5
  33. data/lib/puma/error_logger.rb +12 -5
  34. data/lib/puma/events.rb +2 -3
  35. data/lib/puma/launcher.rb +4 -3
  36. data/lib/puma/minissl.rb +48 -17
  37. data/lib/puma/minissl/context_builder.rb +6 -0
  38. data/lib/puma/null_io.rb +12 -0
  39. data/lib/puma/queue_close.rb +7 -7
  40. data/lib/puma/reactor.rb +7 -2
  41. data/lib/puma/request.rb +23 -7
  42. data/lib/puma/runner.rb +8 -3
  43. data/lib/puma/server.rb +43 -114
  44. data/lib/puma/thread_pool.rb +4 -3
  45. data/lib/rack/handler/puma.rb +1 -0
  46. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a6a1bfd1d41d66c8aef6c52a2a043a0e537a1ddb51e20c778bb2da023d9a964
4
- data.tar.gz: d256171ae36d0c5d1646ecbea4476df3e1bf7fbba5415c6ca6672eacbc5bd995
3
+ metadata.gz: 2f0d0f5c0a10e36659888cae94e428c91dbe06ba8e3842853b4d6cfd0b103603
4
+ data.tar.gz: 7b375f89a704b081fba4eb08c52aec94563f0c6a888b9544ce0afcefc443b8fa
5
5
  SHA512:
6
- metadata.gz: 9d6e9dfa206d98785ff62d7c03cd5193d5745918d684bf2a7d78027294ae345eb34d32d819ffda08ba34629cda589b0138faf1fdc91606a0cbab352615c859f3
7
- data.tar.gz: 6775ccd4eaf9abdda6191c07b7d668588b813dbc96b71496b98cb0ee2ffefb94dd3db068159d8a2c746e5bcc4e4456fa6c4f12c721b66f6c5bed13b9e19718e2
6
+ metadata.gz: 14a0bde86f109197089905694c259d2382d86000ab877cb8eaf44c593866afdedad173d1c7c9eb1efe48a714ee33f6b5e4c3c32fe420d3298ab3511c9fae0a7a
7
+ data.tar.gz: a31d4feee8e6a36c27d1037ad91cc279c294505ecbb143c3a005f7d0817031c9b80cef465b5800c6c6075f16f587e43fa98de8dd2b99fe92996c9c9fba36ea70
data/History.md CHANGED
@@ -1,8 +1,84 @@
1
+ ## 5.3.2 / 2021-05-21
2
+
3
+ * Bugfixes
4
+ * Gracefully handle Rack not accepting CLI options (#2630, #2626)
5
+ * Fix sigterm misbehavior (#2629)
6
+ * Improvements to keepalive-connection shedding (#2628)
7
+
8
+ ## 5.3.1 / 2021-05-11
9
+
10
+ * Security
11
+ * Close keepalive connections after the maximum number of fast inlined requests (#2625)
12
+
13
+ ## 5.3.0 / 2021-05-07
14
+
15
+ * Features
16
+ * Add support for Linux's abstract sockets ([#2564], [#2526])
17
+ * Add debug to worker timeout and startup ([#2559], [#2528])
18
+ * Print warning when running one-worker cluster ([#2565], [#2534])
19
+ * Don't close systemd activated socket on pumactl restart ([#2563], [#2504])
20
+
21
+ * Bugfixes
22
+ * systemd - fix event firing ([#2591], [#2572])
23
+ * Immediately unlink temporary files ([#2613])
24
+ * Improve parsing of HTTP_HOST header ([#2605], [#2584])
25
+ * Handle fatal error that has no backtrace ([#2607], [#2552])
26
+ * Fix timing out requests too early ([#2606], [#2574])
27
+ * Handle segfault in Ruby 2.6.6 on thread-locals ([#2567], [#2566])
28
+ * Server#closed_socket? - parameter may be a MiniSSL::Socket ([#2596])
29
+ * Define UNPACK_TCP_STATE_FROM_TCP_INFO in the right place ([#2588], [#2556])
30
+ * request.rb - fix chunked assembly for ascii incompatible encodings, add test ([#2585], [#2583])
31
+
32
+ * Performance
33
+ * Reset peerip only if remote_addr_header is set ([#2609])
34
+ * Reduce puma_parser struct size ([#2590])
35
+
36
+ * Refactor
37
+ * Refactor drain on shutdown ([#2600])
38
+ * Micro optimisations in `wait_for_less_busy_worker` feature ([#2579])
39
+ * Lots of test fixes
40
+
41
+ ## 5.2.2 / 2021-02-22
42
+
43
+ * Bugfixes
44
+ * Add `#flush` and `#sync` methods to `Puma::NullIO` ([#2553])
45
+ * Restore `sync=true` on `STDOUT` and `STDERR` streams ([#2557])
46
+
47
+ ## 5.2.1 / 2021-02-05
48
+
49
+ * Bugfixes
50
+ * Fix TCP cork/uncork operations to work with ssl clients ([#2550])
51
+ * Require rack/common_logger explicitly if :verbose is true ([#2547])
52
+ * MiniSSL::Socket#write - use data.byteslice(wrote..-1) ([#2543])
53
+ * Set `@env[CONTENT_LENGTH]` value as string. ([#2549])
54
+
55
+ ## 5.2.0 / 2021-01-27
56
+
57
+ * Features
58
+ * 10x latency improvement for MRI on ssl connections by reducing overhead ([#2519])
59
+ * Add option to specify the desired IO selector backend for libev ([#2522])
60
+ * Add ability to set OpenSSL verification flags (MRI only) ([#2490])
61
+ * Uses `flush` after writing messages to avoid mutating $stdout and $stderr using `sync=true` ([#2486])
62
+
63
+ * Bugfixes
64
+ * MiniSSL - Update dhparam to 2048 bit for use with SSL_CTX_set_tmp_dh ([#2535])
65
+ * Change 'Goodbye!' message to be output after listeners are closed ([#2529])
66
+ * Fix ssl bind logging with 0.0.0.0 and localhost ([#2533])
67
+ * Fix compiler warnings, but skipped warnings related to ragel state machine generated code ([#1953])
68
+ * Fix phased restart errors related to nio4r gem when using the Puma control server ([#2516])
69
+ * Add `#string` method to `Puma::NullIO` ([#2520])
70
+ * Fix binding via Rack handler to IPv6 addresses ([#2521])
71
+
72
+ * Refactor
73
+ * Refactor MiniSSL::Context on MRI, fix MiniSSL::Socket#write ([#2519])
74
+ * Remove `Server#read_body` ([#2531])
75
+ * Fail build if compiling extensions raises warnings on GH Actions, configurable via `MAKE_WARNINGS_INTO_ERRORS` ([#1953])
76
+
1
77
  ## 5.1.1 / 2020-12-10
2
78
 
3
- * Bugfixes
79
+ * Bugfixes
4
80
  * Fix over eager matching against banned header names ([#2510])
5
-
81
+
6
82
  ## 5.1.0 / 2020-11-30
7
83
 
8
84
  * Features
@@ -98,7 +174,7 @@
98
174
  * Daemonization has been removed without replacement. ([#2170])
99
175
  * Changed #connected_port to #connected_ports ([#2076])
100
176
  * Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found ([#2022])
101
- * Log binding on http:// for TCP bindings to make it clickable
177
+ * Log binding on http:// for TCP bindings to make it clickable ([#2300])
102
178
 
103
179
  * Bugfixes
104
180
  * Fix JSON loading issues on phased-restarts ([#2269])
@@ -144,17 +220,22 @@
144
220
  * Support parallel tests in verbose progress reporting ([#2223])
145
221
  * Refactor error handling in server accept loop ([#2239])
146
222
 
147
- ## 4.3.6 / 2020-09-05
223
+ ## 4.3.8 / 2021-05-11
148
224
 
149
- * Bugfixes
150
- * Explicitly include ctype.h to fix compilation warning and build error on macOS with Xcode 12 ([#2304])
151
- * Don't require json at boot ([#2269])
225
+ * Security
226
+ * Close keepalive connections after the maximum number of fast inlined requests (#2625)
152
227
 
153
228
  ## 4.3.7 / 2020-11-30
154
229
 
155
230
  * Bugfixes
156
231
  * Backport set CONTENT_LENGTH for chunked requests (Originally: [#2287], backport: [#2496])
157
232
 
233
+ ## 4.3.6 / 2020-09-05
234
+
235
+ * Bugfixes
236
+ * Explicitly include ctype.h to fix compilation warning and build error on macOS with Xcode 12 ([#2304])
237
+ * Don't require json at boot ([#2269])
238
+
158
239
  ## 4.3.4/4.3.5 and 3.12.5/3.12.6 / 2020-05-22
159
240
 
160
241
  Each patchlevel release contains a separate security fix. We recommend simply upgrading to 4.3.5/3.12.6.
@@ -1672,7 +1753,53 @@ be added back in a future date when a java Puma::MiniSSL is added.
1672
1753
  * Bugfixes
1673
1754
  * Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
1674
1755
 
1675
- [#2510]:https://github.com/puma/puma/pull/2510 "PR by @micke"
1756
+ [#2564]:https://github.com/puma/puma/pull/2564 "PR by @MSP-Greg, merged 2021-04-24"
1757
+ [#2526]:https://github.com/puma/puma/issues/2526 "Issue by @nerdrew, closed 2021-04-24"
1758
+ [#2559]:https://github.com/puma/puma/pull/2559 "PR by @ylecuyer, merged 2021-03-11"
1759
+ [#2528]:https://github.com/puma/puma/issues/2528 "Issue by @cjlarose, closed 2021-03-11"
1760
+ [#2565]:https://github.com/puma/puma/pull/2565 "PR by @CGA1123, merged 2021-03-09"
1761
+ [#2534]:https://github.com/puma/puma/issues/2534 "Issue by @nateberkopec, closed 2021-03-09"
1762
+ [#2563]:https://github.com/puma/puma/pull/2563 "PR by @MSP-Greg, merged 2021-03-06"
1763
+ [#2504]:https://github.com/puma/puma/issues/2504 "Issue by @fsateler, closed 2021-03-06"
1764
+ [#2591]:https://github.com/puma/puma/pull/2591 "PR by @MSP-Greg, merged 2021-05-05"
1765
+ [#2572]:https://github.com/puma/puma/issues/2572 "Issue by @josefbilendo, closed 2021-05-05"
1766
+ [#2613]:https://github.com/puma/puma/pull/2613 "PR by @smcgivern, merged 2021-04-27"
1767
+ [#2605]:https://github.com/puma/puma/pull/2605 "PR by @pascalbetz, merged 2021-04-26"
1768
+ [#2584]:https://github.com/puma/puma/issues/2584 "Issue by @kaorihinata, closed 2021-04-26"
1769
+ [#2607]:https://github.com/puma/puma/pull/2607 "PR by @calvinxiao, merged 2021-04-23"
1770
+ [#2552]:https://github.com/puma/puma/issues/2552 "Issue by @feliperaul, opened 2021-02-09"
1771
+ [#2606]:https://github.com/puma/puma/pull/2606 "PR by @wjordan, merged 2021-04-20"
1772
+ [#2574]:https://github.com/puma/puma/issues/2574 "Issue by @darkhelmet, closed 2021-04-20"
1773
+ [#2567]:https://github.com/puma/puma/pull/2567 "PR by @kddeisz, merged 2021-04-19"
1774
+ [#2566]:https://github.com/puma/puma/issues/2566 "Issue by @kddeisz, closed 2021-04-19"
1775
+ [#2596]:https://github.com/puma/puma/pull/2596 "PR by @MSP-Greg, merged 2021-04-18"
1776
+ [#2588]:https://github.com/puma/puma/pull/2588 "PR by @dentarg, merged 2021-04-02"
1777
+ [#2556]:https://github.com/puma/puma/issues/2556 "Issue by @gamecreature, closed 2021-04-02"
1778
+ [#2585]:https://github.com/puma/puma/pull/2585 "PR by @MSP-Greg, merged 2021-03-26"
1779
+ [#2583]:https://github.com/puma/puma/issues/2583 "Issue by @jboler, closed 2021-03-26"
1780
+ [#2609]:https://github.com/puma/puma/pull/2609 "PR by @calvinxiao, merged 2021-04-26"
1781
+ [#2590]:https://github.com/puma/puma/pull/2590 "PR by @calvinxiao, merged 2021-04-05"
1782
+ [#2600]:https://github.com/puma/puma/pull/2600 "PR by @wjordan, merged 2021-04-30"
1783
+ [#2579]:https://github.com/puma/puma/pull/2579 "PR by @ghiculescu, merged 2021-03-17"
1784
+ [#2553]:https://github.com/puma/puma/pull/2553 "PR by @olivierbellone, merged 2021-02-10"
1785
+ [#2557]:https://github.com/puma/puma/pull/2557 "PR by @cjlarose, merged 2021-02-22"
1786
+ [#2550]:https://github.com/puma/puma/pull/2550 "PR by @MSP-Greg, merged 2021-02-05"
1787
+ [#2547]:https://github.com/puma/puma/pull/2547 "PR by @wildmaples, merged 2021-02-03"
1788
+ [#2543]:https://github.com/puma/puma/pull/2543 "PR by @MSP-Greg, merged 2021-02-01"
1789
+ [#2549]:https://github.com/puma/puma/pull/2549 "PR by @nmb, merged 2021-02-04"
1790
+ [#2519]:https://github.com/puma/puma/pull/2519 "PR by @MSP-Greg, merged 2021-01-26"
1791
+ [#2522]:https://github.com/puma/puma/pull/2522 "PR by @jcmfernandes, merged 2021-01-12"
1792
+ [#2490]:https://github.com/puma/puma/pull/2490 "PR by @Bonias, merged 2020-12-07"
1793
+ [#2486]:https://github.com/puma/puma/pull/2486 "PR by @ccverak, merged 2020-12-02"
1794
+ [#2535]:https://github.com/puma/puma/pull/2535 "PR by @MSP-Greg, merged 2021-01-27"
1795
+ [#2529]:https://github.com/puma/puma/pull/2529 "PR by @MSP-Greg, merged 2021-01-24"
1796
+ [#2533]:https://github.com/puma/puma/pull/2533 "PR by @MSP-Greg, merged 2021-01-24"
1797
+ [#1953]:https://github.com/puma/puma/issues/1953 "Issue by @nateberkopec, closed 2020-12-01"
1798
+ [#2516]:https://github.com/puma/puma/pull/2516 "PR by @cjlarose, merged 2020-12-17"
1799
+ [#2520]:https://github.com/puma/puma/pull/2520 "PR by @dentarg, merged 2021-01-04"
1800
+ [#2521]:https://github.com/puma/puma/pull/2521 "PR by @ojab, merged 2021-01-04"
1801
+ [#2531]:https://github.com/puma/puma/pull/2531 "PR by @wjordan, merged 2021-01-19"
1802
+ [#2510]:https://github.com/puma/puma/pull/2510 "PR by @micke, merged 2020-12-10"
1676
1803
  [#2472]:https://github.com/puma/puma/pull/2472 "PR by @ccverak, merged 2020-11-02"
1677
1804
  [#2438]:https://github.com/puma/puma/pull/2438 "PR by @ekohl, merged 2020-10-26"
1678
1805
  [#2406]:https://github.com/puma/puma/pull/2406 "PR by @fdel15, merged 2020-10-19"
@@ -1736,6 +1863,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
1736
1863
  [#2170]:https://github.com/puma/puma/pull/2170 "PR by @nateberkopec, merged 2020-03-10"
1737
1864
  [#2076]:https://github.com/puma/puma/pull/2076 "PR by @drews256, merged 2020-02-27"
1738
1865
  [#2022]:https://github.com/puma/puma/pull/2022 "PR by @olleolleolle, merged 2019-11-11"
1866
+ [#2300]:https://github.com/puma/puma/pull/2300 "PR by @alexeevit, merged 2020-07-06"
1739
1867
  [#2269]:https://github.com/puma/puma/pull/2269 "PR by @MSP-Greg, merged 2020-08-31"
1740
1868
  [#2312]:https://github.com/puma/puma/pull/2312 "PR by @MSP-Greg, merged 2020-07-20"
1741
1869
  [#2338]:https://github.com/puma/puma/issues/2338 "Issue by @micahhainlinestitchfix, closed 2020-08-18"
@@ -1771,8 +1899,8 @@ be added back in a future date when a java Puma::MiniSSL is added.
1771
1899
  [#2124]:https://github.com/puma/puma/pull/2124 "PR by @wjordan, merged 2020-04-14"
1772
1900
  [#2223]:https://github.com/puma/puma/pull/2223 "PR by @wjordan, merged 2020-04-20"
1773
1901
  [#2239]:https://github.com/puma/puma/pull/2239 "PR by @wjordan, merged 2020-05-15"
1774
- [#2304]:https://github.com/puma/puma/issues/2304 "Issue by @mpeltomaa, closed 2020-09-05"
1775
1902
  [#2496]:https://github.com/puma/puma/pull/2496 "PR by @TheRusskiy, merged 2020-11-30"
1903
+ [#2304]:https://github.com/puma/puma/issues/2304 "Issue by @mpeltomaa, closed 2020-09-05"
1776
1904
  [#2132]:https://github.com/puma/puma/issues/2132 "Issue by @bmclean, closed 2020-02-28"
1777
1905
  [#2010]:https://github.com/puma/puma/pull/2010 "PR by @nateberkopec, merged 2019-10-07"
1778
1906
  [#2012]:https://github.com/puma/puma/pull/2012 "PR by @headius, merged 2019-10-07"
@@ -2119,7 +2247,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
2119
2247
  [#646]:https://github.com/puma/puma/pull/646 "PR by @mkonecny, merged 2015-02-05"
2120
2248
  [#630]:https://github.com/puma/puma/issues/630 "Issue by @jelmd, closed 2015-01-20"
2121
2249
  [#622]:https://github.com/puma/puma/issues/622 "Issue by @sabamotto, closed 2015-01-20"
2122
- [#583]:https://github.com/puma/puma/issues/583 "Issue by @emq, closed 2015-01-20"
2250
+ [#583]:https://github.com/puma/puma/issues/583 "Issue by @rwojsznis, closed 2015-01-20"
2123
2251
  [#586]:https://github.com/puma/puma/issues/586 "Issue by @ponchik, closed 2015-01-20"
2124
2252
  [#359]:https://github.com/puma/puma/issues/359 "Issue by @natew, closed 2014-12-13"
2125
2253
  [#633]:https://github.com/puma/puma/issues/633 "Issue by @joevandyk, closed 2015-01-20"
data/README.md CHANGED
@@ -16,7 +16,7 @@ Puma is a **simple, fast, multi-threaded, and highly concurrent HTTP 1.1 server
16
16
 
17
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.
18
18
 
19
- Puma was designed to be the go-to server for [Rubinius](https://rubinius.com), but also works well with JRuby and MRI.
19
+ Originally designed as a server for [Rubinius](https://github.com/rubinius/rubinius), Puma also works well with Ruby (MRI) and JRuby.
20
20
 
21
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.
22
22
 
@@ -212,6 +212,23 @@ Disable TLS v1 with the `no_tlsv1` option:
212
212
  $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true'
213
213
  ```
214
214
 
215
+ #### Controlling OpenSSL Verification Flags
216
+
217
+ To enable verification flags offered by OpenSSL, use `verification_flags` (not available for JRuby):
218
+
219
+ ```
220
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&verification_flags=PARTIAL_CHAIN'
221
+ ```
222
+
223
+ You can also set multiple verification flags (by separating them with coma):
224
+
225
+ ```
226
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&verification_flags=PARTIAL_CHAIN,CRL_CHECK'
227
+ ```
228
+
229
+ List of available flags: `USE_CHECK_TIME`, `CRL_CHECK`, `CRL_CHECK_ALL`, `IGNORE_CRITICAL`, `X509_STRICT`, `ALLOW_PROXY_CERTS`, `POLICY_CHECK`, `EXPLICIT_POLICY`, `INHIBIT_ANY`, `INHIBIT_MAP`, `NOTIFY_POLICY`, `EXTENDED_CRL_SUPPORT`, `USE_DELTAS`, `CHECK_SS_SIGNATURE`, `TRUSTED_FIRST`, `SUITEB_128_LOS_ONLY`, `SUITEB_192_LOS`, `SUITEB_128_LOS`, `PARTIAL_CHAIN`, `NO_ALT_CHAINS`, `NO_CHECK_TIME`
230
+ (see https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_hostflags.html#VERIFICATION-FLAGS).
231
+
215
232
  ### Control/Status Server
216
233
 
217
234
  Puma has a built-in status and control app that can be used to query and control Puma.
@@ -238,7 +255,7 @@ You can also provide a configuration file with the `-C` (or `--config`) flag:
238
255
  $ puma -C /path/to/config
239
256
  ```
240
257
 
241
- 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` or the `RAILS_ENV` environment variables, Puma looks for configuration at `config/puma/<environment_name>.rb`.
258
+ 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` or the `RAILS_ENV` environment variables, Puma first looks for configuration at `config/puma/<environment_name>.rb`, and then falls back to `config/puma.rb`.
242
259
 
243
260
  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:
244
261
 
@@ -266,6 +283,7 @@ Some platforms do not support all Puma features.
266
283
 
267
284
  * **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).
268
285
  * **Windows**: Cluster mode is not supported due to a lack of fork(2).
286
+ * **Kubernetes**: The way Kubernetes handles pod shutdowns interacts poorly with server processes implementing graceful shutdown, like Puma. See the [kubernetes section of the documentation](docs/kubernetes.md) for more details.
269
287
 
270
288
  ## Known Bugs
271
289
 
@@ -291,6 +309,10 @@ reliability in production environments:
291
309
  * [rc.d](docs/jungle/rc.d/README.md)
292
310
  * [systemd](docs/systemd.md)
293
311
 
312
+ Community guides:
313
+
314
+ * [Deploying Puma on OpenBSD using relayd and httpd](https://gist.github.com/anon987654321/4532cf8d6c59c1f43ec8973faa031103)
315
+
294
316
  ## Community Extensions
295
317
 
296
318
  ### Plugins
data/docs/architecture.md CHANGED
@@ -4,34 +4,38 @@
4
4
 
5
5
  ![https://bit.ly/2iJuFky](images/puma-general-arch.png)
6
6
 
7
- Puma is a threaded web server, processing requests across a TCP or UNIX socket.
7
+ Puma is a threaded Ruby HTTP application server, processing requests across a TCP or UNIX socket.
8
8
 
9
- Workers accept connections from the socket and a thread in the worker's thread pool processes the client's request.
10
9
 
11
- Clustered mode is shown/discussed here. Single mode is analogous to having a single worker process.
10
+ Puma processes (there can be one or many) accept connections from the socket via a thread (in the [`Reactor`](../lib/puma/reactor.rb) class). The connection, once fully buffered and read, moves in to the `todo` list, where it will be picked up by a free/waiting thread in the threadpool (the [`ThreadPool`](../lib/puma/thread_pool.rb) class).
12
11
 
13
- ## Connection pipeline
12
+ Puma works in two main modes: cluster and single. In single mode, only one Puma process is booted. In cluster mode, a `master` process is booted, which prepares (and may boot) the application, and then uses the `fork()` system call to create 1 or more `child` processes. These `child` processes all listen to the same socket. The `master` process does not listen to the socket or process requests - its purpose is mostly to manage and listen for UNIX signals and possibly kill or boot `child` processes.
13
+
14
+ We sometimes call `child` processes (or Puma processes in `single` mode) _workers_, and we sometimes call the threads created by Puma's [`ThreadPool`](../lib/puma/thread_pool.rb) _worker threads_.
15
+
16
+ ## How Requests Work
14
17
 
15
18
  ![https://bit.ly/2zwzhEK](images/puma-connection-flow.png)
16
19
 
17
20
  * Upon startup, Puma listens on a TCP or UNIX socket.
18
- * The backlog of this socket is configured (with a default of 1024), determining how many established but unaccepted connections can exist concurrently.
19
- * This socket backlog is distinct from the "backlog" of work as reported by the control server stats. The latter is the number of connections in that worker's "todo" set waiting for a worker thread.
20
- * By default, a single, separate thread is used to receive HTTP requests across the socket.
21
- * When at least one worker thread is available for work, a connection is accepted and placed in this request buffer
22
- * This thread waits for entire HTTP requests to be received over the connection
23
- * The time spent waiting for the HTTP request body to be received is exposed to the Rack app as `env['puma.request_body_wait']` (milliseconds)
24
- * Once received, the connection is pushed into the "todo" set
25
- * Worker threads pop work off the "todo" set for processing
26
- * The thread processes the request via the rack application (which generates the HTTP response)
27
- * The thread writes the response to the connection
28
- * Finally, the thread become available to process another connection in the "todo" set
29
-
30
- ### Disabling `queue_requests`
21
+ * The backlog of this socket is configured (with a default of 1024). This determines the size of the queue for unaccepted connections. Generally, this setting is unimportant and will never be hit in production use. If the backlog is full, the connection will be refused by the operating system.
22
+ * This socket backlog is distinct from the `backlog` of work as reported by `Puma.stats` or the control server. The backlog as reported by Puma is the number of connections in the process' `todo` set waiting for a thread from the [`ThreadPool`](../lib/puma/thread_pool.rb).
23
+ * By default, a single, separate thread (created by the [`Reactor`](../lib/puma/reactor.rb) class) is used to read and buffer requests from the socket.
24
+ * When at least one worker thread is available for work, the reactor thread listens to the socket and accepts a request, if one is waiting.
25
+ * The reactor thread waits for the entire HTTP request to be received.
26
+ * The time spent waiting for the HTTP request body to be received is exposed to the Rack app as `env['puma.request_body_wait']` (milliseconds).
27
+ * Once fully buffered and received, the connection is pushed into the "todo" set.
28
+ * Worker threads pop work off the "todo" set for processing.
29
+ * The worker thread processes the request via `call`ing the configured Rack application. The Rack application generates the HTTP response.
30
+ * The worker thread writes the response to the connection. Note that while Puma buffers requests via a separate thread, it does not use a separate thread for responses.
31
+ * Once done, the thread become available to process another connection in the "todo" set.
32
+
33
+ ### `queue_requests`
31
34
 
32
35
  ![https://bit.ly/2zxCJ1Z](images/puma-connection-flow-no-reactor.png)
33
36
 
34
- The `queue_requests` option is `true` by default, enabling the separate thread used to buffer requests as described above.
37
+ The `queue_requests` option is `true` by default, enabling the separate reactor thread used to buffer requests as described above.
35
38
 
36
39
  If set to `false`, this buffer will not be used for connections while waiting for the request to arrive.
40
+
37
41
  In this mode, when a connection is accepted, it is added to the "todo" queue immediately, and a worker will synchronously do any waiting necessary to read the HTTP request from the socket.
@@ -1,19 +1,19 @@
1
1
  # Compile Options
2
2
 
3
- There provide some `cflags` to change Puma's default configuration for C.
3
+ There are some `cflags` provided to change Puma's default configuration for its C extension.
4
4
 
5
- ## Query String
5
+ ## Query String, `PUMA_QUERY_STRING_MAX_LENGTH`
6
6
 
7
- By default, the max length of `QUERY_STRING` is `1024 * 10`. But you may want to adjust it to allow accept large queries in the GET requests.
7
+ By default, the max length of `QUERY_STRING` is `1024 * 10`. But you may want to adjust it to allow accept larger queries in GET requests.
8
8
 
9
- For manual install
9
+ For manual install, pass the `PUMA_QUERY_STRING_MAX_LENGTH` option like this:
10
10
 
11
11
  ```
12
12
  gem install puma -- --with-cflags="-D PUMA_QUERY_STRING_MAX_LENGTH=64000"
13
13
  ```
14
14
 
15
- For bundler config
15
+ For Bundler, use its configuration system:
16
16
 
17
17
  ```
18
- bundle config build.puma --with-cflags="-D PUMA_QUERY_STRING_MAX_LENGTH=64000"
18
+ bundle config build.puma "--with-cflags='-D PUMA_QUERY_STRING_MAX_LENGTH=64000'"
19
19
  ```
data/docs/deployment.md CHANGED
@@ -16,7 +16,7 @@ Welcome back!
16
16
 
17
17
  ## Single vs Cluster mode
18
18
 
19
- Puma was originally conceived as a thread-only webserver, but grew the ability to
19
+ Puma was originally conceived as a thread-only web server, but grew the ability to
20
20
  also use processes in version 2.
21
21
 
22
22
  To run `puma` in single mode (e.g. for a development environment) you will need to
@@ -29,7 +29,7 @@ Here are some rules of thumb for cluster mode:
29
29
  * Use cluster mode and set the number of workers to 1.5x the number of cpu cores
30
30
  in the machine, minimum 2.
31
31
  * Set the number of threads to desired concurrent requests / number of workers.
32
- Puma defaults to 16 and that's a decent number.
32
+ Puma defaults to 5 and that's a decent number.
33
33
 
34
34
  #### Migrating from Unicorn
35
35
 
@@ -1,6 +1,6 @@
1
1
  # Puma as a service using rc.d
2
2
 
3
- Manage multilpe Puma servers as services on one box using FreeBSD's rc.d service.
3
+ Manage multiple Puma servers as services on one box using FreeBSD's rc.d service.
4
4
 
5
5
  ## Dependencies
6
6
 
@@ -0,0 +1,66 @@
1
+ # Kubernetes
2
+
3
+ ## Running Puma in Kubernetes
4
+
5
+ In general running Puma in Kubernetes works as-is, no special configuration is needed beyond what you would write anyway to get a new Kubernetes Deployment going. There is one known interaction between the way Kubernetes handles pod termination and how Puma handles `SIGINT`, where some request might be sent to Puma after it has already entered graceful shutdown mode and is no longer accepting requests. This can lead to dropped requests during rolling deploys. A workaround for this is listed at the end of this article.
6
+
7
+ ## Basic setup
8
+
9
+ Assuming you already have a running cluster and docker image repository, you can run a simple Puma app with the following example Dockerfile and Deployment specification. These are meant as examples only and are deliberately very minimal to the point of skipping many options that are recommended for running in production, like healthchecks and envvar configuration with ConfigMaps. In general you should check the [Kubernetes documentation](https://kubernetes.io/docs/home/) and [Docker documentation](https://docs.docker.com/) for a more comprehensive overview of the available options.
10
+
11
+ A basic Dockerfile example:
12
+ ```
13
+ FROM ruby:2.5.1-alpine # can be updated to newer ruby versions
14
+ RUN apk update && apk add build-base # and any other packages you need
15
+
16
+ # Only rebuild gem bundle if Gemfile changes
17
+ COPY Gemfile Gemfile.lock ./
18
+ RUN bundle install
19
+
20
+ # Copy over the rest of the files
21
+ COPY . .
22
+
23
+ # Open up port and start the service
24
+ EXPOSE 9292
25
+ CMD bundle exec rackup -o 0.0.0.0
26
+ ```
27
+
28
+ A sample `deployment.yaml`:
29
+ ```
30
+ ---
31
+ apiVersion: apps/v1
32
+ kind: Deployment
33
+ metadata:
34
+ name: my-awesome-puma-app
35
+ spec:
36
+ selector:
37
+ matchLabels:
38
+ app: my-awesome-puma-app
39
+ template:
40
+ metadata:
41
+ labels:
42
+ app: my-awesome-puma-app
43
+ service: my-awesome-puma-app
44
+ spec:
45
+ containers:
46
+ - name: my-awesome-puma-app
47
+ image: <your image here>
48
+ ports:
49
+ - containerPort: 9292
50
+ ```
51
+
52
+ ## Graceful shutdown and pod termination
53
+
54
+ For some high-throughput systems, it is possible that some HTTP requests will return responses with response codes in the 5XX range during a rolling deploy to a new version. This is caused by [the way that Kubernetes terminates a pod during rolling deploys](https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-terminating-with-grace):
55
+
56
+ 1. The replication controller determines a pod should be shut down.
57
+ 2. The Pod is set to the “Terminating” State and removed from the endpoints list of all Services, so that it receives no more requests.
58
+ 3. The pods pre-stop hook get called. The default for this is to send `SIGTERM` to the process inside the pod.
59
+ 4. The pod has up to `terminationGracePeriodSeconds` (default: 30 seconds) to gracefully shut down. Puma will do this (after it receives SIGTERM) by closing down the socket that accepts new requests and finishing any requests already running before exiting the Puma process.
60
+ 5. If the pod is still running after `terminationGracePeriodSeconds` has elapsed, the pod receives `SIGKILL` to make sure the process inside it stops. After that, the container exits and all other Kubernetes objects associated with it are cleaned up.
61
+
62
+ There is a subtle race condition between step 2 and 3: The replication controller does not synchronously remove the pod from the Services AND THEN call the pre-stop hook of the pod, but rather it asynchronously sends "remove this pod from your endpoints" requests to the Services and then immediately proceeds to invoke the pods' pre-stop hook. If the Service controller (typically something like nginx or haproxy) receives this request handles this request "too" late (due to internal lag or network latency between the replication and Service controllers) then it is possible that the Service controller will send one or more requests to a Puma process which has already shut down its listening socket. These requests will then fail with 5XX error codes.
63
+
64
+ The way Kubernetes works this way, rather than handling step 2 synchronously, is due to the CAP theorem: in a distributed system there is no way to guarantee that any message will arrive promptly. In particular, waiting for all Service controllers to report back might get stuck for an indefinite time if one of them has already been terminated or if there has been a net split. A way to work around this is to add a sleep to the pre-stop hook of the same time as the `terminationGracePeriodSeconds` time. This will allow the Puma process to keep serving new requests during the entire grace period, although it will no longer receive new requests after all Service controllers have propagated the removal of the pod from their endpoint lists. Then, after `terminationGracePeriodSeconds`, the pod receives `SIGKILL` and closes down. If your process can't handle SIGKILL properly, for example because it needs to release locks in different services, you can also sleep for a shorter period (and/or increase `terminationGracePeriodSeconds`) as long as the time slept is longer than the time that your Service controllers take to propagate the pod removal. The downside of this workaround is that all pods will take at minimum the amount of time slept to shut down and this will increase the time required for your rolling deploy.
65
+
66
+ More discussions and links to relevant articles can be found in https://github.com/puma/puma/issues/2343.