puma 6.6.1 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +224 -4
  3. data/README.md +34 -34
  4. data/docs/deployment.md +58 -23
  5. data/docs/fork_worker.md +5 -5
  6. data/docs/jungle/README.md +1 -1
  7. data/docs/kubernetes.md +11 -16
  8. data/docs/plugins.md +2 -2
  9. data/docs/restart.md +2 -2
  10. data/docs/signals.md +19 -19
  11. data/docs/stats.md +4 -3
  12. data/docs/systemd.md +3 -3
  13. data/ext/puma_http11/extconf.rb +2 -17
  14. data/ext/puma_http11/mini_ssl.c +18 -8
  15. data/ext/puma_http11/org/jruby/puma/Http11.java +9 -1
  16. data/ext/puma_http11/puma_http11.c +122 -118
  17. data/lib/puma/app/status.rb +10 -2
  18. data/lib/puma/binder.rb +10 -8
  19. data/lib/puma/cli.rb +3 -5
  20. data/lib/puma/client.rb +52 -56
  21. data/lib/puma/cluster/worker.rb +17 -17
  22. data/lib/puma/cluster/worker_handle.rb +38 -7
  23. data/lib/puma/cluster.rb +23 -23
  24. data/lib/puma/cluster_accept_loop_delay.rb +91 -0
  25. data/lib/puma/commonlogger.rb +3 -3
  26. data/lib/puma/configuration.rb +104 -51
  27. data/lib/puma/const.rb +9 -10
  28. data/lib/puma/control_cli.rb +6 -2
  29. data/lib/puma/detect.rb +2 -0
  30. data/lib/puma/dsl.rb +149 -91
  31. data/lib/puma/error_logger.rb +3 -1
  32. data/lib/puma/events.rb +25 -10
  33. data/lib/puma/io_buffer.rb +8 -4
  34. data/lib/puma/launcher/bundle_pruner.rb +1 -1
  35. data/lib/puma/launcher.rb +54 -49
  36. data/lib/puma/minissl.rb +0 -1
  37. data/lib/puma/plugin/systemd.rb +3 -3
  38. data/lib/puma/rack/urlmap.rb +1 -1
  39. data/lib/puma/reactor.rb +19 -13
  40. data/lib/puma/request.rb +42 -31
  41. data/lib/puma/runner.rb +9 -18
  42. data/lib/puma/server.rb +114 -64
  43. data/lib/puma/single.rb +6 -3
  44. data/lib/puma/state_file.rb +3 -2
  45. data/lib/puma/thread_pool.rb +47 -82
  46. data/lib/puma/util.rb +0 -7
  47. data/lib/puma.rb +10 -0
  48. data/lib/rack/handler/puma.rb +2 -2
  49. data/tools/Dockerfile +13 -5
  50. metadata +6 -5
  51. data/ext/puma_http11/ext_help.h +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 574e9afd59afd9a6d5b86bd74cc7e524e73982b61ca294884540cb54324771bf
4
- data.tar.gz: 4702dc966028a0cb7c7f912ba6cdc33446071e8cd13ea63f14070f247f5d4504
3
+ metadata.gz: cf20ee32c008736a0ecf6072333f9204d0845fe98c65de34cafed9d6cbcbf407
4
+ data.tar.gz: 8dc8d19a8648c5db1f64ae0f84e5c97c0db890fa92183fbb6372ae209e56f449
5
5
  SHA512:
6
- metadata.gz: 89dccb7f7cde9cc70904c28cf6026022239eac61fe8c903d924f10e50a59d17876d181feb4c80c7b4315c46d166fdcca7743dca16a3c52e27827f2e2d39a8ec3
7
- data.tar.gz: c30aa7e48f3b6c191351ebe5c9b407fec7b2523c679bc915c21aefb854b0b43e7b9d776fcc3fdef574da70df71225ae4dbb78ed7045f4b178ae8a8578ae48efd
6
+ metadata.gz: 18033fd5ca12182ac421125433082f1b919deb43abc3a525c45db1d256c65e557feb273e785798d3606fd12638140ba1fba2e3189a2ca70855f59c074ba63ea4
7
+ data.tar.gz: 6c6bad3a44ad2aaefde1a7d4aab2d50dcdb7d10333f2efa05cf0031aaa4ad702226b8038155fe78b2689e7e38b51fb8bcd26c3d643f3a1b1bbcdb9293f65d16c
data/History.md CHANGED
@@ -1,3 +1,137 @@
1
+ ## 7.2.0 / 2026-01-20
2
+
3
+ * Features
4
+ * Add workers `:auto` ([#3827])
5
+ * Make it possible to restrict control server commands to stats ([#3787])
6
+
7
+ * Bugfixes
8
+ * Don't break if `WEB_CONCURRENCY` is set to a blank string ([#3837])
9
+ * Don't share server between worker 0 and descendants on refork ([#3602])
10
+ * Fix phase check race condition in `Puma::Cluster#check_workers` ([#3690])
11
+ * Fix advertising of CLI config before config files are loaded ([#3823])
12
+
13
+ * Performance
14
+ * 17% faster HTTP parsing through pre-interning env keys ([#3825])
15
+ * Implement `dsize` and `dcompact` functions for `Puma::HttpParser`, which makes Puma's C-extension GC-compactible ([#3828])
16
+
17
+ * Refactor
18
+ * Remove `NoMethodError` rescue in `Reactor#select_loop` ([#3831])
19
+ * Various cleanups in the C extension ([#3814])
20
+ * Monomorphize `handle_request` return ([#3802])
21
+
22
+ * Docs
23
+ * Change link to `docs/deployment.md` in `README.md` ([#3848])
24
+ * Fix formatting for each signal description in signals.md ([#3813])
25
+ * Update deployment and Kubernetes docs with Puma configuration tips ([#3807])
26
+ * Rename master to main ([#3809], [#3808], [#3800])
27
+ * Fix some minor typos in the docs ([#3804])
28
+ * Add `GOVERNANCE.md`, `MAINTAINERS` ([#3826])
29
+ * Remove Code Climate badge ([#3820])
30
+ * Add @joshuay03 to the maintainer list
31
+
32
+ * CI
33
+ * Use Minitest 6 where applicable ([#3859])
34
+ * Many test suite improvements and flake fixes ([#3861], [#3863], [#3860], [#3852], [#3857], [#3856], [#3845], [#3843], [#3842], [#3841], [#3822], [#3817], [#3764])
35
+
36
+ ## 7.1.0 / 2025-10-16
37
+
38
+ * Features
39
+ * Introduce `after_worker_shutdown` hook ([#3707])
40
+ * Reintroduce keepalive "fast inline" behavior. Provides faster (8x on JRuby & 1.4x on Ruby) pipeline processing ([#3794])
41
+
42
+ * Bugfixes
43
+ * Skip reading zero bytes when request body is buffered ([#3795])
44
+ * Fix `PUMA_LOG_CONFIG=1` logging twice with prune_bundler enabled ([#3778])
45
+ * Fix prune_bundler not showing in `PUMA_LOG_CONFIG=1` output ([#3779])
46
+ * Guard ThreadPool method call, which may be nil during shutdown ([#3791], [#3790])
47
+ * Set `Thread.current.puma_server` in Thread init code, not every request ([#3774])
48
+ * Fix race condition while deleting pidfile ([#3657])
49
+
50
+ ## 7.0.4 / 2025-09-23
51
+
52
+ * Bugfixes
53
+ * Fix SSL_shutdown error handling ([#3703])
54
+ * Strip whitespace from the beginnings of request header values. ([#3742])
55
+
56
+ * Performance
57
+ * puma_http11.c: Use interned UTF-8 strings for hash keys ([#3754])
58
+ * Move sleep cluster logic to its own class ([#3746], [#3740])
59
+
60
+ ## 7.0.3 / 2025-09-13
61
+
62
+ * Performance
63
+ * server.rb - process_client - add ka to todo if readable & complete ([#3748])
64
+
65
+ * Bugfixes
66
+ * Convert PUMA_PERSISTENT_TIMEOUT to an Integer ([#3749])
67
+
68
+ ## 7.0.2 / 2025-09-08
69
+
70
+ * Bugfixes
71
+ * bug: control_cli.rb - Fixup `pumactl` code to load puma.rb for `deprecate_method_change` ([#3736], [#3734])
72
+ * Replace sleep spin lock with condition variable ([#3729])
73
+ * Fix Puma not booting if queue_requests disabled ([#3731])
74
+
75
+ ## 7.0.1 / 2025-09-06
76
+
77
+ * Bugfixes
78
+ * Add backward compatibility aliases for Events class methods ([#3725])
79
+
80
+ ## 7.0.0 / 2025-09-03
81
+
82
+ * Breaking changes
83
+ * Set default `max_keep_alive` to 999 ([#3719])
84
+ * Increase `persistent_timeout` default to 65 seconds ([#3378])
85
+ * Raise an ArgumentError if no block given to hooks ([#3377])
86
+ * Don't set env['HTTP_VERSION'] for Rack > 3.1 ([#3711], [#3576])
87
+ * Runner.rb - remove `ruby_engine` method, deprecated Nov-2024 ([#3701])
88
+ * Config `preload_app!` is now the default for clustered mode ([#3297])
89
+ * Config instance must be `clamp`-d before reading any values ([#3297])
90
+ * Response headers set to lowercase ([#3704])
91
+ * Update minimum Ruby version to 3.0 ([#3698])
92
+ * Rename callback hooks ([#3438])
93
+
94
+ | Old hook name| New hook name|
95
+ |----------|----------|
96
+ | on_worker_boot | before_worker_boot |
97
+ | on_worker_shutdown | before_worker_shutdown |
98
+ | on_restart | before_restart |
99
+ | on_booted | after_booted |
100
+ | on_stopped | after_stopped |
101
+ | on_refork | before_refork |
102
+ | on_thread_start | before_thread_start |
103
+ | on_thread_exit | before_thread_exit |
104
+ | on_worker_fork | before_worker_fork |
105
+
106
+ * Features
107
+ * Fix long tail response problem with keepalive connections ([#3678]) (Previously released in 7.0.0.pre1, this was a high effort change)
108
+ * Introduce support for fiber-per-request. ([#3101])
109
+ * Add support for `rack.response_finished` ([#3681])
110
+ * Feature/support custom logger with request logs ([#3140])
111
+
112
+ * Bugfixes
113
+ * Fix error_logger inproperly logging `env[QUERY_STRING]` ([#3713], [#3625])
114
+ * Fix handling of invalid Transfer-Encoding header errors ([#3702])
115
+ * Fix socket leak on monitor wakeup `NoMethodError` in `Reactor#select_loop` ([#3696], [#3695])
116
+ * CI: puma_socket.rb fixup socket/request writes ([#3684])
117
+ * Warn when RUBY_MN_THREADS env var is set ([#3721])
118
+ * Improve the DSL `preload_app!` doc ([#3712])
119
+ * Fix the ability to focus individual tests ([#3705])
120
+ * Set env['rack.hijack'] to client.method(:full_hijack) ([#3073])
121
+
122
+ * Performance
123
+ * server.rb - initialize ivars `@reactor` and `@env_set_http_version` ([#3714])
124
+
125
+ * Refactor
126
+ * Simplify `Puma::DSL#process_hook` logic ([#3710])
127
+ * Dry up deprecation warnings and fix deprecation warnings when running CI. ([#3709], [#3708])
128
+ * Ensure and enforce that configs are loaded before options are accessed ([#3616])
129
+
130
+ ## 7.0.0.pre1 / 2025-07-31
131
+
132
+ * Changed
133
+ * Fix long tail response problem with keepalive connections ([#3678])
134
+
1
135
  ## 6.6.1 / 2025-07-30
2
136
 
3
137
  * Bugfixes
@@ -2160,12 +2294,98 @@ be added back in a future date when a java Puma::MiniSSL is added.
2160
2294
  * Bugfixes
2161
2295
  * Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
2162
2296
 
2163
- [#3680]:https://github.com/puma/puma/pull/3680 "PR by @byroot, merged 2025-07-31"
2297
+ [#3863]:https://github.com/puma/puma/pull/3863 "PR by Nate Berkopec, merged 2026-01-20"
2298
+ [#3861]:https://github.com/puma/puma/pull/3861 "PR by MSP-Greg, merged 2026-01-20"
2299
+ [#3860]:https://github.com/puma/puma/pull/3860 "PR by MSP-Greg, merged 2026-01-16"
2300
+ [#3859]:https://github.com/puma/puma/pull/3859 "PR by MSP-Greg, merged 2026-01-16"
2301
+ [#3857]:https://github.com/puma/puma/pull/3857 "PR by Aaron Patterson, merged 2026-01-12"
2302
+ [#3856]:https://github.com/puma/puma/pull/3856 "PR by MSP-Greg, merged 2026-01-12"
2303
+ [#3852]:https://github.com/puma/puma/pull/3852 "PR by Miłosz Bieniek, merged 2026-01-14"
2304
+ [#3848]:https://github.com/puma/puma/pull/3848 "PR by Miłosz Bieniek, merged 2025-12-27"
2305
+ [#3845]:https://github.com/puma/puma/pull/3845 "PR by MSP-Greg, merged 2025-12-19"
2306
+ [#3843]:https://github.com/puma/puma/pull/3843 "PR by MSP-Greg, merged 2025-12-18"
2307
+ [#3842]:https://github.com/puma/puma/pull/3842 "PR by MSP-Greg, merged 2025-12-18"
2308
+ [#3841]:https://github.com/puma/puma/pull/3841 "PR by MSP-Greg, merged 2025-12-18"
2309
+ [#3837]:https://github.com/puma/puma/pull/3837 "PR by John Bachir, merged 2026-01-09"
2310
+ [#3833]:https://github.com/puma/puma/pull/3833 "PR by Patrik Ragnarsson, merged 2025-11-25"
2311
+ [#3831]:https://github.com/puma/puma/pull/3831 "PR by Joshua Young, merged 2025-11-25"
2312
+ [#3828]:https://github.com/puma/puma/pull/3828 "PR by Jean Boussier, merged 2025-11-21"
2313
+ [#3827]:https://github.com/puma/puma/pull/3827 "PR by Nate Berkopec, merged 2026-01-20"
2314
+ [#3826]:https://github.com/puma/puma/pull/3826 "PR by Nate Berkopec, merged 2026-01-20"
2315
+ [#3825]:https://github.com/puma/puma/pull/3825 "PR by Jean Boussier, merged 2025-11-19"
2316
+ [#3823]:https://github.com/puma/puma/pull/3823 "PR by Joshua Young, merged 2025-11-18"
2317
+ [#3822]:https://github.com/puma/puma/pull/3822 "PR by Nate Berkopec, merged 2025-11-17"
2318
+ [#3820]:https://github.com/puma/puma/pull/3820 "PR by Nate Berkopec, merged 2025-11-19"
2319
+ [#3817]:https://github.com/puma/puma/pull/3817 "PR by Nate Berkopec, merged 2025-11-17"
2320
+ [#3814]:https://github.com/puma/puma/pull/3814 "PR by Jean Boussier, merged 2025-11-17"
2321
+ [#3813]:https://github.com/puma/puma/pull/3813 "PR by Masafumi Koba, merged 2025-11-17"
2322
+ [#3809]:https://github.com/puma/puma/pull/3809 "PR by Patrik Ragnarsson, merged 2025-10-26"
2323
+ [#3808]:https://github.com/puma/puma/pull/3808 "PR by Nymuxyzo, merged 2025-10-26"
2324
+ [#3807]:https://github.com/puma/puma/pull/3807 "PR by Nate Berkopec, merged 2025-10-28"
2325
+ [#3804]:https://github.com/puma/puma/pull/3804 "PR by Joe Rafaniello, merged 2025-10-21"
2326
+ [#3802]:https://github.com/puma/puma/pull/3802 "PR by Richard Schneeman, merged 2025-10-20"
2327
+ [#3800]:https://github.com/puma/puma/pull/3800 "PR by MSP-Greg, merged 2025-10-19"
2328
+ [#3787]:https://github.com/puma/puma/pull/3787 "PR by Stan Hu, merged 2025-10-17"
2329
+ [#3764]:https://github.com/puma/puma/pull/3764 "PR by MSP-Greg, merged 2025-10-17"
2330
+ [#3690]:https://github.com/puma/puma/pull/3690 "PR by Joshua Young, merged 2025-11-18"
2331
+ [#3602]:https://github.com/puma/puma/pull/3602 "PR by Joshua Young, merged 2025-11-28"
2332
+
2333
+ [#3707]:https://github.com/puma/puma/pull/3707 "PR by @nerdrew, merged 2025-10-02"
2334
+ [#3794]:https://github.com/puma/puma/pull/3794 "PR by @schneems, merged 2025-10-16"
2335
+ [#3795]:https://github.com/puma/puma/pull/3795 "PR by @MSP-Greg, merged 2025-10-16"
2336
+ [#3778]:https://github.com/puma/puma/pull/3778 "PR by @joshuay03, merged 2025-10-16"
2337
+ [#3779]:https://github.com/puma/puma/pull/3779 "PR by @joshuay03, merged 2025-10-16"
2338
+ [#3791]:https://github.com/puma/puma/pull/3791 "PR by @MSP-Greg, merged 2025-10-09"
2339
+ [#3790]:https://github.com/puma/puma/issues/3790 "Issue by @eric-wtfoxtrot, closed 2025-10-09"
2340
+ [#3774]:https://github.com/puma/puma/pull/3774 "PR by @MSP-Greg, merged 2025-10-16"
2341
+ [#3657]:https://github.com/puma/puma/pull/3657 "PR by @marksmith, merged 2025-10-16"
2342
+ [#3703]:https://github.com/puma/puma/pull/3703 "PR by @marshall-lee, merged 2025-09-20"
2343
+ [#3742]:https://github.com/puma/puma/pull/3742 "PR by @kenballus, merged 2025-09-18"
2344
+ [#3754]:https://github.com/puma/puma/pull/3754 "PR by @byroot, merged 2025-09-18"
2345
+ [#3746]:https://github.com/puma/puma/pull/3746 "PR by @schneems, merged 2025-09-18"
2346
+ [#3740]:https://github.com/puma/puma/issues/3740 "Issue by @joshuay03, closed 2025-09-18"
2347
+ [#3748]:https://github.com/puma/puma/pull/3748 "PR by @MSP-Greg, merged 2025-09-14"
2348
+ [#3749]:https://github.com/puma/puma/pull/3749 "PR by @schneems, merged 2025-09-14"
2349
+ [#3736]:https://github.com/puma/puma/pull/3736 "PR by @MSP-Greg, merged 2025-09-08"
2350
+ [#3734]:https://github.com/puma/puma/issues/3734 "Issue by @espen, closed 2025-09-08"
2351
+ [#3729]:https://github.com/puma/puma/pull/3729 "PR by @bensheldon, merged 2025-09-08"
2352
+ [#3731]:https://github.com/puma/puma/pull/3731 "PR by @stanhu, merged 2025-09-06"
2353
+ [#3725]:https://github.com/puma/puma/pull/3725 "PR by @tannakartikey, merged 2025-09-05"
2354
+ [#3719]:https://github.com/puma/puma/pull/3719 "PR by @schneems, merged 2025-09-03"
2355
+ [#3378]:https://github.com/puma/puma/pull/3378 "PR by @shayonj, merged 2025-08-19"
2356
+ [#3377]:https://github.com/puma/puma/pull/3377 "PR by @joshuay03, merged 2025-08-12"
2357
+ [#3711]:https://github.com/puma/puma/pull/3711 "PR by @MSP-Greg, merged 2025-08-28"
2358
+ [#3576]:https://github.com/puma/puma/issues/3576 "Issue by @pdalberti, closed 2025-08-28"
2359
+ [#3701]:https://github.com/puma/puma/pull/3701 "PR by @MSP-Greg, merged 2025-08-26"
2360
+ [#3297]:https://github.com/puma/puma/pull/3297 "PR by @joshuay03, merged 2025-08-26"
2361
+ [#3704]:https://github.com/puma/puma/pull/3704 "PR by @schneems, merged 2025-08-25"
2362
+ [#3698]:https://github.com/puma/puma/pull/3698 "PR by @schneems, merged 2025-08-21"
2363
+ [#3438]:https://github.com/puma/puma/pull/3438 "PR by @tannakartikey, merged 2025-08-25"
2364
+ [#3678]:https://github.com/puma/puma/pull/3678 "PR by @MSP-Greg, merged 2025-07-31"
2365
+ [#3101]:https://github.com/puma/puma/pull/3101 "PR by @ioquatix, merged 2025-08-25"
2366
+ [#3681]:https://github.com/puma/puma/pull/3681 "PR by @byroot, merged 2025-08-15"
2367
+ [#3140]:https://github.com/puma/puma/pull/3140 "PR by @phyzical, merged 2025-08-12"
2368
+ [#3713]:https://github.com/puma/puma/pull/3713 "PR by @MSP-Greg, merged 2025-08-29"
2369
+ [#3625]:https://github.com/puma/puma/pull/3625 "PR by @bhooshiek-narendiran, closed 2025-08-29"
2370
+ [#3702]:https://github.com/puma/puma/pull/3702 "PR by @marshall-lee, merged 2025-08-25"
2371
+ [#3696]:https://github.com/puma/puma/pull/3696 "PR by @joshuay03, merged 2025-08-22"
2372
+ [#3695]:https://github.com/puma/puma/issues/3695 "Issue by @joshuay03, closed 2025-08-22"
2373
+ [#3684]:https://github.com/puma/puma/pull/3684 "PR by @MSP-Greg, merged 2025-08-02"
2374
+ [#3721]:https://github.com/puma/puma/pull/3721 "PR by @schneems, merged 2025-09-03"
2375
+ [#3712]:https://github.com/puma/puma/pull/3712 "PR by @joshuay03, merged 2025-08-28"
2376
+ [#3705]:https://github.com/puma/puma/pull/3705 "PR by @schneems, merged 2025-08-25"
2377
+ [#3073]:https://github.com/puma/puma/pull/3073 "PR by @MSP-Greg, merged 2025-08-12"
2378
+ [#3714]:https://github.com/puma/puma/pull/3714 "PR by @MSP-Greg, merged 2025-08-29"
2379
+ [#3710]:https://github.com/puma/puma/pull/3710 "PR by @joshuay03, merged 2025-08-28"
2380
+ [#3709]:https://github.com/puma/puma/pull/3709 "PR by @MSP-Greg, merged 2025-08-28"
2381
+ [#3708]:https://github.com/puma/puma/issues/3708 "Issue by @schneems, closed 2025-08-28"
2382
+ [#3616]:https://github.com/puma/puma/pull/3616 "PR by @joshuay03, merged 2025-08-25"
2383
+ [#3635]:https://github.com/puma/puma/pull/3635 "PR by @LevitatingBusinessMan, merged 2025-05-08"
2164
2384
  [#3572]:https://github.com/puma/puma/pull/3572 "PR by @barthez, merged 2025-02-06"
2385
+ [#3601]:https://github.com/puma/puma/pull/3601 "PR by @joshuay03, merged 2025-01-31"
2165
2386
  [#3586]:https://github.com/puma/puma/pull/3586 "PR by @MSP-Greg, merged 2025-02-03"
2166
2387
  [#3598]:https://github.com/puma/puma/pull/3598 "PR by @joshuay03, merged 2025-01-31"
2167
- [#3601]:https://github.com/puma/puma/pull/3601 "PR by @joshuay03, merged 2025-01-31"
2168
- [#3635]:https://github.com/puma/puma/pull/3635 "PR by @LevitatingBusinessMan, merged 2025-05-08"
2388
+ [#3680]:https://github.com/puma/puma/pull/3680 "PR by @byroot, merged 2025-07-31"
2169
2389
  [#3570]:https://github.com/puma/puma/pull/3570 "PR by @mohamedhafez, merged 2024-12-30"
2170
2390
  [#3567]:https://github.com/puma/puma/issues/3567 "Issue by @mohamedhafez, closed 2024-12-30"
2171
2391
  [#3383]:https://github.com/puma/puma/pull/3383 "PR by @joshuay03, merged 2024-11-29"
@@ -2764,7 +2984,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
2764
2984
  [#1022]:https://github.com/puma/puma/issues/1022 "Issue by @AKovtunov, closed 2017-08-16"
2765
2985
  [#958]:https://github.com/puma/puma/issues/958 "Issue by @lalitlogical, closed 2016-04-23"
2766
2986
  [#782]:https://github.com/puma/puma/issues/782 "Issue by @Tonkpils, closed 2016-07-19"
2767
- [#1010]:https://github.com/puma/puma/issues/1010 "Issue by @mneumark, closed 2016-07-19"
2987
+ [#1010]:https://github.com/puma/puma/issues/1010 "Issue by @mirineumark, closed 2016-07-19"
2768
2988
  [#959]:https://github.com/puma/puma/issues/959 "Issue by @mwpastore, closed 2016-04-22"
2769
2989
  [#840]:https://github.com/puma/puma/issues/840 "Issue by @marisawallace, closed 2016-04-07"
2770
2990
  [#1007]:https://github.com/puma/puma/pull/1007 "PR by @willnet, merged 2016-06-24"
data/README.md CHANGED
@@ -4,8 +4,7 @@
4
4
 
5
5
  # Puma: A Ruby Web Server Built For Parallelism
6
6
 
7
- [![Actions](https://github.com/puma/puma/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/puma/puma/actions/workflows/tests.yml?query=branch%3Amaster)
8
- [![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
7
+ [![Actions](https://github.com/puma/puma/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/puma/puma/actions/workflows/tests.yml?query=branch%3Amain)
9
8
  [![StackOverflow](https://img.shields.io/badge/stackoverflow-Puma-blue.svg)]( https://stackoverflow.com/questions/tagged/puma )
10
9
 
11
10
  Puma is a **simple, fast, multi-threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications**.
@@ -82,10 +81,10 @@ $ bundle exec puma
82
81
 
83
82
  ## Configuration
84
83
 
85
- Puma provides numerous options. Consult `puma -h` (or `puma --help`) for a full list of CLI options, or see `Puma::DSL` or [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb).
84
+ Puma provides numerous options. Consult `puma -h` (or `puma --help`) for a full list of CLI options, or see `Puma::DSL` or [dsl.rb](https://github.com/puma/puma/blob/main/lib/puma/dsl.rb).
86
85
 
87
86
  You can also find several configuration examples as part of the
88
- [test](https://github.com/puma/puma/tree/master/test/config) suite.
87
+ [test](https://github.com/puma/puma/tree/main/test/config) suite.
89
88
 
90
89
  For debugging purposes, you can set the environment variable `PUMA_LOG_CONFIG` with a value
91
90
  and the loaded configuration will be printed as part of the boot process.
@@ -116,15 +115,24 @@ Or with the `WEB_CONCURRENCY` environment variable:
116
115
  $ WEB_CONCURRENCY=3 puma -t 8:32
117
116
  ```
118
117
 
118
+ When using a config file, most applications can simply set `workers :auto` (requires the `concurrent-ruby` gem) to match the number of worker processes to the available processors:
119
+
120
+ ```ruby
121
+ # config/puma.rb
122
+ workers :auto
123
+ ```
124
+
125
+ See [`workers :auto` gotchas](lib/puma/dsl.rb).
126
+
119
127
  Note that threads are still used in cluster 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.
120
128
 
121
- If the `WEB_CONCURRENCY` environment variable is set to `"auto"` and the `concurrent-ruby` gem is available in your application, Puma will set the worker process count to the result of [available processors](https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent.html#available_processor_count-class_method).
129
+ If `workers` is set to `:auto`, or the `WEB_CONCURRENCY` environment variable is set to `"auto"`, and the `concurrent-ruby` gem is available in your application, Puma will set the worker process count to the result of [available processors](https://msp-greg.github.io/concurrent-ruby/Concurrent.html#available_processor_count-class_method).
122
130
 
123
- For an in-depth discussion of the tradeoffs of thread and process count settings, [see our docs](https://github.com/puma/puma/blob/9282a8efa5a0c48e39c60d22ca70051a25df9f55/docs/kubernetes.md#workers-per-pod-and-other-config-issues).
131
+ For an in-depth discussion of the tradeoffs of thread and process count settings, [see our docs](docs/deployment.md).
124
132
 
125
133
  In cluster 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).
126
134
 
127
- If the `WEB_CONCURRENCY` environment variable is set to a value > 1 (and `--prune-bundler` has not been specified), preloading will be enabled by default. Otherwise, you can use the `--preload` flag from the command line:
135
+ If the number of workers is greater than 1 (and `--prune-bundler` has not been specified), preloading will be enabled by default. Otherwise, you can use the `--preload` flag from the command line:
128
136
 
129
137
  ```
130
138
  $ puma -w 3 --preload
@@ -142,8 +150,8 @@ Preloading can’t be used with phased restart, since phased restart kills and r
142
150
 
143
151
  #### Cluster mode hooks
144
152
 
145
- When using cluster mode, Puma's configuration DSL provides `before_fork` and `on_worker_boot`
146
- hooks to run code when the master process forks and child workers are booted respectively.
153
+ When using clustered mode, Puma's configuration DSL provides `before_fork`, `before_worker_boot`, and `after_worker_shutdown`
154
+ hooks to run code when the master process forks, the child workers are booted, and after each child worker exits respectively.
147
155
 
148
156
  It is recommended to use these hooks with `preload_app!`, otherwise constants loaded by your
149
157
  application (such as `Rails`) will not be available inside the hooks.
@@ -154,16 +162,21 @@ before_fork do
154
162
  # Add code to run inside the Puma master process before it forks a worker child.
155
163
  end
156
164
 
157
- on_worker_boot do
165
+ before_worker_boot do
158
166
  # Add code to run inside the Puma worker process after forking.
159
167
  end
168
+
169
+ after_worker_shutdown do |worker_handle|
170
+ # Add code to run inside the Puma master process after a worker exits. `worker.process_status` can be used to get the
171
+ # `Process::Status` of the exited worker.
172
+ end
160
173
  ```
161
174
 
162
- In addition, there is an `on_refork` and `after_refork` hooks which are used only in [`fork_worker` mode](docs/fork_worker.md),
175
+ In addition, there is an `before_refork` and `after_refork` hooks which are used only in [`fork_worker` mode](docs/fork_worker.md),
163
176
  when the worker 0 child process forks a grandchild worker:
164
177
 
165
178
  ```ruby
166
- on_refork do
179
+ before_refork do
167
180
  # Used only when fork_worker mode is enabled. Add code to run inside the Puma worker 0
168
181
  # child process before it forks a grandchild worker.
169
182
  end
@@ -190,29 +203,29 @@ Therefore, we recommend the following:
190
203
 
191
204
  1. If possible, do not establish any socket connections (HTTP, database connections, etc.)
192
205
  inside Puma's master process when booting.
193
- 2. If (1) is not possible, use `before_fork` and `on_refork` to disconnect the parent's socket
206
+ 2. If (1) is not possible, use `before_fork` and `before_refork` to disconnect the parent's socket
194
207
  connections when forking, so that they are not accidentally copied to the child process.
195
- 3. Use `on_worker_boot` to restart any background threads on the forked child.
208
+ 3. Use `before_worker_boot` to restart any background threads on the forked child.
196
209
  4. Use `after_refork` to restart any background threads on the parent.
197
210
 
198
211
  #### Master process lifecycle hooks
199
212
 
200
- Puma's configuration DSL provides master process lifecycle hooks `on_booted`, `on_restart`, and `on_stopped`
213
+ Puma's configuration DSL provides master process lifecycle hooks `after_booted`, `before_restart`, and `after_stopped`
201
214
  which may be used to specify code blocks to run on each event:
202
215
 
203
216
  ```ruby
204
217
  # config/puma.rb
205
- on_booted do
218
+ after_booted do
206
219
  # Add code to run in the Puma master process after it boots,
207
220
  # and also after a phased restart completes.
208
221
  end
209
222
 
210
- on_restart do
223
+ before_restart do
211
224
  # Add code to run in the Puma master process when it receives
212
225
  # a restart command but before it restarts.
213
226
  end
214
227
 
215
- on_stopped do
228
+ after_stopped do
216
229
  # Add code to run in the Puma master process when it receives
217
230
  # a stop command but before it shuts down.
218
231
  end
@@ -221,7 +234,7 @@ end
221
234
  ### Error handling
222
235
 
223
236
  If Puma encounters an error outside of the context of your application, it will respond with a 400/500 and a simple
224
- textual error message (see `Puma::Server#lowlevel_error` or [server.rb](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
237
+ textual error message (see `Puma::Server#lowlevel_error` or [server.rb](https://github.com/puma/puma/blob/main/lib/puma/server.rb)).
225
238
  You can specify custom behavior for this scenario. For example, you can report the error to your third-party
226
239
  error-tracking service (in this example, [rollbar](https://rollbar.com)):
227
240
 
@@ -380,7 +393,7 @@ Puma has a built-in status and control app that can be used to query and control
380
393
  $ puma --control-url tcp://127.0.0.1:9293 --control-token foo
381
394
  ```
382
395
 
383
- 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 `Puma::App::Status` or [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the status app has available.
396
+ 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 `Puma::App::Status` or [status.rb](https://github.com/puma/puma/blob/main/lib/puma/app/status.rb) to see what the status app has available.
384
397
 
385
398
  You can also interact with the control server via `pumactl`. This command will restart Puma:
386
399
 
@@ -412,7 +425,7 @@ $ puma -C "-"
412
425
 
413
426
  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 in `Puma::Configuration#puma_default_options` or [configuration.rb](https://github.com/puma/puma/blob/61c6213fbab/lib/puma/configuration.rb#L182-L204).
414
427
 
415
- Check out `Puma::DSL` or [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb) to see all available options.
428
+ Check out `Puma::DSL` or [dsl.rb](https://github.com/puma/puma/blob/main/lib/puma/dsl.rb) to see all available options.
416
429
 
417
430
  ## Restart
418
431
 
@@ -432,19 +445,6 @@ Some platforms do not support all Puma features.
432
445
  * **Windows**: Cluster mode is not supported due to a lack of fork(2).
433
446
  * **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.
434
447
 
435
- ## Known Bugs
436
-
437
- 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:
438
-
439
- ```ruby
440
- if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
441
- begin
442
- require 'stopgap_13632'
443
- rescue LoadError
444
- end
445
- end
446
- ```
447
-
448
448
  ## Deployment
449
449
 
450
450
  * Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
data/docs/deployment.md CHANGED
@@ -16,32 +16,34 @@ assume this is how you're using Puma.
16
16
  Initially, Puma was conceived as a thread-only web server, but support for
17
17
  processes was added in version 2.
18
18
 
19
+ In general, use single mode only if:
20
+
21
+ * You are using JRuby, TruffleRuby or another fully-multithreaded implementation of Ruby
22
+ * You are using MRI but in an environment where only 1 CPU core is available.
23
+
24
+ Otherwise, you'll want to use cluster mode to utilize all available CPU resources.
25
+
19
26
  To run `puma` in single mode (i.e., as a development environment), set the
20
27
  number of workers to 0; anything higher will run in cluster mode.
21
28
 
22
- Here are some tips for cluster mode:
29
+ ## Cluster Mode Tips
23
30
 
24
- ### MRI
31
+ For the purposes of Puma provisioning, "CPU cores" means:
25
32
 
26
- * Use cluster mode and set the number of workers to 1.5x the number of CPU cores
27
- in the machine, starting from a minimum of 2.
28
- * Set the number of threads to desired concurrent requests/number of workers.
29
- Puma defaults to 5, and that's a decent number.
33
+ 1. On ARM, the number of physical cores.
34
+ 2. On x86, the number of logical cores, hyperthreads, or vCPUs (these words all mean the same thing).
30
35
 
31
- #### Migrating from Unicorn
36
+ Set your config with the following process:
32
37
 
33
- * If you're migrating from unicorn though, here are some settings to start with:
34
- * Set workers to half the number of unicorn workers you're using
35
- * Set threads to 2
36
- * Enjoy 50% memory savings
37
- * As you grow more confident in the thread-safety of your app, you can tune the
38
- workers down and the threads up.
38
+ * Use cluster mode and set `workers :auto` (requires the `concurrent-ruby` gem) to match the number of CPU cores on the machine (minimum 2, otherwise use single mode!). If you can't add the gem, set the worker count manually to the available CPU cores.
39
+ * Set the number of threads to desired concurrent requests/number of workers.
40
+ Puma defaults to 5, and that's a decent number.
39
41
 
40
- #### Ubuntu / Systemd (Systemctl) Installation
42
+ For most deployments, adding `concurrent-ruby` and using `workers :auto` is the right starting point.
41
43
 
42
- See [systemd.md](systemd.md)
44
+ See [`workers :auto` gotchas](../lib/puma/dsl.rb).
43
45
 
44
- #### Worker utilization
46
+ ## Worker utilization
45
47
 
46
48
  **How do you know if you've got enough (or too many workers)?**
47
49
 
@@ -50,14 +52,34 @@ a time. But since so many apps are waiting on IO from DBs, etc., they can
50
52
  utilize threads to use the process more efficiently.
51
53
 
52
54
  Generally, you never want processes that are pegged all the time. That can mean
53
- there is more work to do than the process can get through. On the other hand, if
54
- you have processes that sit around doing nothing, then they're just eating up
55
- resources.
55
+ there is more work to do than the process can get through, and requests will end up with additional latency. On the other hand, if
56
+ you have processes that sit around doing nothing, then you're wasting resources and money.
57
+
58
+ In general, you are making a tradeoff between:
59
+
60
+ 1. CPU and memory utilization.
61
+ 2. Time spent queueing for a Puma worker to `accept` requests and additional latency caused by CPU contention.
62
+
63
+ If latency is important to you, you will have to accept lower utilization, and vice versa.
56
64
 
57
- Watch your CPU utilization over time and aim for about 70% on average. 70%
58
- utilization means you've got capacity still but aren't starving threads.
65
+ ## Container/VPS sizing
59
66
 
60
- **Measuring utilization**
67
+ You will have to make a decision about how "big" to make each pod/VPS/server/dyno.
68
+
69
+ **TL:DR;**: 80% of Puma apps will end up deploying "pods" of 4 workers, 5 threads each, 4 vCPU and 8GB of RAM.
70
+
71
+ For the rest of this discussion, we'll adopt the Kubernetes term of "pods".
72
+
73
+ Should you run 2 pods with 50 workers each? 25 pods, each with 4 workers? 100 pods, with each Puma running in single mode? Each scenario represents the same total amount of capacity (100 Puma processes that can respond to requests), but there are tradeoffs to make:
74
+
75
+ * **Increasing worker counts decreases latency, but means you scale in bigger "chunks"**. Worker counts should be somewhere between 4 and 32 in most cases. You want more than 4 in order to minimize time spent in request queueing for a free Puma worker, but probably less than ~32 because otherwise autoscaling is working in too large of an increment or they probably won't fit very well into your nodes. In any queueing system, queue time is proportional to 1/n, where n is the number of things pulling from the queue. Each pod will have its own request queue (i.e., the socket backlog). If you have 4 pods with 1 worker each (4 request queues), wait times are, proportionally, about 4 times higher than if you had 1 pod with 4 workers (1 request queue).
76
+ * **Increasing thread counts will increase throughput, but also latency and memory use** Unless you have a very I/O-heavy application (50%+ time spent waiting on IO), use the default thread count (5 for MRI). Using higher numbers of threads with low I/O wait (<50% of wall clock time) will lead to additional request latency and additional memory usage.
77
+ * **Increasing worker counts decreases memory per worker on average**. More processes per pod reduces memory usage per process, because of copy-on-write memory and because the cost of the single master process is "amortized" over more child processes.
78
+ * **Low worker counts (<4) have exceptionally poor throughput**. Don't run less than 4 processes per pod if you can. Low numbers of processes per pod will lead to high request queueing (see discussion above), which means you will have to run more pods and resources.
79
+ * **CPU-core-to-worker ratios should be around 1**. If running Puma with `threads > 1`, allocate 1 CPU core (see definition above!) per worker. If single threaded, allocate ~0.75 cpus per worker. Most web applications spend about 25% of their time in I/O - but when you're running multi-threaded, your Puma process will have higher CPU usage and should be able to fully saturate a CPU core. Using `workers :auto` will size workers to this guidance on most platforms.
80
+ * **Don't set memory limits unless necessary**. Most Puma processes will use about ~512MB-1GB per worker, and about 1GB for the master process. However, you probably shouldn't bother with setting memory limits lower than around 2GB per process, because most places you are deploying will have 2GB of RAM per CPU. A sensible memory limit for a Puma configuration of 4 child workers might be something like 8 GB (1 GB for the master, 7GB for the 4 children).
81
+
82
+ **Measuring utilization and queue time**
61
83
 
62
84
  Using a timestamp header from an upstream proxy server (e.g., `nginx` or
63
85
  `haproxy`) makes it possible to indicate how long requests have been waiting for
@@ -75,7 +97,7 @@ a Puma thread to become available.
75
97
  * `env['puma.request_body_wait']` contains the number of milliseconds Puma
76
98
  spent waiting for the client to send the request body.
77
99
  * haproxy: `%Th` (TLS handshake time) and `%Ti` (idle time before request)
78
- can can also be added as headers.
100
+ can also be added as headers.
79
101
 
80
102
  ## Should I daemonize?
81
103
 
@@ -100,3 +122,16 @@ or hell, even `monit`.
100
122
  You probably will want to deploy some new code at some point, and you'd like
101
123
  Puma to start running that new code. There are a few options for restarting
102
124
  Puma, described separately in our [restart documentation](restart.md).
125
+
126
+ ## Migrating from Unicorn
127
+
128
+ * If you're migrating from unicorn though, here are some settings to start with:
129
+ * Set workers to half the number of unicorn workers you're using
130
+ * Set threads to 2
131
+ * Enjoy 50% memory savings
132
+ * As you grow more confident in the thread-safety of your app, you can tune the
133
+ workers down and the threads up.
134
+
135
+ ## Ubuntu / Systemd (Systemctl) Installation
136
+
137
+ See [systemd.md](systemd.md)
data/docs/fork_worker.md CHANGED
@@ -24,13 +24,13 @@ The `fork_worker` option allows your application to be initialized only once for
24
24
 
25
25
  ### Usage Considerations
26
26
 
27
- - `fork_worker` introduces new `on_refork` and `after_refork` configuration hooks. Note the following:
28
- - When initially forking the parent process to the worker 0 child, `before_fork` will trigger on the parent process and `on_worker_boot` will trigger on the worker 0 child as normal.
29
- - When forking the worker 0 child to grandchild workers, `on_refork` and `after_refork` will trigger on the worker 0 child, and `on_worker_boot` will trigger on each grandchild worker.
27
+ - `fork_worker` introduces new `before_refork` and `after_refork` configuration hooks. Note the following:
28
+ - When initially forking the parent process to the worker 0 child, `before_fork` will trigger on the parent process and `before_worker_boot` will trigger on the worker 0 child as normal.
29
+ - When forking the worker 0 child to grandchild workers, `before_refork` and `after_refork` will trigger on the worker 0 child, and `before_worker_boot` will trigger on each grandchild worker.
30
30
  - For clarity, `before_fork` does not trigger on worker 0, and `after_refork` does not trigger on the grandchild.
31
31
  - As a general migration guide:
32
- - Copy any logic within your existing `before_fork` hook to the `on_refork` hook.
33
- - Consider to copy logic from your `on_worker_boot` hook to the `after_refork` hook, if it is needed to reset the state of worker 0 after it forks.
32
+ - Copy any logic within your existing `before_fork` hook to the `before_refork` hook.
33
+ - Consider to copy logic from your `before_worker_boot` hook to the `after_refork` hook, if it is needed to reset the state of worker 0 after it forks.
34
34
 
35
35
  ### Limitations
36
36
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Systemd
4
4
 
5
- See [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md).
5
+ See [/docs/systemd](https://github.com/puma/puma/blob/main/docs/systemd.md).
6
6
 
7
7
  ## rc.d
8
8