puma 5.1.1 → 5.2.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puma might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a6a1bfd1d41d66c8aef6c52a2a043a0e537a1ddb51e20c778bb2da023d9a964
4
- data.tar.gz: d256171ae36d0c5d1646ecbea4476df3e1bf7fbba5415c6ca6672eacbc5bd995
3
+ metadata.gz: d702fffe078664ed49a411a31910737455c819d6acadd3875c89e00368f68dd8
4
+ data.tar.gz: 972f53b07a05363ff839b6f176150bdf4cbc19f7445601ad10f41e9bcaf73af2
5
5
  SHA512:
6
- metadata.gz: 9d6e9dfa206d98785ff62d7c03cd5193d5745918d684bf2a7d78027294ae345eb34d32d819ffda08ba34629cda589b0138faf1fdc91606a0cbab352615c859f3
7
- data.tar.gz: 6775ccd4eaf9abdda6191c07b7d668588b813dbc96b71496b98cb0ee2ffefb94dd3db068159d8a2c746e5bcc4e4456fa6c4f12c721b66f6c5bed13b9e19718e2
6
+ metadata.gz: fff3451918f8e34324189c0fa6c161baa1860181920f934541a4db9b5e484d20edae74dd9ac33baa3c14514c75d052cbb5d42539f371bf33cca82e644aa52c57
7
+ data.tar.gz: 86c7ba8cb909bedb1dceb259d28677295a71e66b53ed1f1fb6ce324ddab0dbe05c5469aaa120f50f7427cc257d6fa6b6898c7b0346810871f1fceb2ad25bab93
data/History.md CHANGED
@@ -1,8 +1,38 @@
1
+ ## 5.2.1 / 2021-02-05
2
+
3
+ * Bugfixes
4
+ * Fix TCP cork/uncork operations to work with ssl clients ([#2550])
5
+ * Require rack/common_logger explicitly if :verbose is true ([#2547])
6
+ * MiniSSL::Socket#write - use data.byteslice(wrote..-1) ([#2543])
7
+ * Set `@env[CONTENT_LENGTH]` value as string. ([#2549])
8
+
9
+ ## 5.2.0 / 2021-01-27
10
+
11
+ * Features
12
+ * 10x latency improvement for MRI on ssl connections by reducing overhead ([#2519])
13
+ * Add option to specify the desired IO selector backend for libev ([#2522])
14
+ * Add ability to set OpenSSL verification flags (MRI only) ([#2490])
15
+ * Uses `flush` after writing messages to avoid mutating $stdout and $stderr using `sync=true` ([#2486])
16
+
17
+ * Bugfixes
18
+ * MiniSSL - Update dhparam to 2048 bit for use with SSL_CTX_set_tmp_dh ([#2535])
19
+ * Change 'Goodbye!' message to be output after listeners are closed ([#2529])
20
+ * Fix ssl bind logging with 0.0.0.0 and localhost ([#2533])
21
+ * Fix compiler warnings, but skipped warnings related to ragel state machine generated code ([#1953])
22
+ * Fix phased restart errors related to nio4r gem when using the Puma control server ([#2516])
23
+ * Add `#string` method to `Puma::NullIO` ([#2520])
24
+ * Fix binding via Rack handler to IPv6 addresses ([#2521])
25
+
26
+ * Refactor
27
+ * Refactor MiniSSL::Context on MRI, fix MiniSSL::Socket#write ([#2519])
28
+ * Remove `Server#read_body` ([#2531])
29
+ * Fail build if compiling extensions raises warnings on GH Actions, configurable via `MAKE_WARNINGS_INTO_ERRORS` ([#1953])
30
+
1
31
  ## 5.1.1 / 2020-12-10
2
32
 
3
- * Bugfixes
33
+ * Bugfixes
4
34
  * Fix over eager matching against banned header names ([#2510])
5
-
35
+
6
36
  ## 5.1.0 / 2020-11-30
7
37
 
8
38
  * Features
@@ -98,7 +128,7 @@
98
128
  * Daemonization has been removed without replacement. ([#2170])
99
129
  * Changed #connected_port to #connected_ports ([#2076])
100
130
  * Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found ([#2022])
101
- * Log binding on http:// for TCP bindings to make it clickable
131
+ * Log binding on http:// for TCP bindings to make it clickable ([#2300])
102
132
 
103
133
  * Bugfixes
104
134
  * Fix JSON loading issues on phased-restarts ([#2269])
@@ -144,16 +174,16 @@
144
174
  * Support parallel tests in verbose progress reporting ([#2223])
145
175
  * Refactor error handling in server accept loop ([#2239])
146
176
 
147
- ## 4.3.6 / 2020-09-05
177
+ ## 4.3.7 / 2020-11-30
148
178
 
149
179
  * Bugfixes
150
- * Explicitly include ctype.h to fix compilation warning and build error on macOS with Xcode 12 ([#2304])
151
- * Don't require json at boot ([#2269])
180
+ * Backport set CONTENT_LENGTH for chunked requests (Originally: [#2287], backport: [#2496])
152
181
 
153
- ## 4.3.7 / 2020-11-30
182
+ ## 4.3.6 / 2020-09-05
154
183
 
155
184
  * Bugfixes
156
- * Backport set CONTENT_LENGTH for chunked requests (Originally: [#2287], backport: [#2496])
185
+ * Explicitly include ctype.h to fix compilation warning and build error on macOS with Xcode 12 ([#2304])
186
+ * Don't require json at boot ([#2269])
157
187
 
158
188
  ## 4.3.4/4.3.5 and 3.12.5/3.12.6 / 2020-05-22
159
189
 
@@ -1672,7 +1702,23 @@ be added back in a future date when a java Puma::MiniSSL is added.
1672
1702
  * Bugfixes
1673
1703
  * Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
1674
1704
 
1675
- [#2510]:https://github.com/puma/puma/pull/2510 "PR by @micke"
1705
+ [#2550]:https://github.com/puma/puma/pull/2550 "PR by @MSP-Greg, merged 2021-02-05"
1706
+ [#2547]:https://github.com/puma/puma/pull/2547 "PR by @wildmaples, merged 2021-02-03"
1707
+ [#2543]:https://github.com/puma/puma/pull/2543 "PR by @MSP-Greg, merged 2021-02-01"
1708
+ [#2549]:https://github.com/puma/puma/pull/2549 "PR by @nmb, merged 2021-02-04"
1709
+ [#2519]:https://github.com/puma/puma/pull/2519 "PR by @MSP-Greg, merged 2021-01-26"
1710
+ [#2522]:https://github.com/puma/puma/pull/2522 "PR by @jcmfernandes, merged 2021-01-12"
1711
+ [#2490]:https://github.com/puma/puma/pull/2490 "PR by @Bonias, merged 2020-12-07"
1712
+ [#2486]:https://github.com/puma/puma/pull/2486 "PR by @ccverak, merged 2020-12-02"
1713
+ [#2535]:https://github.com/puma/puma/pull/2535 "PR by @MSP-Greg, merged 2021-01-27"
1714
+ [#2529]:https://github.com/puma/puma/pull/2529 "PR by @MSP-Greg, merged 2021-01-24"
1715
+ [#2533]:https://github.com/puma/puma/pull/2533 "PR by @MSP-Greg, merged 2021-01-24"
1716
+ [#1953]:https://github.com/puma/puma/issues/1953 "Issue by @nateberkopec, closed 2020-12-01"
1717
+ [#2516]:https://github.com/puma/puma/pull/2516 "PR by @cjlarose, merged 2020-12-17"
1718
+ [#2520]:https://github.com/puma/puma/pull/2520 "PR by @dentarg, merged 2021-01-04"
1719
+ [#2521]:https://github.com/puma/puma/pull/2521 "PR by @ojab, merged 2021-01-04"
1720
+ [#2531]:https://github.com/puma/puma/pull/2531 "PR by @wjordan, merged 2021-01-19"
1721
+ [#2510]:https://github.com/puma/puma/pull/2510 "PR by @micke, merged 2020-12-10"
1676
1722
  [#2472]:https://github.com/puma/puma/pull/2472 "PR by @ccverak, merged 2020-11-02"
1677
1723
  [#2438]:https://github.com/puma/puma/pull/2438 "PR by @ekohl, merged 2020-10-26"
1678
1724
  [#2406]:https://github.com/puma/puma/pull/2406 "PR by @fdel15, merged 2020-10-19"
@@ -1736,6 +1782,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
1736
1782
  [#2170]:https://github.com/puma/puma/pull/2170 "PR by @nateberkopec, merged 2020-03-10"
1737
1783
  [#2076]:https://github.com/puma/puma/pull/2076 "PR by @drews256, merged 2020-02-27"
1738
1784
  [#2022]:https://github.com/puma/puma/pull/2022 "PR by @olleolleolle, merged 2019-11-11"
1785
+ [#2300]:https://github.com/puma/puma/pull/2300 "PR by @alexeevit, merged 2020-07-06"
1739
1786
  [#2269]:https://github.com/puma/puma/pull/2269 "PR by @MSP-Greg, merged 2020-08-31"
1740
1787
  [#2312]:https://github.com/puma/puma/pull/2312 "PR by @MSP-Greg, merged 2020-07-20"
1741
1788
  [#2338]:https://github.com/puma/puma/issues/2338 "Issue by @micahhainlinestitchfix, closed 2020-08-18"
@@ -1771,8 +1818,8 @@ be added back in a future date when a java Puma::MiniSSL is added.
1771
1818
  [#2124]:https://github.com/puma/puma/pull/2124 "PR by @wjordan, merged 2020-04-14"
1772
1819
  [#2223]:https://github.com/puma/puma/pull/2223 "PR by @wjordan, merged 2020-04-20"
1773
1820
  [#2239]:https://github.com/puma/puma/pull/2239 "PR by @wjordan, merged 2020-05-15"
1774
- [#2304]:https://github.com/puma/puma/issues/2304 "Issue by @mpeltomaa, closed 2020-09-05"
1775
1821
  [#2496]:https://github.com/puma/puma/pull/2496 "PR by @TheRusskiy, merged 2020-11-30"
1822
+ [#2304]:https://github.com/puma/puma/issues/2304 "Issue by @mpeltomaa, closed 2020-09-05"
1776
1823
  [#2132]:https://github.com/puma/puma/issues/2132 "Issue by @bmclean, closed 2020-02-28"
1777
1824
  [#2010]:https://github.com/puma/puma/pull/2010 "PR by @nateberkopec, merged 2019-10-07"
1778
1825
  [#2012]:https://github.com/puma/puma/pull/2012 "PR by @headius, merged 2019-10-07"
@@ -2119,7 +2166,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
2119
2166
  [#646]:https://github.com/puma/puma/pull/646 "PR by @mkonecny, merged 2015-02-05"
2120
2167
  [#630]:https://github.com/puma/puma/issues/630 "Issue by @jelmd, closed 2015-01-20"
2121
2168
  [#622]:https://github.com/puma/puma/issues/622 "Issue by @sabamotto, closed 2015-01-20"
2122
- [#583]:https://github.com/puma/puma/issues/583 "Issue by @emq, closed 2015-01-20"
2169
+ [#583]:https://github.com/puma/puma/issues/583 "Issue by @rwojsznis, closed 2015-01-20"
2123
2170
  [#586]:https://github.com/puma/puma/issues/586 "Issue by @ponchik, closed 2015-01-20"
2124
2171
  [#359]:https://github.com/puma/puma/issues/359 "Issue by @natew, closed 2014-12-13"
2125
2172
  [#633]:https://github.com/puma/puma/issues/633 "Issue by @joevandyk, closed 2015-01-20"
data/README.md CHANGED
@@ -212,6 +212,23 @@ Disable TLS v1 with the `no_tlsv1` option:
212
212
  $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true'
213
213
  ```
214
214
 
215
+ #### Controlling OpenSSL Verification Flags
216
+
217
+ To enable verification flags offered by OpenSSL, use `verification_flags` (not available for JRuby):
218
+
219
+ ```
220
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&verification_flags=PARTIAL_CHAIN'
221
+ ```
222
+
223
+ You can also set multiple verification flags (by separating them with coma):
224
+
225
+ ```
226
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&verification_flags=PARTIAL_CHAIN,CRL_CHECK'
227
+ ```
228
+
229
+ List of available flags: `USE_CHECK_TIME`, `CRL_CHECK`, `CRL_CHECK_ALL`, `IGNORE_CRITICAL`, `X509_STRICT`, `ALLOW_PROXY_CERTS`, `POLICY_CHECK`, `EXPLICIT_POLICY`, `INHIBIT_ANY`, `INHIBIT_MAP`, `NOTIFY_POLICY`, `EXTENDED_CRL_SUPPORT`, `USE_DELTAS`, `CHECK_SS_SIGNATURE`, `TRUSTED_FIRST`, `SUITEB_128_LOS_ONLY`, `SUITEB_192_LOS`, `SUITEB_128_LOS`, `PARTIAL_CHAIN`, `NO_ALT_CHAINS`, `NO_CHECK_TIME`
230
+ (see https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_hostflags.html#VERIFICATION-FLAGS).
231
+
215
232
  ### Control/Status Server
216
233
 
217
234
  Puma has a built-in status and control app that can be used to query and control Puma.
@@ -238,7 +255,7 @@ You can also provide a configuration file with the `-C` (or `--config`) flag:
238
255
  $ puma -C /path/to/config
239
256
  ```
240
257
 
241
- If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` or the `RAILS_ENV` environment variables, Puma looks for configuration at `config/puma/<environment_name>.rb`.
258
+ If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` or the `RAILS_ENV` environment variables, Puma first looks for configuration at `config/puma/<environment_name>.rb`, and then falls back to `config/puma.rb`.
242
259
 
243
260
  If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:
244
261
 
@@ -266,6 +283,7 @@ Some platforms do not support all Puma features.
266
283
 
267
284
  * **JRuby**, **Windows**: server sockets are not seamless on restart, they must be closed and reopened. These platforms have no way to pass descriptors into a new process that is exposed to Ruby. Also, cluster mode is not supported due to a lack of fork(2).
268
285
  * **Windows**: Cluster mode is not supported due to a lack of fork(2).
286
+ * **Kubernetes**: The way Kubernetes handles pod shutdowns interacts poorly with server processes implementing graceful shutdown, like Puma. See the [kubernetes section of the documentation](docs/kubernetes.md) for more details.
269
287
 
270
288
  ## Known Bugs
271
289
 
@@ -291,6 +309,10 @@ reliability in production environments:
291
309
  * [rc.d](docs/jungle/rc.d/README.md)
292
310
  * [systemd](docs/systemd.md)
293
311
 
312
+ Community guides:
313
+
314
+ * [Deploying Puma on OpenBSD using relayd and httpd](https://gist.github.com/anon987654321/4532cf8d6c59c1f43ec8973faa031103)
315
+
294
316
  ## Community Extensions
295
317
 
296
318
  ### Plugins
@@ -1,19 +1,19 @@
1
1
  # Compile Options
2
2
 
3
- There provide some `cflags` to change Puma's default configuration for C.
3
+ There are some `cflags` provided to change Puma's default configuration for its C extension.
4
4
 
5
- ## Query String
5
+ ## Query String, `PUMA_QUERY_STRING_MAX_LENGTH`
6
6
 
7
- By default, the max length of `QUERY_STRING` is `1024 * 10`. But you may want to adjust it to allow accept large queries in the GET requests.
7
+ By default, the max length of `QUERY_STRING` is `1024 * 10`. But you may want to adjust it to allow accept larger queries in GET requests.
8
8
 
9
- For manual install
9
+ For manual install, pass the `PUMA_QUERY_STRING_MAX_LENGTH` option like this:
10
10
 
11
11
  ```
12
12
  gem install puma -- --with-cflags="-D PUMA_QUERY_STRING_MAX_LENGTH=64000"
13
13
  ```
14
14
 
15
- For bundler config
15
+ For Bundler, use its configuration system:
16
16
 
17
17
  ```
18
- bundle config build.puma --with-cflags="-D PUMA_QUERY_STRING_MAX_LENGTH=64000"
18
+ bundle config build.puma "--with-cflags='-D PUMA_QUERY_STRING_MAX_LENGTH=64000'"
19
19
  ```
data/docs/deployment.md CHANGED
@@ -29,7 +29,7 @@ Here are some rules of thumb for cluster mode:
29
29
  * Use cluster mode and set the number of workers to 1.5x the number of cpu cores
30
30
  in the machine, minimum 2.
31
31
  * Set the number of threads to desired concurrent requests / number of workers.
32
- Puma defaults to 16 and that's a decent number.
32
+ Puma defaults to 5 and that's a decent number.
33
33
 
34
34
  #### Migrating from Unicorn
35
35
 
@@ -0,0 +1,66 @@
1
+ # Kubernetes
2
+
3
+ ## Running Puma in Kubernetes
4
+
5
+ In general running Puma in Kubernetes works as-is, no special configuration is needed beyond what you would write anyway to get a new Kubernetes Deployment going. There is one known interaction between the way Kubernetes handles pod termination and how Puma handles `SIGINT`, where some request might be sent to Puma after it has already entered graceful shutdown mode and is no longer accepting requests. This can lead to dropped requests during rolling deploys. A workaround for this is listed at the end of this article.
6
+
7
+ ## Basic setup
8
+
9
+ Assuming you already have a running cluster and docker image repository, you can run a simple Puma app with the following example Dockerfile and Deployment specification. These are meant as examples only and are deliberately very minimal to the point of skipping many options that are recommended for running in production, like healthchecks and envvar configuration with ConfigMaps. In general you should check the [Kubernetes documentation](https://kubernetes.io/docs/home/) and [Docker documentation](https://docs.docker.com/) for a more comprehensive overview of the available options.
10
+
11
+ A basic Dockerfile example:
12
+ ```
13
+ FROM ruby:2.5.1-alpine # can be updated to newer ruby versions
14
+ RUN apk update && apk add build-base # and any other packages you need
15
+
16
+ # Only rebuild gem bundle if Gemfile changes
17
+ COPY Gemfile Gemfile.lock ./
18
+ RUN bundle install
19
+
20
+ # Copy over the rest of the files
21
+ COPY . .
22
+
23
+ # Open up port and start the service
24
+ EXPOSE 9292
25
+ CMD bundle exec rackup -o 0.0.0.0
26
+ ```
27
+
28
+ A sample `deployment.yaml`:
29
+ ```
30
+ ---
31
+ apiVersion: apps/v1
32
+ kind: Deployment
33
+ metadata:
34
+ name: my-awesome-puma-app
35
+ spec:
36
+ selector:
37
+ matchLabels:
38
+ app: my-awesome-puma-app
39
+ template:
40
+ metadata:
41
+ labels:
42
+ app: my-awesome-puma-app
43
+ service: my-awesome-puma-app
44
+ spec:
45
+ containers:
46
+ - name: my-awesome-puma-app
47
+ image: <your image here>
48
+ ports:
49
+ - containerPort: 9292
50
+ ```
51
+
52
+ ## Graceful shutdown and pod termination
53
+
54
+ For some high-throughput systems, it is possible that some HTTP requests will return responses with response codes in the 5XX range during a rolling deploy to a new version. This is caused by [the way that Kubernetes terminates a pod during rolling deploys](https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-terminating-with-grace):
55
+
56
+ 1. The replication controller determines a pod should be shut down.
57
+ 2. The Pod is set to the “Terminating” State and removed from the endpoints list of all Services, so that it receives no more requests.
58
+ 3. The pods pre-stop hook get called. The default for this is to send `SIGTERM` to the process inside the pod.
59
+ 4. The pod has up to `terminationGracePeriodSeconds` (default: 30 seconds) to gracefully shut down. Puma will do this (after it receives SIGTERM) by closing down the socket that accepts new requests and finishing any requests already running before exiting the Puma process.
60
+ 5. If the pod is still running after `terminationGracePeriodSeconds` has elapsed, the pod receives `SIGKILL` to make sure the process inside it stops. After that, the container exits and all other Kubernetes objects associated with it are cleaned up.
61
+
62
+ There is a subtle race condition between step 2 and 3: The replication controller does not synchronously remove the pod from the Services AND THEN call the pre-stop hook of the pod, but rather it asynchronously sends "remove this pod from your endpoints" requests to the Services and then immediately proceeds to invoke the pods' pre-stop hook. If the Service controller (typically something like nginx or haproxy) receives this request handles this request "too" late (due to internal lag or network latency between the replication and Service controllers) then it is possible that the Service controller will send one or more requests to a Puma process which has already shut down its listening socket. These requests will then fail with 5XX error codes.
63
+
64
+ The way Kubernetes works this way, rather than handling step 2 synchronously, is due to the CAP theorem: in a distributed system there is no way to guarantuee that any message will arrive promptly. In particular, waiting for all Service controllers to report back might get stuck for an indefinite time if one of them has already been terminated or if there has been a net split. A way to work around this is to add a sleep to the pre-stop hook of the same time as the `terminationGracePeriodSeconds` time. This will allow the Puma process to keep serving new requests during the entire grace period, although it will no longer receive new requests after all Service controllers have propagated the removal of the pod from their endpoint lists. Then, after `terminationGracePeriodSeconds`, the pod receives `SIGKILL` and closes down. If your process can't handle SIGKILL properly, for example because it needs to release locks in different services, you can also sleep for a shorter period (and/or increase `terminationGracePeriodSeconds`) as long as the time slept is longer than the time that your Service controllers take to propagate the pod removal. The downside of this workaround is that all pods will take at minimum the amount of time slept to shut down and this will increase the time required for your rolling deploy.
65
+
66
+ More discussions and links to relevant articles can be found in https://github.com/puma/puma/issues/2343.
data/docs/plugins.md CHANGED
@@ -8,7 +8,7 @@ operations.
8
8
  * [tmp\_restart](https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb):
9
9
  Restarts the server if the file `tmp/restart.txt` is touched
10
10
  * [heroku](https://github.com/puma/puma-heroku/blob/master/lib/puma/plugin/heroku.rb):
11
- Packages up the default configuration used by puma on Heroku
11
+ Packages up the default configuration used by puma on Heroku (being sunset with the release of Puma 5.0)
12
12
 
13
13
  Plugins are activated in a puma configuration file (such as `config/puma.rb'`)
14
14
  by adding `plugin "name"`, such as `plugin "heroku"`.
@@ -0,0 +1,29 @@
1
+ # Running Puma in Rails Development Mode
2
+
3
+ ## "Loopback requests"
4
+
5
+ Be cautious of "loopback requests", where a Rails application executes a request to a server that in turn, results in another request back to the same Rails application before the first request is completed. Having a loopback request will trigger [Rails' load interlock](https://guides.rubyonrails.org/threading_and_code_execution.html#load-interlock) mechanism. The load interlock mechanism prevents a thread from using Rails autoloading mechanism to load constants while the application code is still running inside another thread.
6
+
7
+ This issue only occurs in the development environment as Rails' load interlock is not used in production environments. Although we're not sure, we believe this issue may not occur with the new `zeitwerk` code loader.
8
+
9
+ ### Solutions
10
+
11
+
12
+ #### 1. Bypass Rails' load interlock with `.permit_concurrent_loads`
13
+
14
+ Wrap the first request inside a block that will allow concurrent loads, [`ActiveSupport::Dependencies.interlock.permit_concurrent_loads`](https://guides.rubyonrails.org/threading_and_code_execution.html#permit-concurrent-loads). Anything wrapped inside the `.permit_concurrent_loads` block will bypass the load interlock mechanism, allowing new threads to access the Rails environment and boot properly.
15
+
16
+ ###### Example
17
+
18
+ ```ruby
19
+ response = ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
20
+ # Your HTTP request code here. For example:
21
+ Faraday.post url, data: 'foo'
22
+ end
23
+
24
+ do_something_with response
25
+ ```
26
+
27
+ #### 2. Use multiple processes on Puma
28
+
29
+ Alternatively, you may also enable multiple (single-threaded) workers on Puma. By doing so, you are sidestepping the problem by creating multiple processes rather than new threads. However, this workaround is not ideal because debugging tools such as [byebug](https://github.com/deivid-rodriguez/byebug/issues/487) and [pry](https://github.com/pry/pry/issues/2153), work poorly with any multi-process web server.
data/docs/stats.md ADDED
@@ -0,0 +1,142 @@
1
+ ## accessing stats
2
+
3
+ Stats can be accessed in two ways:
4
+
5
+ ### control server
6
+
7
+ `$ pumactl stats` or `GET /stats`
8
+
9
+ [Read more about `pumactl` and the control server in the README.](https://github.com/puma/puma#controlstatus-server).
10
+
11
+ ### Puma.stats
12
+
13
+ `Puma.stats` produces a JSON string. `Puma.stats_hash` produces a ruby hash.
14
+
15
+ #### in single mode
16
+
17
+ Invoke `Puma.stats` anywhere in runtime, e.g. in a rails initializer:
18
+
19
+ ```ruby
20
+ # config/initializers/puma_stats.rb
21
+
22
+ Thread.new do
23
+ loop do
24
+ sleep 30
25
+ puts Puma.stats
26
+ end
27
+ end
28
+ ```
29
+
30
+ #### in cluster mode
31
+
32
+ Invoke `Puma.stats` from the master process
33
+
34
+ ```ruby
35
+ # config/puma.rb
36
+
37
+ before_fork do
38
+ Thread.new do
39
+ loop do
40
+ puts Puma.stats
41
+ sleep 30
42
+ end
43
+ end
44
+ end
45
+ ```
46
+
47
+
48
+ ## Explanation of stats
49
+
50
+ `Puma.stats` returns different information and a different structure depending on if Puma is in single vs cluster mode. There is one top-level attribute that is common to both modes:
51
+
52
+ * started_at: when puma was started
53
+
54
+ ### single mode and individual workers in cluster mode
55
+
56
+ When Puma is run in single mode, these stats ar available at the top level. When Puma is run in cluster mode, these stats are available within the `worker_status` array in a hash labeled `last_status`, in an array of hashes, one hash for each worker.
57
+
58
+ * backlog: requests that are waiting for an available thread to be available. if this is above 0, you need more capacity [always true?]
59
+ * running: how many threads are running
60
+ * pool_capacity: the number of requests that the server is capable of taking right now. For example if the number is 5 then it means there are 5 threads sitting idle ready to take a request. If one request comes in, then the value would be 4 until it finishes processing. If the minimum threads allowed is zero, this number will still have a maximum value of the maximum threads allowed.
61
+ * max_threads: the maximum number of threads puma is configured to spool up per worker
62
+ * requests_count: the number of requests this worker has served since starting
63
+
64
+
65
+ ### cluster mode
66
+
67
+ * phase: which phase of restart the process is in, during [phased restart](https://github.com/puma/puma/blob/master/docs/restart.md)
68
+ * workers: ??
69
+ * booted_workers: how many workers currently running?
70
+ * old_workers: ??
71
+ * worker_status: array of hashes of info for each worker (see below)
72
+
73
+ ### worker status
74
+
75
+ * started_at: when the worker was started
76
+ * pid: the process id of the worker process
77
+ * index: each worker gets a number. if puma is configured to have 3 workers, then this will be 0, 1, or 2
78
+ * booted: if it's done booting [?]
79
+ * last_checkin: Last time the worker responded to the master process' heartbeat check.
80
+ * 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.
81
+
82
+
83
+ ## Examples
84
+
85
+ Here are two example stats hashes produced by `Puma.stats`:
86
+
87
+ ### single
88
+
89
+ ```json
90
+ {
91
+ "started_at": "2021-01-14T07:12:35Z",
92
+ "backlog": 0,
93
+ "running": 5,
94
+ "pool_capacity": 5,
95
+ "max_threads": 5,
96
+ "requests_count": 3
97
+ }
98
+ ```
99
+
100
+ ### cluster
101
+
102
+ ```json
103
+ {
104
+ "started_at": "2021-01-14T07:09:17Z",
105
+ "workers": 2,
106
+ "phase": 0,
107
+ "booted_workers": 2,
108
+ "old_workers": 0,
109
+ "worker_status": [
110
+ {
111
+ "started_at": "2021-01-14T07:09:24Z",
112
+ "pid": 64136,
113
+ "index": 0,
114
+ "phase": 0,
115
+ "booted": true,
116
+ "last_checkin": "2021-01-14T07:11:09Z",
117
+ "last_status": {
118
+ "backlog": 0,
119
+ "running": 5,
120
+ "pool_capacity": 5,
121
+ "max_threads": 5,
122
+ "requests_count": 2
123
+ }
124
+ },
125
+ {
126
+ "started_at": "2021-01-14T07:09:24Z",
127
+ "pid": 64137,
128
+ "index": 1,
129
+ "phase": 0,
130
+ "booted": true,
131
+ "last_checkin": "2021-01-14T07:11:09Z",
132
+ "last_status": {
133
+ "backlog": 0,
134
+ "running": 5,
135
+ "pool_capacity": 5,
136
+ "max_threads": 5,
137
+ "requests_count": 1
138
+ }
139
+ }
140
+ ]
141
+ }
142
+ ```