puma 8.1.3-java → 8.2.0.pre1-java
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 +120 -0
- data/README.md +4 -3
- data/docs/GLOSSARY.md +160 -0
- data/docs/architecture.md +41 -42
- data/docs/binding.md +3 -0
- data/docs/cluster_mode.md +21 -21
- data/docs/control_server.md +4 -4
- data/docs/deployment/nginx.md +2 -0
- data/docs/deployment/systemd.md +15 -0
- data/docs/puma_support.md +12 -0
- data/docs/restart.md +2 -2
- data/docs/signals.md +3 -3
- data/docs/ssl.md +65 -0
- data/docs/upgrading/5.0-Upgrade.md +1 -1
- data/docs/upgrading/6.0-Upgrade.md +1 -1
- data/docs/upgrading/7.0-Upgrade.md +1 -1
- data/docs/upgrading/8.0-Upgrade.md +1 -1
- data/lib/puma/app/status.rb +22 -7
- data/lib/puma/binder.rb +0 -1
- data/lib/puma/cli.rb +1 -3
- data/lib/puma/client.rb +133 -57
- data/lib/puma/client_env.rb +9 -11
- data/lib/puma/cluster/worker.rb +0 -6
- data/lib/puma/cluster.rb +3 -14
- data/lib/puma/cluster_accept_loop_delay.rb +18 -7
- data/lib/puma/commonlogger.rb +3 -4
- data/lib/puma/configuration.rb +4 -1
- data/lib/puma/const.rb +5 -5
- data/lib/puma/control_cli.rb +5 -7
- data/lib/puma/detect.rb +1 -1
- data/lib/puma/dsl.rb +70 -14
- data/lib/puma/http_parser_error.rb +8 -0
- data/lib/puma/launcher/bundle_pruner.rb +3 -21
- data/lib/puma/launcher.rb +55 -25
- data/lib/puma/minissl/context_builder.rb +3 -2
- data/lib/puma/minissl.rb +12 -16
- data/lib/puma/plugin/systemd.rb +69 -3
- data/lib/puma/puma_http11.jar +0 -0
- data/lib/puma/rack/urlmap.rb +2 -2
- data/lib/puma/reactor.rb +138 -25
- data/lib/puma/response.rb +65 -38
- data/lib/puma/runner.rb +4 -1
- data/lib/puma/sd_notify.rb +21 -0
- data/lib/puma/server.rb +14 -14
- data/lib/puma/server_plugin_control.rb +2 -1
- data/lib/puma/single.rb +0 -1
- data/lib/puma/thread_pool.rb +87 -14
- data/lib/puma/util.rb +5 -16
- data/lib/puma.rb +22 -5
- data/lib/rack/handler/puma.rb +1 -5
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4380f86e36d31e95b3ad024923af1afb05d00398589f289e65790a747d70662
|
|
4
|
+
data.tar.gz: d90cb46bbd12e24b3ea355b6475f78e27a0560530a90d5b9d27aee811679a4b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41cf12824259980dc71b9e64dc26943ac611c8dd7ca0bdb32e62694ac24fc5143334f5e8ea2e97577dc007b1be7f20710b0a73c302cb6598db9c5cd2a38ec213
|
|
7
|
+
data.tar.gz: a99b047d20bb27fe493e8b0028fd3c2cf6c97ee051bede4efd70eabff4d48da990e5c0c38a81d66b9810e4cc22c8965e3715a7864af54429b4ea685e1393dafd
|
data/History.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
## 8.2.0.pre1 / 2026-12-01
|
|
2
|
+
|
|
3
|
+
* Features
|
|
4
|
+
* Add `nil_rack_input_on_empty_body` option to leave `rack.input` unset for requests with no body under Rack 3.1+ ([#4301])
|
|
5
|
+
* Add `data_token` option to the control server for read-only access to stats; set it to `"none"` to allow stats without a token ([#4260], [#4283])
|
|
6
|
+
* Add `http_parser` option to replace Puma's HTTP parser with another class ([#4026])
|
|
7
|
+
* Send a `Date` response header ([#4063], [#4287])
|
|
8
|
+
* Keep extending the systemd startup timeout until Puma is ready ([#3871], [#4282])
|
|
9
|
+
* Exit with status 143 on SIGTERM when Puma runs as PID 1, such as in a container without an init process ([#3941])
|
|
10
|
+
|
|
11
|
+
* Security (Hardening)
|
|
12
|
+
* Reject more malformed requests that RFC 9110 and RFC 9112 forbid, such as duplicate `Host` headers, non-ASCII URLs, invalid HTTP versions, bare CR line endings and malformed chunk extensions ([#4273])
|
|
13
|
+
* Enforce `first_data_timeout` as a total deadline for request headers, so a client can't keep a connection open by sending one byte at a time ([#4094])
|
|
14
|
+
* Close the connection after a request with both `Content-Length` and `Transfer-Encoding` ([#4090])
|
|
15
|
+
* Check the CRLF after chunk data when a chunk spans more than one read ([#4089])
|
|
16
|
+
* Keep the private key out of the `key_pem` error message ([#4061])
|
|
17
|
+
* Validate single-line response header strings ([#4278])
|
|
18
|
+
|
|
19
|
+
* Bugfixes
|
|
20
|
+
* Count IO threads in the admission gate when `queue_requests` is disabled ([#4174])
|
|
21
|
+
* Accept an empty `Host` header, which RFC 9112 requires clients to send when the target URI has no authority ([#4152])
|
|
22
|
+
* Close HTTP/1.0 keep-alive connections when the response body has no known length ([#4062])
|
|
23
|
+
* Fix `RangeError` for chunk sizes that don't fit in a C long ([#4058])
|
|
24
|
+
* Stop `HttpParser#execute` from changing the String passed to it ([#4060])
|
|
25
|
+
* Let busy thread pools shrink when trim is requested ([#3979])
|
|
26
|
+
* Fix swapped thread pool defaults in the server plugin control ([#4067])
|
|
27
|
+
* Keep the SIGTERM exit status when Puma runs on JRuby ([#4203])
|
|
28
|
+
* Honor `exception: false` in `MiniSSL::Socket#read_nonblock` ([#4177])
|
|
29
|
+
* Free MiniSSL engines that have no SSL connection, and free them with Ruby's allocator ([#4179], [#4178])
|
|
30
|
+
* Detect Linux from `RUBY_DESCRIPTION`, so FreeBSD and other platforms are no longer treated as Linux ([#3983])
|
|
31
|
+
* Keep type-limits warnings nonfatal in strict native builds ([#4218])
|
|
32
|
+
|
|
33
|
+
* Performance
|
|
34
|
+
* Reduce allocations per response header in `Response#str_headers` by 80%; a response with a Rails app's headers uses 25% less CPU and 68% fewer allocations than 8.1.3 ([#4048])
|
|
35
|
+
* Avoid copying common HTTP header names, and normalize names with a lookup table ([#4272])
|
|
36
|
+
* Track reactor timeouts in O(1); a reactor wakeup among 600 idle connections uses 12–35x less CPU than 8.1.3, at the cost of more allocations when those connections have mixed timeouts ([#4268])
|
|
37
|
+
* Buffer small chunked request bodies in memory instead of a `Tempfile`; 16 KB chunked POSTs serve about 2x the requests per second of 8.1.3, with 69% lower P99 latency ([#4054])
|
|
38
|
+
* Improve the cluster accept loop delay under partial load and overload ([#4042], [#4286])
|
|
39
|
+
* Load `openssl` at boot instead of on each `peercert` call ([#4285])
|
|
40
|
+
|
|
41
|
+
* Refactor
|
|
42
|
+
* Remove dead code and old compatibility shims ([#4250], [#4289], [#4281])
|
|
43
|
+
* Remove the `MiniSSL::OPENSSL_NO_SSL3`, `OPENSSL_NO_TLS1` and `OPENSSL_NO_TLS1_1` constants ([#4180])
|
|
44
|
+
|
|
45
|
+
* Docs
|
|
46
|
+
* Add `docs/GLOSSARY.md` and use its terms throughout the docs ([#4297])
|
|
47
|
+
|
|
1
48
|
## 8.1.3 / 2026-11-25
|
|
2
49
|
|
|
3
50
|
* Security
|
|
@@ -70,6 +117,23 @@
|
|
|
70
117
|
* Fix typos and grammar in README, CONTRIBUTING and docs ([#4035], [#3974])
|
|
71
118
|
* Improve DSL documentation, including `queue_requests` ([#3966], [#3965])
|
|
72
119
|
|
|
120
|
+
## 8.0.5 / 2026-11-25
|
|
121
|
+
|
|
122
|
+
* Security
|
|
123
|
+
* Apply `verify_mode`, `ca` and the other TLS options of an `ssl://` bind when the `localhost` gem supplies the certificate; such a bind now fails at boot if those options are invalid. ([GHSA-r3wq-wqc8-m4pv](https://github.com/puma/puma/security/advisories/GHSA-r3wq-wqc8-m4pv))
|
|
124
|
+
* Escape control characters and invalid UTF-8 bytes in the first line of error log entries, which can include request data. ([GHSA-rhp6-mwcq-4p4c](https://github.com/puma/puma/security/advisories/GHSA-rhp6-mwcq-4p4c))
|
|
125
|
+
* Escape control characters and invalid UTF-8 bytes in request log lines, such as a `REMOTE_USER` with a line break. ([GHSA-9v95-fm6g-2gj5](https://github.com/puma/puma/security/advisories/GHSA-9v95-fm6g-2gj5))
|
|
126
|
+
* Keep the path of an absolute-form request target as the client sent it, whatever its URI scheme. ([GHSA-w67v-xw8r-x55m](https://github.com/puma/puma/security/advisories/GHSA-w67v-xw8r-x55m))
|
|
127
|
+
* Send error details and backtraces from the control server only in the `development` and `test` environments. ([GHSA-7q89-p6pc-544r](https://github.com/puma/puma/security/advisories/GHSA-7q89-p6pc-544r))
|
|
128
|
+
|
|
129
|
+
## 8.0.4 / 2026-11-17
|
|
130
|
+
|
|
131
|
+
* Security
|
|
132
|
+
* Close a TLS connection when OpenSSL reports a fatal error reading it, rather than buffering everything the client sends until `first_data_timeout`. ([GHSA-4v6q-hvv7-49h9](https://github.com/puma/puma/security/advisories/GHSA-4v6q-hvv7-49h9))
|
|
133
|
+
* On JRuby, stop request headers such as `Query-String` and `Request-Path` from changing `QUERY_STRING`, `PATH_INFO` and the other env keys that come from the request line. ([GHSA-rhww-p99c-hgj9](https://github.com/puma/puma/security/advisories/GHSA-rhww-p99c-hgj9))
|
|
134
|
+
|
|
135
|
+
CVE IDs have been requested for these advisories and will be added here once assigned.
|
|
136
|
+
|
|
73
137
|
## 8.0.3 / 2026-11-13
|
|
74
138
|
|
|
75
139
|
* Security
|
|
@@ -135,6 +199,22 @@
|
|
|
135
199
|
* Breaking changes
|
|
136
200
|
* Default production bind address changed from `0.0.0.0` to `::` (IPv6) when a non-loopback IPv6 interface is available; falls back to `0.0.0.0` if IPv6 is unavailable ([#3847])
|
|
137
201
|
|
|
202
|
+
## 7.2.4 / 2026-11-25
|
|
203
|
+
|
|
204
|
+
* Security
|
|
205
|
+
* Apply `verify_mode`, `ca` and the other TLS options of an `ssl://` bind when the `localhost` gem supplies the certificate; such a bind now fails at boot if those options are invalid. ([GHSA-r3wq-wqc8-m4pv](https://github.com/puma/puma/security/advisories/GHSA-r3wq-wqc8-m4pv))
|
|
206
|
+
* Escape control characters and invalid UTF-8 bytes in the first line of error log entries, which can include request data. ([GHSA-rhp6-mwcq-4p4c](https://github.com/puma/puma/security/advisories/GHSA-rhp6-mwcq-4p4c))
|
|
207
|
+
* Escape control characters and invalid UTF-8 bytes in request log lines, such as a `REMOTE_USER` with a line break. ([GHSA-9v95-fm6g-2gj5](https://github.com/puma/puma/security/advisories/GHSA-9v95-fm6g-2gj5))
|
|
208
|
+
* Keep the path of an absolute-form request target as the client sent it, whatever its URI scheme. ([GHSA-w67v-xw8r-x55m](https://github.com/puma/puma/security/advisories/GHSA-w67v-xw8r-x55m))
|
|
209
|
+
* Send error details and backtraces from the control server only in the `development` and `test` environments. ([GHSA-7q89-p6pc-544r](https://github.com/puma/puma/security/advisories/GHSA-7q89-p6pc-544r))
|
|
210
|
+
|
|
211
|
+
## 7.2.3 / 2026-11-17
|
|
212
|
+
|
|
213
|
+
* Security
|
|
214
|
+
* Close a TLS connection when OpenSSL reports a fatal error reading it, rather than buffering everything the client sends until `first_data_timeout`. ([GHSA-4v6q-hvv7-49h9](https://github.com/puma/puma/security/advisories/GHSA-4v6q-hvv7-49h9))
|
|
215
|
+
|
|
216
|
+
A CVE ID has been requested for this advisory and will be added here once assigned.
|
|
217
|
+
|
|
138
218
|
## 7.2.2 / 2026-11-13
|
|
139
219
|
|
|
140
220
|
* Security
|
|
@@ -2455,6 +2535,46 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
|
2455
2535
|
* Bugfixes
|
|
2456
2536
|
* Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
|
|
2457
2537
|
|
|
2538
|
+
[#4301]:https://github.com/puma/puma/pull/4301 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2539
|
+
[#4260]:https://github.com/puma/puma/pull/4260 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2540
|
+
[#4283]:https://github.com/puma/puma/pull/4283 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2541
|
+
[#4026]:https://github.com/puma/puma/pull/4026 "PR by Shane Becker, merged 2026-11-30"
|
|
2542
|
+
[#4063]:https://github.com/puma/puma/pull/4063 "PR by Ben Sheldon, merged 2026-11-30"
|
|
2543
|
+
[#4287]:https://github.com/puma/puma/pull/4287 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2544
|
+
[#3871]:https://github.com/puma/puma/pull/3871 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2545
|
+
[#4282]:https://github.com/puma/puma/pull/4282 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2546
|
+
[#3941]:https://github.com/puma/puma/pull/3941 "PR by Nikolay Gagarinov, merged 2026-11-30"
|
|
2547
|
+
[#4273]:https://github.com/puma/puma/pull/4273 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2548
|
+
[#4094]:https://github.com/puma/puma/pull/4094 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2549
|
+
[#4090]:https://github.com/puma/puma/pull/4090 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2550
|
+
[#4089]:https://github.com/puma/puma/pull/4089 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2551
|
+
[#4061]:https://github.com/puma/puma/pull/4061 "PR by Samuel Giddins, merged 2026-11-30"
|
|
2552
|
+
[#4278]:https://github.com/puma/puma/pull/4278 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2553
|
+
[#4174]:https://github.com/puma/puma/pull/4174 "PR by William T. Nelson, merged 2026-12-01"
|
|
2554
|
+
[#4152]:https://github.com/puma/puma/pull/4152 "PR by Wesley Beary, merged 2026-12-01"
|
|
2555
|
+
[#4062]:https://github.com/puma/puma/pull/4062 "PR by Samuel Giddins, merged 2026-11-30"
|
|
2556
|
+
[#4058]:https://github.com/puma/puma/pull/4058 "PR by Wleeaf, merged 2026-11-30"
|
|
2557
|
+
[#4060]:https://github.com/puma/puma/pull/4060 "PR by Samuel Giddins, merged 2026-11-30"
|
|
2558
|
+
[#3979]:https://github.com/puma/puma/pull/3979 "PR by Yuki Nishijima, merged 2026-11-27"
|
|
2559
|
+
[#4067]:https://github.com/puma/puma/pull/4067 "PR by Yuki Nishijima, merged 2026-11-27"
|
|
2560
|
+
[#4203]:https://github.com/puma/puma/pull/4203 "PR by Nate Berkopec, merged 2026-11-25"
|
|
2561
|
+
[#4177]:https://github.com/puma/puma/pull/4177 "PR by Nate Berkopec, merged 2026-11-19"
|
|
2562
|
+
[#4179]:https://github.com/puma/puma/pull/4179 "PR by Nate Berkopec, merged 2026-11-19"
|
|
2563
|
+
[#4178]:https://github.com/puma/puma/pull/4178 "PR by Nate Berkopec, merged 2026-11-19"
|
|
2564
|
+
[#3983]:https://github.com/puma/puma/pull/3983 "PR by neil, merged 2026-11-15"
|
|
2565
|
+
[#4218]:https://github.com/puma/puma/pull/4218 "PR by Nate Berkopec, merged 2026-11-25"
|
|
2566
|
+
[#4048]:https://github.com/puma/puma/pull/4048 "PR by scart88, merged 2026-11-30"
|
|
2567
|
+
[#4272]:https://github.com/puma/puma/pull/4272 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2568
|
+
[#4268]:https://github.com/puma/puma/pull/4268 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2569
|
+
[#4054]:https://github.com/puma/puma/pull/4054 "PR by Petrik de Heus, merged 2026-11-30"
|
|
2570
|
+
[#4042]:https://github.com/puma/puma/pull/4042 "PR by scart88, merged 2026-11-30"
|
|
2571
|
+
[#4286]:https://github.com/puma/puma/pull/4286 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2572
|
+
[#4285]:https://github.com/puma/puma/pull/4285 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2573
|
+
[#4250]:https://github.com/puma/puma/pull/4250 "PR by Nate Berkopec, merged 2026-11-30"
|
|
2574
|
+
[#4289]:https://github.com/puma/puma/pull/4289 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2575
|
+
[#4281]:https://github.com/puma/puma/pull/4281 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2576
|
+
[#4180]:https://github.com/puma/puma/pull/4180 "PR by Nate Berkopec, merged 2026-11-19"
|
|
2577
|
+
[#4297]:https://github.com/puma/puma/pull/4297 "PR by Nate Berkopec, merged 2026-12-01"
|
|
2458
2578
|
[#4135]:https://github.com/puma/puma/pull/4135 "PR by Nate Berkopec, merged 2026-11-15"
|
|
2459
2579
|
[#4108]:https://github.com/puma/puma/pull/4108 "PR by Nate Berkopec, merged 2026-11-15"
|
|
2460
2580
|
[#4124]:https://github.com/puma/puma/pull/4124 "PR by Nate Berkopec, merged 2026-11-15"
|
data/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Puma is a **simple, fast, multi-threaded, and highly parallel HTTP 1.1 server fo
|
|
|
20
20
|
Puma is a server for [Rack](https://github.com/rack/rack)-powered HTTP applications written in Ruby. It is:
|
|
21
21
|
* **Multi-threaded**. Each request is served in a separate thread. This helps you serve more requests per second with less memory use.
|
|
22
22
|
* **Multi-process**. "Pre-forks" in cluster mode, using less memory per-process thanks to copy-on-write memory.
|
|
23
|
-
* **Standalone**. With SSL support, zero-downtime
|
|
23
|
+
* **Standalone**. With SSL support, zero-downtime phased restarts and a built-in request bufferer, you can deploy Puma without any reverse proxy.
|
|
24
24
|
* **Battle-tested**. Our HTTP parser is inherited from Mongrel and has over 15 years of production use. Puma is currently the most popular Ruby webserver, and is the default server for Ruby on Rails.
|
|
25
25
|
|
|
26
26
|
Originally designed as a server for [Rubinius](https://github.com/rubinius/rubinius), Puma also works well with Ruby (MRI) and JRuby.
|
|
@@ -100,7 +100,8 @@ and the loaded configuration will be printed as part of the boot process.
|
|
|
100
100
|
* [Configuration](docs/configuration.md)
|
|
101
101
|
* [Cluster mode](docs/cluster_mode.md)
|
|
102
102
|
* [Binding TCP / Sockets and SSL](docs/binding.md)
|
|
103
|
-
* [
|
|
103
|
+
* [HTTPS behind a reverse proxy or in Puma](docs/ssl.md)
|
|
104
|
+
* [Control server and stats](docs/control_server.md)
|
|
104
105
|
* [Restart](docs/restart.md)
|
|
105
106
|
* [Signals](docs/signals.md)
|
|
106
107
|
* [Plugins](docs/plugins.md)
|
|
@@ -125,7 +126,7 @@ Puma stickers, shirts, hoodies, and mugs are available at [commitgoods.com](http
|
|
|
125
126
|
|
|
126
127
|
## Contributing
|
|
127
128
|
|
|
128
|
-
Find details for contributing in the [contribution guide](CONTRIBUTING.md).
|
|
129
|
+
Find details for contributing in the [contribution guide](governance/CONTRIBUTING.md).
|
|
129
130
|
|
|
130
131
|
## License
|
|
131
132
|
|
data/docs/GLOSSARY.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Puma
|
|
2
|
+
|
|
3
|
+
Puma is a threaded, optionally multi-process HTTP server for Ruby Rack applications. This glossary fixes the words used for its processes, request flow, restarts and operations.
|
|
4
|
+
|
|
5
|
+
## Processes
|
|
6
|
+
|
|
7
|
+
**Mode**:
|
|
8
|
+
Whether Puma runs as one process (single mode) or as a master with forked workers (cluster mode).
|
|
9
|
+
_Avoid_: Clustered mode, multi-process mode
|
|
10
|
+
|
|
11
|
+
**Master**:
|
|
12
|
+
In cluster mode, the process that loads configuration, owns the listeners and forks and supervises workers. It never serves requests.
|
|
13
|
+
_Avoid_: Parent, primary, main process
|
|
14
|
+
|
|
15
|
+
**Worker**:
|
|
16
|
+
A child process forked in cluster mode that serves requests with its own thread pool. Always a process, never a thread.
|
|
17
|
+
_Avoid_: Child, worker process (redundant), worker thread
|
|
18
|
+
|
|
19
|
+
**Worker index**:
|
|
20
|
+
A worker's stable slot number in the cluster (0 to workers - 1), kept when the worker in that slot is replaced.
|
|
21
|
+
_Avoid_: Worker ID, worker number
|
|
22
|
+
|
|
23
|
+
**Worker 0**:
|
|
24
|
+
In fork-worker mode, the worker that every other worker is forked from.
|
|
25
|
+
_Avoid_: Seed worker
|
|
26
|
+
|
|
27
|
+
**Mold**:
|
|
28
|
+
In mold-worker mode, a former worker promoted to stop serving requests and do nothing but fork new workers.
|
|
29
|
+
_Avoid_: Template worker, zygote
|
|
30
|
+
|
|
31
|
+
**Phase**:
|
|
32
|
+
A generation number for the cluster that increases with each phased restart or refork. A worker whose phase differs from the master's is an old worker waiting to be replaced.
|
|
33
|
+
_Avoid_: Generation, version
|
|
34
|
+
|
|
35
|
+
**Preload**:
|
|
36
|
+
Loading the application in the master before forking, so workers share its memory through copy-on-write.
|
|
37
|
+
_Avoid_: Eager load
|
|
38
|
+
|
|
39
|
+
**Prune bundler**:
|
|
40
|
+
Starting the master without the application's bundle loaded, so each newly booted worker can load a different bundle.
|
|
41
|
+
|
|
42
|
+
**Worker check-in**:
|
|
43
|
+
A worker's periodic status report to the master. A worker that misses check-ins for longer than the worker timeout is treated as hung and killed.
|
|
44
|
+
_Avoid_: Heartbeat, ping
|
|
45
|
+
|
|
46
|
+
**Worker culling**:
|
|
47
|
+
Choosing which workers to stop when the worker count is reduced.
|
|
48
|
+
|
|
49
|
+
## Requests
|
|
50
|
+
|
|
51
|
+
**Listener**:
|
|
52
|
+
A bound TCP, SSL or UNIX socket that Puma accepts connections from.
|
|
53
|
+
_Avoid_: Bind (for the socket itself; a bind is the configured address)
|
|
54
|
+
|
|
55
|
+
**Bind**:
|
|
56
|
+
A configured address, written as a URI, that Puma turns into a listener.
|
|
57
|
+
|
|
58
|
+
**Socket backlog**:
|
|
59
|
+
The kernel's queue of connections that have arrived on a listener but have not been accepted yet.
|
|
60
|
+
_Avoid_: Backlog (unqualified), accept queue
|
|
61
|
+
|
|
62
|
+
**Backlog**:
|
|
63
|
+
Connections a process has accepted that are waiting for a free thread. This is the value reported in stats.
|
|
64
|
+
_Avoid_: Queue depth, todo queue
|
|
65
|
+
|
|
66
|
+
**Connection**:
|
|
67
|
+
One accepted client socket. Keep-alive lets it carry many requests.
|
|
68
|
+
_Avoid_: Client, request (they are not the same thing)
|
|
69
|
+
|
|
70
|
+
**Reactor**:
|
|
71
|
+
The single thread in each process that holds connections whose request hasn't fully arrived, including idle keep-alive connections, and returns them to the backlog once it has.
|
|
72
|
+
_Avoid_: Event loop, selector
|
|
73
|
+
|
|
74
|
+
**Queue requests**:
|
|
75
|
+
The mode, on by default, in which the reactor buffers requests before they reach a thread. With it off, threads read requests themselves.
|
|
76
|
+
|
|
77
|
+
**Thread pool**:
|
|
78
|
+
The bounded set of threads in a process that run the application for each request. Its size is set by min and max threads.
|
|
79
|
+
_Avoid_: Worker pool
|
|
80
|
+
|
|
81
|
+
**Thread**:
|
|
82
|
+
One member of a thread pool that serves one request at a time.
|
|
83
|
+
_Avoid_: Worker, worker thread
|
|
84
|
+
|
|
85
|
+
**IO thread**:
|
|
86
|
+
A thread whose current request the application has marked as IO-bound, so the thread pool may grow past its maximum up to the configured IO thread allowance.
|
|
87
|
+
_Avoid_: Extra thread, overflow thread
|
|
88
|
+
|
|
89
|
+
**Busy threads**:
|
|
90
|
+
Threads currently serving a request plus connections in the backlog, which measures how loaded a process is.
|
|
91
|
+
|
|
92
|
+
**Wait for less busy worker**:
|
|
93
|
+
A short delay before a busy worker accepts a new connection, so idle workers in the same cluster get it first.
|
|
94
|
+
|
|
95
|
+
**Out-of-band hook**:
|
|
96
|
+
User code that runs in a worker when all of its threads are idle, between requests.
|
|
97
|
+
_Avoid_: Idle hook, OOB GC
|
|
98
|
+
|
|
99
|
+
**Lowlevel error handler**:
|
|
100
|
+
User code that builds the response when the application raises, or when Puma fails outside the application.
|
|
101
|
+
_Avoid_: Error app, rescue handler
|
|
102
|
+
|
|
103
|
+
## Lifecycle and restarts
|
|
104
|
+
|
|
105
|
+
**Hot restart**:
|
|
106
|
+
Restarting by having the master re-exec itself while keeping its listeners open. Configuration, application and Puma itself are all reloaded. Triggered by `USR2`.
|
|
107
|
+
_Avoid_: Full restart, rolling restart
|
|
108
|
+
|
|
109
|
+
**Phased restart**:
|
|
110
|
+
Replacing workers one at a time while the master keeps running, so the application can be upgraded without dropping capacity. Triggered by `USR1`. Cluster mode only.
|
|
111
|
+
_Avoid_: Rolling restart, graceful restart
|
|
112
|
+
|
|
113
|
+
**Refork**:
|
|
114
|
+
In fork-worker or mold-worker mode, replacing workers by forking them again from worker 0 or a newly promoted mold, so they share that process's warmed-up memory. Triggered by `URG`.
|
|
115
|
+
_Avoid_: Re-fork restart
|
|
116
|
+
|
|
117
|
+
**Fork-worker mode**:
|
|
118
|
+
Cluster mode in which workers are forked from worker 0 rather than from the master.
|
|
119
|
+
|
|
120
|
+
**Mold-worker mode**:
|
|
121
|
+
Cluster mode in which workers are forked from a mold, and the mold is replaced at configured request thresholds.
|
|
122
|
+
|
|
123
|
+
**Hook**:
|
|
124
|
+
User code registered in the configuration that Puma runs at a named lifecycle point, such as before a fork or after a worker boots.
|
|
125
|
+
_Avoid_: Callback
|
|
126
|
+
|
|
127
|
+
**Graceful shutdown**:
|
|
128
|
+
Stopping after in-flight requests are finished and idle keep-alive connections are closed.
|
|
129
|
+
|
|
130
|
+
**Force shutdown**:
|
|
131
|
+
Killing threads that are still serving requests once the force-shutdown deadline passes during a stop.
|
|
132
|
+
|
|
133
|
+
**Idle timeout**:
|
|
134
|
+
Shutting the server down after it has received no requests for a set time.
|
|
135
|
+
|
|
136
|
+
## Operations
|
|
137
|
+
|
|
138
|
+
**Control server**:
|
|
139
|
+
An optional HTTP endpoint, separate from the application, that reports stats and accepts commands like restart and stop. It is guarded by a token.
|
|
140
|
+
_Avoid_: Status server, status app, admin server
|
|
141
|
+
|
|
142
|
+
**pumactl**:
|
|
143
|
+
The command-line client that controls a running Puma through the control server, or by sending signals when there is no control server.
|
|
144
|
+
|
|
145
|
+
**State file**:
|
|
146
|
+
A file Puma writes with its pid and control server details so that pumactl can find a running instance.
|
|
147
|
+
_Avoid_: Pidfile (a separate, pid-only file)
|
|
148
|
+
|
|
149
|
+
**Stats**:
|
|
150
|
+
The snapshot of a server's runtime counters (threads, backlog, requests and per-worker status) exposed through the control server and `Puma.stats`.
|
|
151
|
+
_Avoid_: Metrics, status
|
|
152
|
+
|
|
153
|
+
**Plugin**:
|
|
154
|
+
A named extension loaded from the configuration that can add configuration and run background work alongside the server.
|
|
155
|
+
|
|
156
|
+
**Launcher**:
|
|
157
|
+
The top-level object that owns a running Puma instance: configuration, listeners, signal handling and restarts.
|
|
158
|
+
|
|
159
|
+
**Runner**:
|
|
160
|
+
The mode-specific driver that the launcher delegates to: one for single mode and one for cluster mode.
|
data/docs/architecture.md
CHANGED
|
@@ -8,67 +8,66 @@ Puma is a threaded Ruby HTTP application server processing requests across a TCP
|
|
|
8
8
|
and/or UNIX socket.
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Puma processes (there can be one or many) accept connections from the socket
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class).
|
|
11
|
+
Puma processes (there can be one or many) accept connections from the socket and
|
|
12
|
+
put them in the backlog, where an available thread will pick them up (in the
|
|
13
|
+
[`ThreadPool`](../lib/puma/thread_pool.rb) class). Connections that are still
|
|
14
|
+
waiting for request data are buffered by the reactor (in the
|
|
15
|
+
[`Reactor`](../lib/puma/reactor.rb) class) so they don't tie up a thread.
|
|
16
16
|
|
|
17
17
|
Puma works in two main modes: cluster and single. In single mode, only one Puma
|
|
18
18
|
process boots. In cluster mode, a `master` process is booted, which prepares
|
|
19
19
|
(and may boot) the application and then uses the `fork()` system call to create
|
|
20
|
-
one or more
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
one or more _workers_. The workers all listen to the same socket. The `master`
|
|
21
|
+
process does not listen to the socket or process requests - its purpose is
|
|
22
|
+
primarily to manage and listen for UNIX signals and possibly kill or boot
|
|
23
|
+
workers.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
[
|
|
25
|
+
A _worker_ is always a process. The threads created by Puma's
|
|
26
|
+
[`ThreadPool`](../lib/puma/thread_pool.rb) are just _threads_. See
|
|
27
|
+
[GLOSSARY.md](GLOSSARY.md) for the terms used throughout these docs.
|
|
28
28
|
|
|
29
29
|
## How Requests Work
|
|
30
30
|
|
|
31
31
|

|
|
32
32
|
|
|
33
33
|
* Upon startup, Puma listens on a TCP or UNIX socket.
|
|
34
|
-
* The backlog
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
a thread from the
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
* The socket backlog is configured with a default of 1024, but the actual
|
|
35
|
+
value is capped by the `net.core.somaxconn` sysctl value. The socket
|
|
36
|
+
backlog determines the size of the kernel's queue for unaccepted
|
|
37
|
+
connections. If it is full, the operating system is not accepting new
|
|
38
|
+
connections.
|
|
39
|
+
* The socket backlog is distinct from the `backlog` reported by
|
|
40
|
+
`Puma.stats` or the control server, which is the number of connections a
|
|
41
|
+
process has accepted that are waiting for a thread from the
|
|
42
|
+
[`ThreadPool`](../lib/puma/thread_pool.rb).
|
|
43
|
+
* A server thread accepts connections from the socket and pushes them into the
|
|
44
|
+
backlog.
|
|
45
|
+
* In cluster mode, a busy worker briefly delays accepting so that less busy
|
|
46
|
+
workers pick up the connection first (`wait_for_less_busy_worker`).
|
|
47
|
+
* Threads pop connections off the backlog for processing.
|
|
48
|
+
* The thread reads the request. If the full request hasn't arrived yet, it
|
|
49
|
+
hands the connection to the reactor and moves on.
|
|
50
|
+
* The reactor is a single, separate thread (created by the
|
|
51
|
+
[`Reactor`](../lib/puma/reactor.rb) class) that waits for the rest of the
|
|
52
|
+
request to arrive, then pushes the connection back into the backlog.
|
|
48
53
|
* Puma exposes the time spent waiting for the HTTP request body to be
|
|
49
54
|
received to the Rack app as `env['puma.request_body_wait']`
|
|
50
55
|
(milliseconds).
|
|
51
|
-
*
|
|
52
|
-
set.
|
|
53
|
-
* Worker threads pop work off the "todo" set for processing.
|
|
54
|
-
* The worker thread processes the request via `call`ing the configured Rack
|
|
56
|
+
* The thread processes the request via `call`ing the configured Rack
|
|
55
57
|
application. The Rack application generates the HTTP response.
|
|
56
|
-
* The
|
|
57
|
-
requests via
|
|
58
|
-
responses.
|
|
58
|
+
* The thread writes the response to the connection. While Puma buffers
|
|
59
|
+
requests via the reactor, it does not use a separate thread for responses.
|
|
59
60
|
* Once done, the thread becomes available to process another connection in the
|
|
60
|
-
|
|
61
|
+
backlog. Idle keep-alive connections go back to the reactor to wait for
|
|
62
|
+
their next request.
|
|
61
63
|
|
|
62
64
|
### `queue_requests`
|
|
63
65
|
|
|
64
66
|

|
|
65
67
|
|
|
66
|
-
The `queue_requests` option is `true` by default, enabling the
|
|
67
|
-
|
|
68
|
+
The `queue_requests` option is `true` by default, enabling the reactor used to
|
|
69
|
+
buffer requests as described above.
|
|
68
70
|
|
|
69
|
-
If set to `false`,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
In this mode, when a connection is accepted, it is added to the "todo" queue
|
|
73
|
-
immediately, and a worker will synchronously do any waiting necessary to read
|
|
74
|
-
the HTTP request from the socket.
|
|
71
|
+
If set to `false`, no reactor runs. Puma only accepts a connection when a thread
|
|
72
|
+
is free, and that thread synchronously does any waiting necessary to read the
|
|
73
|
+
HTTP request from the socket.
|
data/docs/binding.md
CHANGED
|
@@ -25,6 +25,9 @@ Need a bit of security? Use SSL sockets:
|
|
|
25
25
|
```
|
|
26
26
|
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
|
|
27
27
|
```
|
|
28
|
+
|
|
29
|
+
If a reverse proxy already handles HTTPS, Puma usually needs no SSL bind. See [HTTPS with Puma](ssl.md).
|
|
30
|
+
|
|
28
31
|
## Self-signed SSL certificates (via the [`localhost`] gem, for development use):
|
|
29
32
|
|
|
30
33
|
Puma supports the [`localhost`] gem for self-signed certificates. This is particularly useful if you want to use Puma with SSL locally, and self-signed certificates will work for your use-case. Currently, the integration can only be used in MRI.
|
data/docs/cluster_mode.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Cluster mode
|
|
2
2
|
|
|
3
|
-
Puma also offers "cluster mode". Cluster mode `fork`s workers from a master process. Each
|
|
3
|
+
Puma also offers "cluster mode". Cluster mode `fork`s workers from a master process. Each worker still has its own thread pool. You can tune the number of workers with the `-w` (or `--workers`) flag:
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
$ puma -t 8:32 -w 3
|
|
@@ -47,8 +47,8 @@ Preloading can’t be used with phased restart, since phased restart kills and r
|
|
|
47
47
|
|
|
48
48
|
## Cluster mode hooks
|
|
49
49
|
|
|
50
|
-
When using
|
|
51
|
-
hooks to run code when the master process forks, the
|
|
50
|
+
When using cluster mode, Puma's configuration DSL provides `before_fork`, `before_worker_boot`, and `after_worker_shutdown`
|
|
51
|
+
hooks to run code when the master process forks, the workers are booted, and after each worker exits respectively.
|
|
52
52
|
|
|
53
53
|
It is recommended to use these hooks with `preload_app!`, otherwise constants loaded by your
|
|
54
54
|
application (such as `Rails`) will not be available inside the hooks.
|
|
@@ -56,7 +56,7 @@ application (such as `Rails`) will not be available inside the hooks.
|
|
|
56
56
|
```ruby
|
|
57
57
|
# config/puma.rb
|
|
58
58
|
before_fork do
|
|
59
|
-
# Add code to run inside the Puma master process before it forks a worker
|
|
59
|
+
# Add code to run inside the Puma master process before it forks a worker.
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
before_worker_boot do
|
|
@@ -70,19 +70,19 @@ end
|
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
In addition, there are `before_refork` and `after_refork` hooks which are used only in [`fork_worker` mode](#fork-worker-cluster-mode-experimental),
|
|
73
|
-
when
|
|
73
|
+
when worker 0 forks another worker:
|
|
74
74
|
|
|
75
75
|
```ruby
|
|
76
76
|
before_refork do
|
|
77
|
-
# Used only when fork_worker mode is enabled. Add code to run inside
|
|
78
|
-
#
|
|
77
|
+
# Used only when fork_worker mode is enabled. Add code to run inside Puma worker 0
|
|
78
|
+
# before it forks another worker.
|
|
79
79
|
end
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
```ruby
|
|
83
83
|
after_refork do
|
|
84
|
-
# Used only when fork_worker mode is enabled. Add code to run inside
|
|
85
|
-
#
|
|
84
|
+
# Used only when fork_worker mode is enabled. Add code to run inside Puma worker 0
|
|
85
|
+
# after it forks another worker.
|
|
86
86
|
end
|
|
87
87
|
```
|
|
88
88
|
|
|
@@ -100,10 +100,10 @@ Therefore, we recommend the following:
|
|
|
100
100
|
|
|
101
101
|
1. If possible, do not establish any socket connections (HTTP, database connections, etc.)
|
|
102
102
|
inside Puma's master process when booting.
|
|
103
|
-
2. If (1) is not possible, use `before_fork` and `before_refork` to disconnect the
|
|
104
|
-
connections when forking, so that they are not accidentally copied to the
|
|
105
|
-
3. Use `before_worker_boot` to restart any background threads
|
|
106
|
-
4. Use `after_refork` to restart any background threads
|
|
103
|
+
2. If (1) is not possible, use `before_fork` and `before_refork` to disconnect the master's (or worker 0's) socket
|
|
104
|
+
connections when forking, so that they are not accidentally copied to the new worker.
|
|
105
|
+
3. Use `before_worker_boot` to restart any background threads in the new worker.
|
|
106
|
+
4. Use `after_refork` to restart any background threads in worker 0.
|
|
107
107
|
|
|
108
108
|
## Fork-Worker Cluster Mode [Experimental]
|
|
109
109
|
|
|
@@ -132,9 +132,9 @@ The `fork_worker` option allows your application to be initialized only once for
|
|
|
132
132
|
### Usage Considerations
|
|
133
133
|
|
|
134
134
|
- `fork_worker` introduces new `before_refork` and `after_refork` configuration hooks. Note the following:
|
|
135
|
-
- When
|
|
136
|
-
- When
|
|
137
|
-
- For clarity, `before_fork` does not trigger
|
|
135
|
+
- When the master forks worker 0, `before_fork` will trigger in the master and `before_worker_boot` will trigger in worker 0 as normal.
|
|
136
|
+
- When worker 0 forks the other workers, `before_refork` and `after_refork` will trigger in worker 0, and `before_worker_boot` will trigger in each new worker.
|
|
137
|
+
- For clarity, `before_fork` does not trigger in worker 0, and `after_refork` does not trigger in the workers forked from it.
|
|
138
138
|
- As a general migration guide:
|
|
139
139
|
- Copy any logic within your existing `before_fork` hook to the `before_refork` hook.
|
|
140
140
|
- Consider copying 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.
|
|
@@ -177,13 +177,13 @@ mold_worker 1000, 2000, 4000
|
|
|
177
177
|
- `before_mold_shutdown` runs in the mold before it exits.
|
|
178
178
|
- `before_worker_boot` runs in each forked worker, as usual. Use it for what you would do in `after_refork`.
|
|
179
179
|
|
|
180
|
-
## Using gRPC with Puma in
|
|
180
|
+
## Using gRPC with Puma in Cluster Mode
|
|
181
181
|
|
|
182
|
-
This guide shows how to set up gRPC with Puma in
|
|
182
|
+
This guide shows how to set up gRPC with Puma in cluster mode using Puma's hooks to manage gRPC's lifecycle methods during forking.
|
|
183
183
|
|
|
184
184
|
### The Problem
|
|
185
185
|
|
|
186
|
-
In
|
|
186
|
+
In cluster mode, you might encounter the following error when using gRPC:
|
|
187
187
|
|
|
188
188
|
```
|
|
189
189
|
grpc cannot be used between calls to GRPC.prefork and GRPC.postfork_child or GRPC.postfork_parent
|
|
@@ -194,13 +194,13 @@ To work correctly, gRPC needs these methods called at specific points in the pro
|
|
|
194
194
|
- `GRPC.postfork_child`: Called in the child process after forking.
|
|
195
195
|
- `GRPC.postfork_parent`: Called in the parent process after forking.
|
|
196
196
|
|
|
197
|
-
Puma provides hooks such as `before_worker_fork`, `after_worker_fork`, and `before_worker_boot` to execute code during these lifecycle events. Understanding the behavior of these hooks is key to ensuring gRPC operates correctly in
|
|
197
|
+
Puma provides hooks such as `before_worker_fork`, `after_worker_fork`, and `before_worker_boot` to execute code during these lifecycle events. Understanding the behavior of these hooks is key to ensuring gRPC operates correctly in cluster mode.
|
|
198
198
|
|
|
199
199
|
### The Solution
|
|
200
200
|
|
|
201
201
|
#### Example Configuration
|
|
202
202
|
|
|
203
|
-
This configuration integrates gRPC's lifecycle methods in
|
|
203
|
+
This configuration integrates gRPC's lifecycle methods in cluster mode and works whether preloading is enabled or not.
|
|
204
204
|
|
|
205
205
|
```ruby
|
|
206
206
|
# config/puma.rb
|
data/docs/control_server.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# Control
|
|
1
|
+
# Control Server
|
|
2
2
|
|
|
3
|
-
Puma has a built-in
|
|
3
|
+
Puma has a built-in control server that can be used to query and control Puma.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
$ puma --control-url tcp://127.0.0.1:9293 --control-token foo
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
Puma will start the control server on localhost port 9293. All requests to the control server will need to include a 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
|
|
9
|
+
Puma will start the control server on localhost port 9293. All requests to the control server will need to include a 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 control server has available.
|
|
10
10
|
|
|
11
11
|
You can also interact with the control server via `pumactl`. This command will restart Puma:
|
|
12
12
|
|
|
@@ -98,7 +98,7 @@ When Puma runs in single mode, these stats are available at the top level. When
|
|
|
98
98
|
* pid: the process id of the worker process
|
|
99
99
|
* index: each worker gets a number. If Puma is configured to have 3 workers, then this will be 0, 1, or 2
|
|
100
100
|
* booted: if it's done booting [?]
|
|
101
|
-
* last_checkin: Last time the worker
|
|
101
|
+
* last_checkin: Last time the worker checked in with the master process.
|
|
102
102
|
* last_status: a hash of info about the worker's state handling requests. See the explanation for this in "single mode and individual workers in cluster mode" section above.
|
|
103
103
|
|
|
104
104
|
|
data/docs/deployment/nginx.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This is a very common setup using an upstream. It was adapted from some Capistrano recipe I found on the Internet a while ago.
|
|
4
4
|
|
|
5
|
+
For HTTPS terminated at nginx, see [HTTPS with Puma](../ssl.md).
|
|
6
|
+
|
|
5
7
|
```nginx
|
|
6
8
|
upstream myapp {
|
|
7
9
|
server unix:///myapp/tmp/puma.sock;
|