puma 6.6.0 → 7.1.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.
- checksums.yaml +4 -4
- data/History.md +170 -5
- data/README.md +24 -32
- data/docs/fork_worker.md +5 -5
- data/docs/kubernetes.md +8 -6
- data/docs/restart.md +2 -2
- data/docs/signals.md +11 -11
- data/docs/stats.md +3 -2
- data/docs/systemd.md +1 -1
- data/ext/puma_http11/extconf.rb +2 -17
- data/ext/puma_http11/mini_ssl.c +18 -8
- data/ext/puma_http11/org/jruby/puma/Http11.java +10 -2
- data/ext/puma_http11/puma_http11.c +23 -11
- data/lib/puma/binder.rb +10 -8
- data/lib/puma/cli.rb +3 -5
- data/lib/puma/client.rb +95 -61
- data/lib/puma/cluster/worker.rb +9 -10
- data/lib/puma/cluster/worker_handle.rb +38 -7
- data/lib/puma/cluster.rb +41 -26
- data/lib/puma/cluster_accept_loop_delay.rb +91 -0
- data/lib/puma/commonlogger.rb +3 -3
- data/lib/puma/configuration.rb +89 -43
- data/lib/puma/const.rb +9 -10
- data/lib/puma/control_cli.rb +6 -2
- data/lib/puma/detect.rb +2 -0
- data/lib/puma/dsl.rb +135 -94
- data/lib/puma/error_logger.rb +3 -1
- data/lib/puma/events.rb +25 -10
- data/lib/puma/io_buffer.rb +8 -4
- data/lib/puma/launcher/bundle_pruner.rb +1 -1
- data/lib/puma/launcher.rb +52 -48
- data/lib/puma/minissl.rb +0 -1
- data/lib/puma/plugin/systemd.rb +3 -3
- data/lib/puma/rack/urlmap.rb +1 -1
- data/lib/puma/reactor.rb +19 -4
- data/lib/puma/request.rb +45 -32
- data/lib/puma/runner.rb +8 -17
- data/lib/puma/server.rb +111 -61
- data/lib/puma/single.rb +5 -2
- data/lib/puma/state_file.rb +3 -2
- data/lib/puma/thread_pool.rb +47 -82
- data/lib/puma/util.rb +0 -7
- data/lib/puma.rb +10 -0
- data/lib/rack/handler/puma.rb +2 -2
- data/tools/Dockerfile +3 -1
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb282989c2e0ee20b007c5b0cdf231caf106816210101572346098f6863502c7
|
|
4
|
+
data.tar.gz: f4217f8221a64fcd6f5bf2c2249ed8dc6d512ba167e93ef4273b0accb574d26d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2070bae758f22fc8b0784c6b426a7177d65e9039fd2d1969d1241e8f101e46a04afdc5f93f5b6646eb0d9fb15fd6b47f87fb0cee478c3c58e840d3ae852b754a
|
|
7
|
+
data.tar.gz: 6d35fd83049a36ec8017fb859899fddd0305b90977a14f707f551b1e802d822100bf10126ce43598bf23bbf17deb581135955f61028ee56d0ba3e161718f9d79
|
data/History.md
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
+
## 7.1.0 / 2025-10-16
|
|
2
|
+
|
|
3
|
+
* Features
|
|
4
|
+
* Introduce `after_worker_shutdown` hook ([#3707])
|
|
5
|
+
* Reintroduce keepalive "fast inline" behavior. Provides faster (8x on JRuby & 1.4x on Ruby) pipeline processing ([#3794])
|
|
6
|
+
|
|
7
|
+
* Bugfixes
|
|
8
|
+
* Skip reading zero bytes when request body is buffered ([#3795])
|
|
9
|
+
* Fix `PUMA_LOG_CONFIG=1` logging twice with prune_bundler enabled ([#3778])
|
|
10
|
+
* Fix prune_bundler not showing in `PUMA_LOG_CONFIG=1` output ([#3779])
|
|
11
|
+
* Guard ThreadPool method call, which may be nil during shutdown ([#3791], [#3790])
|
|
12
|
+
* Set `Thread.current.puma_server` in Thread init code, not every request ([#3774])
|
|
13
|
+
* Fix race condition while deleting pidfile ([#3657])
|
|
14
|
+
|
|
15
|
+
## 7.0.4 / 2025-09-23
|
|
16
|
+
|
|
17
|
+
* Bugfixes
|
|
18
|
+
* Fix SSL_shutdown error handling ([#3703])
|
|
19
|
+
* Strip whitespace from the beginnings of request header values. ([#3742])
|
|
20
|
+
|
|
21
|
+
* Performance
|
|
22
|
+
* puma_http11.c: Use interned UTF-8 strings for hash keys ([#3754])
|
|
23
|
+
* Move sleep cluster logic to its own class ([#3746], [#3740])
|
|
24
|
+
|
|
25
|
+
## 7.0.3 / 2025-09-13
|
|
26
|
+
|
|
27
|
+
* Performance
|
|
28
|
+
* server.rb - process_client - add ka to todo if readable & complete ([#3748])
|
|
29
|
+
|
|
30
|
+
* Bugfixes
|
|
31
|
+
* Convert PUMA_PERSISTENT_TIMEOUT to an Integer ([#3749])
|
|
32
|
+
|
|
33
|
+
## 7.0.2 / 2025-09-08
|
|
34
|
+
|
|
35
|
+
* Bugfixes
|
|
36
|
+
* bug: control_cli.rb - Fixup `pumactl` code to load puma.rb for `deprecate_method_change` ([#3736], [#3734])
|
|
37
|
+
* Replace sleep spin lock with condition variable ([#3729])
|
|
38
|
+
* Fix Puma not booting if queue_requests disabled ([#3731])
|
|
39
|
+
|
|
40
|
+
## 7.0.1 / 2025-09-06
|
|
41
|
+
|
|
42
|
+
* Bugfixes
|
|
43
|
+
* Add backward compatibility aliases for Events class methods ([#3725])
|
|
44
|
+
|
|
45
|
+
## 7.0.0 / 2025-09-03
|
|
46
|
+
|
|
47
|
+
* Breaking changes
|
|
48
|
+
* Set default `max_keep_alive` to 999 ([#3719])
|
|
49
|
+
* Increase `persistent_timeout` default to 65 seconds ([#3378])
|
|
50
|
+
* Raise an ArgumentError if no block given to hooks ([#3377])
|
|
51
|
+
* Don't set env['HTTP_VERSION'] for Rack > 3.1 ([#3711], [#3576])
|
|
52
|
+
* Runner.rb - remove `ruby_engine` method, deprecated Nov-2024 ([#3701])
|
|
53
|
+
* Config `preload_app!` is now the default for clustered mode ([#3297])
|
|
54
|
+
* Config instance must be `clamp`-d before reading any values ([#3297])
|
|
55
|
+
* Response headers set to lowercase ([#3704])
|
|
56
|
+
* Update minimum Ruby version to 3.0 ([#3698])
|
|
57
|
+
* Rename callback hooks ([#3438])
|
|
58
|
+
|
|
59
|
+
| Old hook name| New hook name|
|
|
60
|
+
|----------|----------|
|
|
61
|
+
| on_worker_boot | before_worker_boot |
|
|
62
|
+
| on_worker_shutdown | before_worker_shutdown |
|
|
63
|
+
| on_restart | before_restart |
|
|
64
|
+
| on_booted | after_booted |
|
|
65
|
+
| on_stopped | after_stopped |
|
|
66
|
+
| on_refork | before_refork |
|
|
67
|
+
| on_thread_start | before_thread_start |
|
|
68
|
+
| on_thread_exit | before_thread_exit |
|
|
69
|
+
| on_worker_fork | before_worker_fork |
|
|
70
|
+
|
|
71
|
+
* Features
|
|
72
|
+
* Fix long tail response problem with keepalive connections ([#3678]) (Previously released in 7.0.0.pre1, this was a high effort change)
|
|
73
|
+
* Introduce support for fiber-per-request. ([#3101])
|
|
74
|
+
* Add support for `rack.response_finished` ([#3681])
|
|
75
|
+
* Feature/support custom logger with request logs ([#3140])
|
|
76
|
+
|
|
77
|
+
* Bugfixes
|
|
78
|
+
* Fix error_logger inproperly logging `env[QUERY_STRING]` ([#3713], [#3625])
|
|
79
|
+
* Fix handling of invalid Transfer-Encoding header errors ([#3702])
|
|
80
|
+
* Fix socket leak on monitor wakeup `NoMethodError` in `Reactor#select_loop` ([#3696], [#3695])
|
|
81
|
+
* CI: puma_socket.rb fixup socket/request writes ([#3684])
|
|
82
|
+
* Warn when RUBY_MN_THREADS env var is set ([#3721])
|
|
83
|
+
* Improve the DSL `preload_app!` doc ([#3712])
|
|
84
|
+
* Fix the ability to focus individual tests ([#3705])
|
|
85
|
+
* Set env['rack.hijack'] to client.method(:full_hijack) ([#3073])
|
|
86
|
+
|
|
87
|
+
* Performance
|
|
88
|
+
* server.rb - initialize ivars `@reactor` and `@env_set_http_version` ([#3714])
|
|
89
|
+
|
|
90
|
+
* Refactor
|
|
91
|
+
* Simplify `Puma::DSL#process_hook` logic ([#3710])
|
|
92
|
+
* Dry up deprecation warnings and fix deprecation warnings when running CI. ([#3709], [#3708])
|
|
93
|
+
* Ensure and enforce that configs are loaded before options are accessed ([#3616])
|
|
94
|
+
|
|
95
|
+
## 7.0.0.pre1 / 2025-07-31
|
|
96
|
+
|
|
97
|
+
* Changed
|
|
98
|
+
* Fix long tail response problem with keepalive connections ([#3678])
|
|
99
|
+
|
|
100
|
+
## 6.6.1 / 2025-07-30
|
|
101
|
+
|
|
102
|
+
* Bugfixes
|
|
103
|
+
* Accept `to_path` to be `nil` on request bodies ([#3635])
|
|
104
|
+
* Fix single runner stats before the server start ([#3572])
|
|
105
|
+
* Fix incomplete worker boot state on refork ([#3601])
|
|
106
|
+
* Improve HttpParserError messages for better debugging ([#3586])
|
|
107
|
+
* Fix refork logs to distinguish from phased restarts ([#3598])
|
|
108
|
+
* Fix `rack.after_reply` so it doesn't interrupt chain on error ([#3680])
|
|
109
|
+
|
|
1
110
|
## 6.6.0 / 2025-01-29
|
|
2
111
|
|
|
3
112
|
* Features
|
|
@@ -163,7 +272,7 @@
|
|
|
163
272
|
|
|
164
273
|
* Features
|
|
165
274
|
* Ability to supply a custom logger ([#2770], [#2511])
|
|
166
|
-
* Warn when
|
|
275
|
+
* Warn when cluster mode-only hooks are defined in single mode ([#3089])
|
|
167
276
|
* Adds the on_booted event ([#2709])
|
|
168
277
|
|
|
169
278
|
* Bugfixes
|
|
@@ -758,7 +867,7 @@ Each patchlevel release contains a separate security fix. We recommend simply up
|
|
|
758
867
|
* Fix Java 8 support ([#1773])
|
|
759
868
|
* Fix error `uninitialized constant Puma::Cluster` ([#1731])
|
|
760
869
|
* Fix `not_token` being able to be set to true ([#1803])
|
|
761
|
-
* Fix "Hang on SIGTERM with ruby 2.6 in
|
|
870
|
+
* Fix "Hang on SIGTERM with ruby 2.6 in cluster mode" (PR [#1741], [#1674], [#1720], [#1730], [#1755])
|
|
762
871
|
|
|
763
872
|
## 3.12.1 / 2019-03-19
|
|
764
873
|
|
|
@@ -1169,7 +1278,7 @@ Each patchlevel release contains a separate security fix. We recommend simply up
|
|
|
1169
1278
|
* 4 minor features:
|
|
1170
1279
|
|
|
1171
1280
|
* Listen to unix socket with provided backlog if any
|
|
1172
|
-
* Improves the
|
|
1281
|
+
* Improves the cluster mode stats to report worker stats
|
|
1173
1282
|
* Pass the env to the lowlevel_error handler. Fixes [#854]
|
|
1174
1283
|
* Treat path-like hosts as unix sockets. Fixes [#824]
|
|
1175
1284
|
|
|
@@ -1896,7 +2005,7 @@ The "clearly I don't have enough tests for the config" release.
|
|
|
1896
2005
|
|
|
1897
2006
|
* 3 doc changes:
|
|
1898
2007
|
* Add note about on_worker_boot hook
|
|
1899
|
-
* Add some documentation for
|
|
2008
|
+
* Add some documentation for Cluster mode
|
|
1900
2009
|
* Added quotes to /etc/puma.conf
|
|
1901
2010
|
|
|
1902
2011
|
## 2.0.1 / 2013-04-30
|
|
@@ -2150,6 +2259,62 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
|
2150
2259
|
* Bugfixes
|
|
2151
2260
|
* Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
|
|
2152
2261
|
|
|
2262
|
+
[#3707]:https://github.com/puma/puma/pull/3707 "PR by @nerdrew, merged 2025-10-02"
|
|
2263
|
+
[#3794]:https://github.com/puma/puma/pull/3794 "PR by @schneems, merged 2025-10-16"
|
|
2264
|
+
[#3795]:https://github.com/puma/puma/pull/3795 "PR by @MSP-Greg, merged 2025-10-16"
|
|
2265
|
+
[#3778]:https://github.com/puma/puma/pull/3778 "PR by @joshuay03, merged 2025-10-16"
|
|
2266
|
+
[#3779]:https://github.com/puma/puma/pull/3779 "PR by @joshuay03, merged 2025-10-16"
|
|
2267
|
+
[#3791]:https://github.com/puma/puma/pull/3791 "PR by @MSP-Greg, merged 2025-10-09"
|
|
2268
|
+
[#3790]:https://github.com/puma/puma/issues/3790 "Issue by @eric-wtfoxtrot, closed 2025-10-09"
|
|
2269
|
+
[#3774]:https://github.com/puma/puma/pull/3774 "PR by @MSP-Greg, merged 2025-10-16"
|
|
2270
|
+
[#3657]:https://github.com/puma/puma/pull/3657 "PR by @marksmith, merged 2025-10-16"
|
|
2271
|
+
[#3703]:https://github.com/puma/puma/pull/3703 "PR by @marshall-lee, merged 2025-09-20"
|
|
2272
|
+
[#3742]:https://github.com/puma/puma/pull/3742 "PR by @kenballus, merged 2025-09-18"
|
|
2273
|
+
[#3754]:https://github.com/puma/puma/pull/3754 "PR by @byroot, merged 2025-09-18"
|
|
2274
|
+
[#3746]:https://github.com/puma/puma/pull/3746 "PR by @schneems, merged 2025-09-18"
|
|
2275
|
+
[#3740]:https://github.com/puma/puma/issues/3740 "Issue by @joshuay03, closed 2025-09-18"
|
|
2276
|
+
[#3748]:https://github.com/puma/puma/pull/3748 "PR by @MSP-Greg, merged 2025-09-14"
|
|
2277
|
+
[#3749]:https://github.com/puma/puma/pull/3749 "PR by @schneems, merged 2025-09-14"
|
|
2278
|
+
[#3736]:https://github.com/puma/puma/pull/3736 "PR by @MSP-Greg, merged 2025-09-08"
|
|
2279
|
+
[#3734]:https://github.com/puma/puma/issues/3734 "Issue by @espen, closed 2025-09-08"
|
|
2280
|
+
[#3729]:https://github.com/puma/puma/pull/3729 "PR by @bensheldon, merged 2025-09-08"
|
|
2281
|
+
[#3731]:https://github.com/puma/puma/pull/3731 "PR by @stanhu, merged 2025-09-06"
|
|
2282
|
+
[#3725]:https://github.com/puma/puma/pull/3725 "PR by @tannakartikey, merged 2025-09-05"
|
|
2283
|
+
[#3719]:https://github.com/puma/puma/pull/3719 "PR by @schneems, merged 2025-09-03"
|
|
2284
|
+
[#3378]:https://github.com/puma/puma/pull/3378 "PR by @shayonj, merged 2025-08-19"
|
|
2285
|
+
[#3377]:https://github.com/puma/puma/pull/3377 "PR by @joshuay03, merged 2025-08-12"
|
|
2286
|
+
[#3711]:https://github.com/puma/puma/pull/3711 "PR by @MSP-Greg, merged 2025-08-28"
|
|
2287
|
+
[#3576]:https://github.com/puma/puma/issues/3576 "Issue by @pdalberti, closed 2025-08-28"
|
|
2288
|
+
[#3701]:https://github.com/puma/puma/pull/3701 "PR by @MSP-Greg, merged 2025-08-26"
|
|
2289
|
+
[#3297]:https://github.com/puma/puma/pull/3297 "PR by @joshuay03, merged 2025-08-26"
|
|
2290
|
+
[#3704]:https://github.com/puma/puma/pull/3704 "PR by @schneems, merged 2025-08-25"
|
|
2291
|
+
[#3698]:https://github.com/puma/puma/pull/3698 "PR by @schneems, merged 2025-08-21"
|
|
2292
|
+
[#3438]:https://github.com/puma/puma/pull/3438 "PR by @tannakartikey, merged 2025-08-25"
|
|
2293
|
+
[#3678]:https://github.com/puma/puma/pull/3678 "PR by @MSP-Greg, merged 2025-07-31"
|
|
2294
|
+
[#3101]:https://github.com/puma/puma/pull/3101 "PR by @ioquatix, merged 2025-08-25"
|
|
2295
|
+
[#3681]:https://github.com/puma/puma/pull/3681 "PR by @byroot, merged 2025-08-15"
|
|
2296
|
+
[#3140]:https://github.com/puma/puma/pull/3140 "PR by @phyzical, merged 2025-08-12"
|
|
2297
|
+
[#3713]:https://github.com/puma/puma/pull/3713 "PR by @MSP-Greg, merged 2025-08-29"
|
|
2298
|
+
[#3625]:https://github.com/puma/puma/pull/3625 "PR by @bhooshiek-narendiran, closed 2025-08-29"
|
|
2299
|
+
[#3702]:https://github.com/puma/puma/pull/3702 "PR by @marshall-lee, merged 2025-08-25"
|
|
2300
|
+
[#3696]:https://github.com/puma/puma/pull/3696 "PR by @joshuay03, merged 2025-08-22"
|
|
2301
|
+
[#3695]:https://github.com/puma/puma/issues/3695 "Issue by @joshuay03, closed 2025-08-22"
|
|
2302
|
+
[#3684]:https://github.com/puma/puma/pull/3684 "PR by @MSP-Greg, merged 2025-08-02"
|
|
2303
|
+
[#3721]:https://github.com/puma/puma/pull/3721 "PR by @schneems, merged 2025-09-03"
|
|
2304
|
+
[#3712]:https://github.com/puma/puma/pull/3712 "PR by @joshuay03, merged 2025-08-28"
|
|
2305
|
+
[#3705]:https://github.com/puma/puma/pull/3705 "PR by @schneems, merged 2025-08-25"
|
|
2306
|
+
[#3073]:https://github.com/puma/puma/pull/3073 "PR by @MSP-Greg, merged 2025-08-12"
|
|
2307
|
+
[#3714]:https://github.com/puma/puma/pull/3714 "PR by @MSP-Greg, merged 2025-08-29"
|
|
2308
|
+
[#3710]:https://github.com/puma/puma/pull/3710 "PR by @joshuay03, merged 2025-08-28"
|
|
2309
|
+
[#3709]:https://github.com/puma/puma/pull/3709 "PR by @MSP-Greg, merged 2025-08-28"
|
|
2310
|
+
[#3708]:https://github.com/puma/puma/issues/3708 "Issue by @schneems, closed 2025-08-28"
|
|
2311
|
+
[#3616]:https://github.com/puma/puma/pull/3616 "PR by @joshuay03, merged 2025-08-25"
|
|
2312
|
+
[#3635]:https://github.com/puma/puma/pull/3635 "PR by @LevitatingBusinessMan, merged 2025-05-08"
|
|
2313
|
+
[#3572]:https://github.com/puma/puma/pull/3572 "PR by @barthez, merged 2025-02-06"
|
|
2314
|
+
[#3601]:https://github.com/puma/puma/pull/3601 "PR by @joshuay03, merged 2025-01-31"
|
|
2315
|
+
[#3586]:https://github.com/puma/puma/pull/3586 "PR by @MSP-Greg, merged 2025-02-03"
|
|
2316
|
+
[#3598]:https://github.com/puma/puma/pull/3598 "PR by @joshuay03, merged 2025-01-31"
|
|
2317
|
+
[#3680]:https://github.com/puma/puma/pull/3680 "PR by @byroot, merged 2025-07-31"
|
|
2153
2318
|
[#3570]:https://github.com/puma/puma/pull/3570 "PR by @mohamedhafez, merged 2024-12-30"
|
|
2154
2319
|
[#3567]:https://github.com/puma/puma/issues/3567 "Issue by @mohamedhafez, closed 2024-12-30"
|
|
2155
2320
|
[#3383]:https://github.com/puma/puma/pull/3383 "PR by @joshuay03, merged 2024-11-29"
|
|
@@ -2748,7 +2913,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
|
2748
2913
|
[#1022]:https://github.com/puma/puma/issues/1022 "Issue by @AKovtunov, closed 2017-08-16"
|
|
2749
2914
|
[#958]:https://github.com/puma/puma/issues/958 "Issue by @lalitlogical, closed 2016-04-23"
|
|
2750
2915
|
[#782]:https://github.com/puma/puma/issues/782 "Issue by @Tonkpils, closed 2016-07-19"
|
|
2751
|
-
[#1010]:https://github.com/puma/puma/issues/1010 "Issue by @
|
|
2916
|
+
[#1010]:https://github.com/puma/puma/issues/1010 "Issue by @mirineumark, closed 2016-07-19"
|
|
2752
2917
|
[#959]:https://github.com/puma/puma/issues/959 "Issue by @mwpastore, closed 2016-04-22"
|
|
2753
2918
|
[#840]:https://github.com/puma/puma/issues/840 "Issue by @marisawallace, closed 2016-04-07"
|
|
2754
2919
|
[#1007]:https://github.com/puma/puma/pull/1007 "PR by @willnet, merged 2016-06-24"
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# Puma: A Ruby Web Server Built For Parallelism
|
|
6
6
|
|
|
7
|
-
[](https://github.com/puma/puma/actions/workflows/tests.yml?query=branch%3Amaster)
|
|
8
8
|
[](https://codeclimate.com/github/puma/puma)
|
|
9
9
|
[]( https://stackoverflow.com/questions/tagged/puma )
|
|
10
10
|
|
|
@@ -102,9 +102,9 @@ Puma will automatically scale the number of threads, from the minimum until it c
|
|
|
102
102
|
|
|
103
103
|
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.
|
|
104
104
|
|
|
105
|
-
###
|
|
105
|
+
### Cluster mode
|
|
106
106
|
|
|
107
|
-
Puma also offers "
|
|
107
|
+
Puma also offers "cluster mode". Cluster 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:
|
|
108
108
|
|
|
109
109
|
```
|
|
110
110
|
$ puma -t 8:32 -w 3
|
|
@@ -116,15 +116,15 @@ Or with the `WEB_CONCURRENCY` environment variable:
|
|
|
116
116
|
$ WEB_CONCURRENCY=3 puma -t 8:32
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
Note that threads are still used in
|
|
119
|
+
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
120
|
|
|
121
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).
|
|
122
122
|
|
|
123
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).
|
|
124
124
|
|
|
125
|
-
In
|
|
125
|
+
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
126
|
|
|
127
|
-
If the
|
|
127
|
+
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
128
|
|
|
129
129
|
```
|
|
130
130
|
$ puma -w 3 --preload
|
|
@@ -140,10 +140,10 @@ preload_app!
|
|
|
140
140
|
|
|
141
141
|
Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preloading copies the code of master into the workers.
|
|
142
142
|
|
|
143
|
-
####
|
|
143
|
+
#### Cluster mode hooks
|
|
144
144
|
|
|
145
|
-
When using clustered mode, Puma's configuration DSL provides `before_fork` and `
|
|
146
|
-
hooks to run code when the master process forks
|
|
145
|
+
When using clustered mode, Puma's configuration DSL provides `before_fork`, `before_worker_boot`, and `after_worker_shutdown`
|
|
146
|
+
hooks to run code when the master process forks, the child workers are booted, and after each child worker exits respectively.
|
|
147
147
|
|
|
148
148
|
It is recommended to use these hooks with `preload_app!`, otherwise constants loaded by your
|
|
149
149
|
application (such as `Rails`) will not be available inside the hooks.
|
|
@@ -154,16 +154,21 @@ before_fork do
|
|
|
154
154
|
# Add code to run inside the Puma master process before it forks a worker child.
|
|
155
155
|
end
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
before_worker_boot do
|
|
158
158
|
# Add code to run inside the Puma worker process after forking.
|
|
159
159
|
end
|
|
160
|
+
|
|
161
|
+
after_worker_shutdown do |worker_handle|
|
|
162
|
+
# Add code to run inside the Puma master process after a worker exits. `worker.process_status` can be used to get the
|
|
163
|
+
# `Process::Status` of the exited worker.
|
|
164
|
+
end
|
|
160
165
|
```
|
|
161
166
|
|
|
162
|
-
In addition, there is an `
|
|
167
|
+
In addition, there is an `before_refork` and `after_refork` hooks which are used only in [`fork_worker` mode](docs/fork_worker.md),
|
|
163
168
|
when the worker 0 child process forks a grandchild worker:
|
|
164
169
|
|
|
165
170
|
```ruby
|
|
166
|
-
|
|
171
|
+
before_refork do
|
|
167
172
|
# Used only when fork_worker mode is enabled. Add code to run inside the Puma worker 0
|
|
168
173
|
# child process before it forks a grandchild worker.
|
|
169
174
|
end
|
|
@@ -176,7 +181,7 @@ after_refork do
|
|
|
176
181
|
end
|
|
177
182
|
```
|
|
178
183
|
|
|
179
|
-
Importantly, note the following considerations when Ruby forks a child process:
|
|
184
|
+
Importantly, note the following considerations when Ruby forks a child process:
|
|
180
185
|
|
|
181
186
|
1. File descriptors such as network sockets **are** copied from the parent to the forked
|
|
182
187
|
child process. Dual-use of the same sockets by parent and child will result in I/O conflicts
|
|
@@ -190,29 +195,29 @@ Therefore, we recommend the following:
|
|
|
190
195
|
|
|
191
196
|
1. If possible, do not establish any socket connections (HTTP, database connections, etc.)
|
|
192
197
|
inside Puma's master process when booting.
|
|
193
|
-
2. If (1) is not possible, use `before_fork` and `
|
|
198
|
+
2. If (1) is not possible, use `before_fork` and `before_refork` to disconnect the parent's socket
|
|
194
199
|
connections when forking, so that they are not accidentally copied to the child process.
|
|
195
|
-
3. Use `
|
|
200
|
+
3. Use `before_worker_boot` to restart any background threads on the forked child.
|
|
196
201
|
4. Use `after_refork` to restart any background threads on the parent.
|
|
197
202
|
|
|
198
203
|
#### Master process lifecycle hooks
|
|
199
204
|
|
|
200
|
-
Puma's configuration DSL provides master process lifecycle hooks `
|
|
205
|
+
Puma's configuration DSL provides master process lifecycle hooks `after_booted`, `before_restart`, and `after_stopped`
|
|
201
206
|
which may be used to specify code blocks to run on each event:
|
|
202
207
|
|
|
203
208
|
```ruby
|
|
204
209
|
# config/puma.rb
|
|
205
|
-
|
|
210
|
+
after_booted do
|
|
206
211
|
# Add code to run in the Puma master process after it boots,
|
|
207
212
|
# and also after a phased restart completes.
|
|
208
213
|
end
|
|
209
214
|
|
|
210
|
-
|
|
215
|
+
before_restart do
|
|
211
216
|
# Add code to run in the Puma master process when it receives
|
|
212
217
|
# a restart command but before it restarts.
|
|
213
218
|
end
|
|
214
219
|
|
|
215
|
-
|
|
220
|
+
after_stopped do
|
|
216
221
|
# Add code to run in the Puma master process when it receives
|
|
217
222
|
# a stop command but before it shuts down.
|
|
218
223
|
end
|
|
@@ -432,19 +437,6 @@ Some platforms do not support all Puma features.
|
|
|
432
437
|
* **Windows**: Cluster mode is not supported due to a lack of fork(2).
|
|
433
438
|
* **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
439
|
|
|
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
440
|
## Deployment
|
|
449
441
|
|
|
450
442
|
* Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
|
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 `
|
|
28
|
-
- When initially forking the parent process to the worker 0 child, `before_fork` will trigger on the parent process and `
|
|
29
|
-
- When forking the worker 0 child to grandchild workers, `
|
|
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 `
|
|
33
|
-
- Consider to copy logic from your `
|
|
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
|
|
data/docs/kubernetes.md
CHANGED
|
@@ -8,10 +8,11 @@ In general running Puma in Kubernetes works as-is, no special configuration is n
|
|
|
8
8
|
|
|
9
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
10
|
|
|
11
|
-
A basic Dockerfile example:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
A basic Dockerfile example:
|
|
12
|
+
|
|
13
|
+
```Dockerfile
|
|
14
|
+
FROM ruby:3.4.5-alpine # can be updated to newer ruby versions
|
|
15
|
+
RUN apk update && apk add build-base # and any other packages you need
|
|
15
16
|
|
|
16
17
|
# Only rebuild gem bundle if Gemfile changes
|
|
17
18
|
COPY Gemfile Gemfile.lock ./
|
|
@@ -26,7 +27,8 @@ CMD bundle exec rackup -o 0.0.0.0
|
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
A sample `deployment.yaml`:
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
30
32
|
---
|
|
31
33
|
apiVersion: apps/v1
|
|
32
34
|
kind: Deployment
|
|
@@ -47,7 +49,7 @@ spec:
|
|
|
47
49
|
image: <your image here>
|
|
48
50
|
ports:
|
|
49
51
|
- containerPort: 9292
|
|
50
|
-
```
|
|
52
|
+
```
|
|
51
53
|
|
|
52
54
|
## Graceful shutdown and pod termination
|
|
53
55
|
|
data/docs/restart.md
CHANGED
|
@@ -29,7 +29,7 @@ Any of the following will cause a Puma server to perform a hot restart:
|
|
|
29
29
|
|
|
30
30
|
* The newly started Puma process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
|
|
31
31
|
* Only one version of the application is running at a time.
|
|
32
|
-
* `
|
|
32
|
+
* `before_restart` is invoked just before the server shuts down. This can be used to clean up resources (like long-lived database connections) gracefully. Since Ruby 2.0, it is not typically necessary to explicitly close file descriptors on restart. This is because any file descriptor opened by Ruby will have the `FD_CLOEXEC` flag set, meaning that file descriptors are closed on `exec`. `before_restart` is useful, though, if your application needs to perform any more graceful protocol-specific shutdown procedures before closing connections.
|
|
33
33
|
|
|
34
34
|
## Phased restart
|
|
35
35
|
|
|
@@ -59,7 +59,7 @@ Any of the following will cause a Puma server to perform a phased restart:
|
|
|
59
59
|
|
|
60
60
|
* When a phased restart begins, the Puma master process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
|
|
61
61
|
* On a single server, it's possible that two versions of the application are running concurrently during a phased restart.
|
|
62
|
-
* `
|
|
62
|
+
* `before_restart` is not invoked
|
|
63
63
|
* Phased restarts can be slow for Puma clusters with many workers. Hot restarts often complete more quickly, but at the cost of increased latency during the restart.
|
|
64
64
|
* Phased restarts cannot be used to upgrade any gems loaded by the Puma master process, including `puma` itself, anything in `extra_runtime_dependencies`, or dependencies thereof. Upgrading other gems is safe.
|
|
65
65
|
* If you remove the gems from old releases as part of your deployment strategy, there are additional considerations. Do not put any gems into `extra_runtime_dependencies` that have native extensions or have dependencies that have native extensions (one common example is `puma_worker_killer` and its dependency on `ffi`). Workers will fail on boot during a phased restart. The underlying issue is recorded in [an issue on the rubygems project](https://github.com/rubygems/rubygems/issues/4004). Hot restarts are your only option here if you need these dependencies.
|
data/docs/signals.md
CHANGED
|
@@ -17,13 +17,13 @@ $ ps aux | grep tail
|
|
|
17
17
|
schneems 87152 0.0 0.0 2432772 492 s032 S+ 12:46PM 0:00.00 tail -f my.log
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
You can send a signal in Ruby using the [Process module](https://ruby-
|
|
20
|
+
You can send a signal in Ruby using the [Process module](https://docs.ruby-lang.org/en/master/Process.html#method-c-kill):
|
|
21
21
|
|
|
22
22
|
```
|
|
23
23
|
$ irb
|
|
24
24
|
> puts pid
|
|
25
25
|
=> 87152
|
|
26
|
-
Process.detach(pid) # https://ruby-
|
|
26
|
+
Process.detach(pid) # https://docs.ruby-lang.org/en/master/Process.html#method-c-detach
|
|
27
27
|
Process.kill("TERM", pid)
|
|
28
28
|
```
|
|
29
29
|
|
|
@@ -54,12 +54,12 @@ puma configuration file reloaded, if there is one
|
|
|
54
54
|
puma configuration file reloaded, if there is one
|
|
55
55
|
|
|
56
56
|
before_fork
|
|
57
|
-
|
|
57
|
+
before_worker_fork
|
|
58
58
|
after_worker_fork
|
|
59
59
|
|
|
60
60
|
Gemfile in context
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
before_worker_boot
|
|
63
63
|
|
|
64
64
|
Code of the app is loaded and running
|
|
65
65
|
```
|
|
@@ -67,18 +67,18 @@ Code of the app is loaded and running
|
|
|
67
67
|
### Send USR2
|
|
68
68
|
|
|
69
69
|
```
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
before_worker_shutdown
|
|
71
|
+
before_restart
|
|
72
72
|
|
|
73
73
|
puma configuration file reloaded, if there is one
|
|
74
74
|
|
|
75
75
|
before_fork
|
|
76
|
-
|
|
76
|
+
before_worker_fork
|
|
77
77
|
after_worker_fork
|
|
78
78
|
|
|
79
79
|
Gemfile in context
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
before_worker_boot
|
|
82
82
|
|
|
83
83
|
Code of the app is loaded and running
|
|
84
84
|
```
|
|
@@ -86,13 +86,13 @@ Code of the app is loaded and running
|
|
|
86
86
|
### Send USR1
|
|
87
87
|
|
|
88
88
|
```
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
before_worker_shutdown
|
|
90
|
+
before_worker_fork
|
|
91
91
|
after_worker_fork
|
|
92
92
|
|
|
93
93
|
Gemfile in context
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
before_worker_boot
|
|
96
96
|
|
|
97
97
|
Code of the app is loaded and running
|
|
98
98
|
```
|
data/docs/stats.md
CHANGED
|
@@ -62,10 +62,11 @@ When Puma runs in single mode, these stats are available at the top level. When
|
|
|
62
62
|
this is a "wholistic" stat reflecting the overall current state of work to be done and the capacity to do it.
|
|
63
63
|
* pool_capacity: `how many threads are waiting to receive work` + `max_threads` - `running`. In a typical configuration where `min_threads`
|
|
64
64
|
and `max_threads` are configured to the same number, this is simply `how many threads are waiting to receive work`. This number exists only as a stat
|
|
65
|
-
and is not used for any internal decisions, unlike `
|
|
65
|
+
and is not used for any internal decisions, unlike `busy_threads`, which is usually a more useful stat.
|
|
66
66
|
* max_threads: the maximum number of threads Puma is configured to spool per worker
|
|
67
67
|
* requests_count: the number of requests this worker has served since starting
|
|
68
|
-
|
|
68
|
+
* reactor_max: the maximum observed number of requests held in Puma's "reactor" which is used for asyncronously buffering request bodies. This stat is reset on every call, so it's the maximum value observed since the last stat call.
|
|
69
|
+
* backlog_max: the maximum number of requests that have been fully buffered by the reactor and placed in a ready queue, but have not yet been picked up by a server thread. This stat is reset on every call, so it's the maximum value observed since the last stat call.
|
|
69
70
|
|
|
70
71
|
### cluster mode
|
|
71
72
|
|
data/docs/systemd.md
CHANGED
|
@@ -72,7 +72,7 @@ systemd and Puma also support socket activation, where systemd opens the
|
|
|
72
72
|
listening socket(s) in advance and provides them to the Puma master process on
|
|
73
73
|
startup. Among other advantages, this keeps listening sockets open across puma
|
|
74
74
|
restarts and achieves graceful restarts, including when upgraded Puma, and is
|
|
75
|
-
compatible with both
|
|
75
|
+
compatible with both cluster mode and application preload.
|
|
76
76
|
|
|
77
77
|
**Note:** Any wrapper scripts which `exec`, or other indirections in `ExecStart`
|
|
78
78
|
may result in activated socket file descriptors being closed before reaching the
|
data/ext/puma_http11/extconf.rb
CHANGED
|
@@ -52,29 +52,14 @@ unless ENV["PUMA_DISABLE_SSL"]
|
|
|
52
52
|
have_func "SSL_get1_peer_certificate" , ssl_h
|
|
53
53
|
|
|
54
54
|
puts ''
|
|
55
|
-
|
|
56
|
-
# Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
|
|
57
|
-
if Random.respond_to?(:bytes)
|
|
58
|
-
$defs.push "-DHAVE_RANDOM_BYTES"
|
|
59
|
-
puts "checking for Random.bytes... yes"
|
|
60
|
-
else
|
|
61
|
-
puts "checking for Random.bytes... no"
|
|
62
|
-
end
|
|
63
55
|
end
|
|
64
56
|
end
|
|
65
57
|
|
|
66
58
|
if ENV["PUMA_MAKE_WARNINGS_INTO_ERRORS"]
|
|
67
59
|
# Make all warnings into errors
|
|
68
60
|
# Except `implicit-fallthrough` since most failures comes from ragel state machine generated code
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
append_cflags '-Wno-implicit-fallthrough'
|
|
72
|
-
else
|
|
73
|
-
# flag may not exist on some platforms, -Werror may not be defined on some platforms, but
|
|
74
|
-
# works with all in current CI
|
|
75
|
-
$CFLAGS << " #{config_string('WERRORFLAG') || '-Werror'}"
|
|
76
|
-
$CFLAGS << ' -Wno-implicit-fallthrough'
|
|
77
|
-
end
|
|
61
|
+
append_cflags(config_string('WERRORFLAG') || '-Werror')
|
|
62
|
+
append_cflags '-Wno-implicit-fallthrough'
|
|
78
63
|
end
|
|
79
64
|
|
|
80
65
|
create_makefile("puma/puma_http11")
|
data/ext/puma_http11/mini_ssl.c
CHANGED
|
@@ -471,13 +471,8 @@ sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
|
|
|
471
471
|
SSL_CTX_set_verify(ctx, NUM2INT(verify_mode), engine_verify_callback);
|
|
472
472
|
}
|
|
473
473
|
|
|
474
|
-
// Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
|
|
475
474
|
session_id_bytes = rb_funcall(
|
|
476
|
-
#ifdef HAVE_RANDOM_BYTES
|
|
477
475
|
rb_cRandom,
|
|
478
|
-
#else
|
|
479
|
-
rb_const_get(rb_cRandom, rb_intern_const("DEFAULT")),
|
|
480
|
-
#endif
|
|
481
476
|
rb_intern_const("bytes"),
|
|
482
477
|
1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH));
|
|
483
478
|
|
|
@@ -665,14 +660,29 @@ VALUE engine_shutdown(VALUE self) {
|
|
|
665
660
|
|
|
666
661
|
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
|
|
667
662
|
|
|
663
|
+
if (SSL_in_init(conn->ssl)) {
|
|
664
|
+
// Avoid "shutdown while in init" error
|
|
665
|
+
// See https://github.com/openssl/openssl/blob/openssl-3.5.2/ssl/ssl_lib.c#L2827-L2828
|
|
666
|
+
return Qtrue;
|
|
667
|
+
}
|
|
668
|
+
|
|
668
669
|
ERR_clear_error();
|
|
669
670
|
|
|
670
671
|
ok = SSL_shutdown(conn->ssl);
|
|
671
|
-
|
|
672
|
-
|
|
672
|
+
// See https://github.com/openssl/openssl/blob/openssl-3.5.2/ssl/ssl_lib.c#L2792-L2797
|
|
673
|
+
// for description of SSL_shutdown return values.
|
|
674
|
+
switch (ok) {
|
|
675
|
+
case 0:
|
|
676
|
+
// "close notify" alert is sent by us.
|
|
677
|
+
return Qfalse;
|
|
678
|
+
case 1:
|
|
679
|
+
// "close notify" alert was received from peer.
|
|
680
|
+
return Qtrue;
|
|
681
|
+
default:
|
|
682
|
+
raise_error(conn->ssl, ok);
|
|
673
683
|
}
|
|
674
684
|
|
|
675
|
-
return
|
|
685
|
+
return Qnil;
|
|
676
686
|
}
|
|
677
687
|
|
|
678
688
|
VALUE engine_init(VALUE self) {
|