puma 4.3.3-java → 5.0.0.beta2-java
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 +4 -4
- data/History.md +79 -8
- data/LICENSE +23 -20
- data/README.md +18 -12
- data/docs/architecture.md +3 -3
- data/docs/deployment.md +9 -3
- data/docs/fork_worker.md +31 -0
- data/docs/jungle/README.md +13 -0
- data/{tools → docs}/jungle/rc.d/README.md +0 -0
- data/{tools → docs}/jungle/rc.d/puma +0 -0
- data/{tools → docs}/jungle/rc.d/puma.conf +0 -0
- data/{tools → docs}/jungle/upstart/README.md +0 -0
- data/{tools → docs}/jungle/upstart/puma-manager.conf +0 -0
- data/{tools → docs}/jungle/upstart/puma.conf +0 -0
- data/docs/signals.md +5 -4
- data/docs/systemd.md +1 -63
- data/ext/puma_http11/PumaHttp11Service.java +2 -4
- data/ext/puma_http11/extconf.rb +4 -3
- data/ext/puma_http11/http11_parser.c +3 -1
- data/ext/puma_http11/http11_parser.rl +3 -1
- data/ext/puma_http11/mini_ssl.c +12 -2
- data/ext/puma_http11/org/jruby/puma/Http11.java +3 -3
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +37 -6
- data/ext/puma_http11/puma_http11.c +3 -38
- data/lib/puma.rb +5 -0
- data/lib/puma/app/status.rb +18 -3
- data/lib/puma/binder.rb +66 -63
- data/lib/puma/cli.rb +7 -15
- data/lib/puma/client.rb +64 -14
- data/lib/puma/cluster.rb +183 -74
- data/lib/puma/commonlogger.rb +2 -2
- data/lib/puma/configuration.rb +30 -42
- data/lib/puma/const.rb +2 -3
- data/lib/puma/control_cli.rb +27 -17
- data/lib/puma/detect.rb +8 -0
- data/lib/puma/dsl.rb +72 -36
- data/lib/puma/error_logger.rb +96 -0
- data/lib/puma/events.rb +33 -31
- data/lib/puma/io_buffer.rb +9 -2
- data/lib/puma/jruby_restart.rb +0 -58
- data/lib/puma/launcher.rb +46 -31
- data/lib/puma/minissl.rb +47 -10
- data/lib/puma/null_io.rb +1 -1
- data/lib/puma/plugin.rb +1 -10
- data/lib/puma/puma_http11.jar +0 -0
- data/lib/puma/rack/builder.rb +0 -4
- data/lib/puma/reactor.rb +8 -3
- data/lib/puma/runner.rb +6 -35
- data/lib/puma/server.rb +138 -182
- data/lib/puma/single.rb +7 -64
- data/lib/puma/state_file.rb +6 -3
- data/lib/puma/thread_pool.rb +90 -49
- data/lib/rack/handler/puma.rb +1 -3
- data/tools/{docker/Dockerfile → Dockerfile} +0 -0
- metadata +18 -21
- data/docs/tcp_mode.md +0 -96
- data/ext/puma_http11/io_buffer.c +0 -155
- data/ext/puma_http11/org/jruby/puma/IOBuffer.java +0 -72
- data/lib/puma/tcp_logger.rb +0 -41
- data/tools/jungle/README.md +0 -19
- data/tools/jungle/init.d/README.md +0 -61
- data/tools/jungle/init.d/puma +0 -421
- data/tools/jungle/init.d/run-puma +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a07b62e45c13573cba434caa78d336c981104d65448bf2cba63cc7fe87ebe5
|
4
|
+
data.tar.gz: d05d3e5a89a5dec3f71a133024d596975bb5fb0a8b4e2a8c0342479f061132fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18498ab4e516ea2b386a8515c5ced3f2f5572e72f6281c87433f24f69b0ad94b55db2466a8f77df24b611c054353641ecce50b397b9cd698370bf81e3ba66369
|
7
|
+
data.tar.gz: 82efab2a81aebbd2eb50de04f906bb5f607f83121fe484f31feacd09cd481433d3f008278e8dcaf844a9b8ed3915e5985fa1a11fcf6d4f556eef24c87e9c6b3d
|
data/History.md
CHANGED
@@ -1,19 +1,90 @@
|
|
1
|
-
##
|
1
|
+
## 5.0.0
|
2
2
|
|
3
3
|
* Features
|
4
|
-
*
|
4
|
+
* EXPERIMENTAL: Add `fork_worker` option and `refork` command for reduced memory usage by forking from a worker process instead of the master process. (#2099)
|
5
|
+
* EXPERIMENTAL: Added `wait_for_less_busy_worker` config. This may reduce latency on MRI through inserting a small delay before re-listening on the socket if worker is busy (#2079).
|
6
|
+
* EXPERIMENTAL: Added `nakayoshi_fork` option. Reduce memory usage in preloaded cluster-mode apps by GCing before fork and compacting, where available. (#2093, #2256)
|
7
|
+
* Added pumactl `thread-backtraces` command to print thread backtraces (#2054)
|
8
|
+
* Added incrementing `requests_count` to `Puma.stats`. (#2106)
|
9
|
+
* Increased maximum URI path length from 2048 to 8192 bytes (#2167, #2344)
|
10
|
+
* `lowlevel_error_handler` is now called during a forced threadpool shutdown, and if a callable with 3 arguments is set, we now also pass the status code (#2203)
|
11
|
+
* Faster phased restart and worker timeout (#2220)
|
12
|
+
* Added `state_permission` to config DSL to set state file permissions (#2238)
|
13
|
+
* Added `Puma.stats_hash`, which returns a stats in Hash instead of a JSON string (#2086, #2253)
|
14
|
+
* `rack.multithread` and `rack.multiprocess` now dynamically resolved by `max_thread` and `workers` respectively (#2288)
|
15
|
+
|
16
|
+
* Deprecations, Removals and Breaking API Changes
|
17
|
+
* `--control` has been removed. Use `--control-url` (#1487)
|
18
|
+
* `worker_directory` has been removed. Use `directory`.
|
19
|
+
* min_threads now set by environment variables PUMA_MIN_THREADS and MIN_THREADS. (#2143)
|
20
|
+
* max_threads now set by environment variables PUMA_MAX_THREADS and MAX_THREADS. (#2143)
|
21
|
+
* max_threads default to 5 in MRI or 16 for all other interpreters. (#2143)
|
22
|
+
* preload by default if workers > 1 (#2143)
|
23
|
+
* Puma::Plugin.workers_supported? has been removed. Use Puma.forkable? instead. (#2143)
|
24
|
+
* `tcp_mode` has been removed without replacement. (#2169)
|
25
|
+
* Daemonization has been removed without replacement. (#2170)
|
26
|
+
* Changed #connected_port to #connected_ports (#2076)
|
27
|
+
* Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022)
|
28
|
+
* Log binding on http:// for TCP bindings to make it clickable
|
5
29
|
|
6
30
|
* Bugfixes
|
7
|
-
*
|
31
|
+
* Fix JSON loading issues on phased-restarts (#2269)
|
32
|
+
* Improve shutdown reliability (#2312, #2338)
|
33
|
+
* Close client http connections made to an ssl server with TLSv1.3 (#2116)
|
34
|
+
* Do not set user_config to quiet by default to allow for file config (#2074)
|
35
|
+
* Always close SSL connection in Puma::ControlCLI (#2211)
|
36
|
+
* Windows update extconf.rb for use with ssp and varied Ruby/MSYS2 combinations (#2069)
|
37
|
+
* Ensure control server Unix socket is closed on shutdown (#2112)
|
38
|
+
* Preserve `BUNDLE_GEMFILE` env var when using `prune_bundler` (#1893)
|
39
|
+
* Send 408 request timeout even when queue requests is disabled (#2119)
|
40
|
+
* Rescue IO::WaitReadable instead of EAGAIN for blocking read (#2121)
|
41
|
+
* Ensure `BUNDLE_GEMFILE` is unspecified in workers if unspecified in master when using `prune_bundler` (#2154)
|
42
|
+
* Rescue and log exceptions in hooks defined by users (on_worker_boot, after_worker_fork etc) (#1551)
|
43
|
+
* Read directly from the socket in #read_and_drop to avoid raising further SSL errors (#2198)
|
44
|
+
* Set `Connection: closed` header when queue requests is disabled (#2216)
|
45
|
+
* Pass queued requests to thread pool on server shutdown (#2122)
|
46
|
+
* Fixed a few minor concurrency bugs in ThreadPool that may have affected non-GVL Rubies (#2220)
|
47
|
+
* Fix `out_of_band` hook never executed if the number of worker threads is > 1 (#2177)
|
48
|
+
* Fix ThreadPool#shutdown timeout accuracy (#2221)
|
49
|
+
* Fix `UserFileDefaultOptions#fetch` to properly use `default` (#2233)
|
50
|
+
* Improvements to `out_of_band` hook (#2234)
|
51
|
+
* Prefer the rackup file specified by the CLI (#2225)
|
52
|
+
* Fix for spawning subprocesses with fork_worker option (#2267)
|
53
|
+
* Set `CONTENT_LENGTH` for chunked requests (#2287)
|
54
|
+
* JRuby - Add Puma::MiniSSL::Engine#init? and #teardown methods, run all SSL tests (#2317)
|
55
|
+
* Improve shutdown reliability (#2312)
|
56
|
+
* Resolve issue with threadpool waiting counter decrement when thread is killed
|
57
|
+
* Constrain rake-compiler version to 0.9.4 to fix `ClassNotFound` exception when using MiniSSL with Java8.
|
58
|
+
* Fix recursive `prune_bundler` (#2319).
|
59
|
+
* Ensure that TCP_CORK is usable
|
60
|
+
* Fix corner case when request body is chunked (#2326)
|
61
|
+
|
62
|
+
* Refactor
|
63
|
+
* Remove unused loader argument from Plugin initializer (#2095)
|
64
|
+
* Simplify `Configuration.random_token` and remove insecure fallback (#2102)
|
65
|
+
* Simplify `Runner#start_control` URL parsing (#2111)
|
66
|
+
* Removed the IOBuffer extension and replaced with Ruby (#1980)
|
67
|
+
* Update `Rack::Handler::Puma.run` to use `**options` (#2189)
|
68
|
+
* ThreadPool concurrency refactoring (#2220)
|
69
|
+
* JSON parse cluster worker stats instead of regex (#2124)
|
70
|
+
* Support parallel tests in verbose progress reporting (#2223)
|
71
|
+
* Refactor error handling in server accept loop (#2239)
|
72
|
+
|
73
|
+
## 4.3.4/4.3.5 and 3.12.5/3.12.6 / 2020-05-22
|
74
|
+
|
75
|
+
Each patchlevel release contains a separate security fix. We recommend simply upgrading to 4.3.5/3.12.6.
|
8
76
|
|
77
|
+
* Security
|
78
|
+
* Fix: Fixed two separate HTTP smuggling vulnerabilities that used the Transfer-Encoding header. CVE-2020-11076 and CVE-2020-11077.
|
9
79
|
|
10
80
|
## 4.3.3 and 3.12.4 / 2020-02-28
|
11
|
-
* Bugfixes
|
12
|
-
* Fix: Fixes a problem where we weren't splitting headers correctly on newlines (#2132)
|
13
|
-
* Security
|
14
|
-
* Fix: Prevent HTTP Response splitting via CR in early hints.
|
15
81
|
|
16
|
-
|
82
|
+
* Bugfixes
|
83
|
+
* Fix: Fixes a problem where we weren't splitting headers correctly on newlines (#2132)
|
84
|
+
* Security
|
85
|
+
* Fix: Prevent HTTP Response splitting via CR in early hints. CVE-2020-5249.
|
86
|
+
|
87
|
+
## 4.3.2 and 3.12.3 / 2020-02-27 (YANKED)
|
17
88
|
|
18
89
|
* Security
|
19
90
|
* Fix: Prevent HTTP Response splitting via CR/LF in header values. CVE-2020-5247.
|
data/LICENSE
CHANGED
@@ -1,26 +1,29 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2019, Evan Phoenix. Some code by Zed Shaw, (c) 2005.
|
3
4
|
All rights reserved.
|
4
5
|
|
5
|
-
Redistribution and use in source and binary forms, with or without
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
6
7
|
modification, are permitted provided that the following conditions are met:
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
16
19
|
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
21
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
29
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
@@ -4,12 +4,11 @@
|
|
4
4
|
|
5
5
|
# Puma: A Ruby Web Server Built For Concurrency
|
6
6
|
|
7
|
-
[![
|
8
|
-
[![Actions Build Status](https://github.com/puma/puma/workflows/Puma/badge.svg)](https://github.com/puma/puma/actions)
|
9
|
-
[![Travis Build Status](https://travis-ci.org/puma/puma.svg?branch=master)](https://travis-ci.org/puma/puma)
|
7
|
+
[![Actions Build Status](https://github.com/puma/puma/workflows/CI/badge.svg?branch=master)](https://github.com/puma/puma/actions)
|
10
8
|
|
11
9
|
[![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
|
12
10
|
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=puma&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=puma&package-manager=bundler&version-scheme=semver)
|
11
|
+
[![StackOverflow](https://img.shields.io/badge/stackoverflow-Puma-blue.svg)]( https://stackoverflow.com/questions/tagged/puma )
|
13
12
|
|
14
13
|
Puma is a **simple, fast, multi-threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications**.
|
15
14
|
|
@@ -28,7 +27,8 @@ $ gem install puma
|
|
28
27
|
$ puma
|
29
28
|
```
|
30
29
|
|
31
|
-
Without arguments, puma will look for a rackup (.ru) file in
|
30
|
+
Without arguments, puma will look for a rackup (.ru) file in
|
31
|
+
working directory called `config.ru`.
|
32
32
|
|
33
33
|
## Frameworks
|
34
34
|
|
@@ -68,7 +68,7 @@ configure { set :server, :puma }
|
|
68
68
|
Puma provides numerous options. Consult `puma -h` (or `puma --help`) for a full list of CLI options, or see [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb).
|
69
69
|
|
70
70
|
You can also find several configuration examples as part of the
|
71
|
-
[test](test/config) suite.
|
71
|
+
[test](https://github.com/puma/puma/tree/master/test/config) suite.
|
72
72
|
|
73
73
|
### Thread Pool
|
74
74
|
|
@@ -78,7 +78,7 @@ Puma uses a thread pool. You can set the minimum and maximum number of threads t
|
|
78
78
|
$ puma -t 8:32
|
79
79
|
```
|
80
80
|
|
81
|
-
Puma will automatically scale the number of threads, from the minimum until it caps out at the maximum, based on how much traffic is present. The current default is `0:16`. Feel free to experiment, but be careful not to set the number of maximum threads to a large number, as you may exhaust resources on the system (or cause contention for the Global VM Lock, when using MRI).
|
81
|
+
Puma will automatically scale the number of threads, from the minimum until it caps out at the maximum, based on how much traffic is present. The current default is `0:16` and on MRI is `0:5`. Feel free to experiment, but be careful not to set the number of maximum threads to a large number, as you may exhaust resources on the system (or cause contention for the Global VM Lock, when using MRI).
|
82
82
|
|
83
83
|
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.
|
84
84
|
|
@@ -135,7 +135,7 @@ Preloading can’t be used with phased restart, since phased restart kills and r
|
|
135
135
|
If puma encounters an error outside of the context of your application, it will respond with a 500 and a simple
|
136
136
|
textual error message (see `lowlevel_error` in [this file](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
|
137
137
|
You can specify custom behavior for this scenario. For example, you can report the error to your third-party
|
138
|
-
error-tracking service (in this example, [rollbar](
|
138
|
+
error-tracking service (in this example, [rollbar](https://rollbar.com)):
|
139
139
|
|
140
140
|
```ruby
|
141
141
|
lowlevel_error_handler do |e|
|
@@ -220,7 +220,7 @@ You can also provide a configuration file with the `-C` (or `--config`) flag:
|
|
220
220
|
$ puma -C /path/to/config
|
221
221
|
```
|
222
222
|
|
223
|
-
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` environment
|
223
|
+
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`.
|
224
224
|
|
225
225
|
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:
|
226
226
|
|
@@ -251,7 +251,7 @@ Some platforms do not support all Puma features.
|
|
251
251
|
|
252
252
|
## Known Bugs
|
253
253
|
|
254
|
-
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:
|
254
|
+
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:
|
255
255
|
|
256
256
|
```ruby
|
257
257
|
if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
|
@@ -270,16 +270,22 @@ It is common to use process monitors with Puma. Modern process monitors like sys
|
|
270
270
|
provide continuous monitoring and restarts for increased
|
271
271
|
reliability in production environments:
|
272
272
|
|
273
|
-
* [
|
273
|
+
* [docs/jungle](https://github.com/puma/puma/tree/master/docs/jungle) for rc.d and upstart
|
274
274
|
* [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
|
275
275
|
|
276
|
-
## Community
|
276
|
+
## Community Extensions
|
277
277
|
|
278
|
-
|
278
|
+
### Plugins
|
279
|
+
|
280
|
+
* [puma-heroku](https://github.com/puma/puma-heroku) — default Puma configuration for running on Heroku
|
279
281
|
* [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
|
280
282
|
* [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
|
281
283
|
* [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog
|
282
284
|
|
285
|
+
### Monitoring
|
286
|
+
|
287
|
+
* [puma-status](https://github.com/ylecuyer/puma-status) — Monitor CPU/Mem/Load of running puma instances from the CLI
|
288
|
+
|
283
289
|
## Contributing
|
284
290
|
|
285
291
|
Find details for contributing in the [contribution guide].
|
data/docs/architecture.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
|
5
|
-
![
|
5
|
+
![https://bit.ly/2iJuFky](images/puma-general-arch.png)
|
6
6
|
|
7
7
|
Puma is a threaded web server, processing requests across a TCP or UNIX socket.
|
8
8
|
|
@@ -12,7 +12,7 @@ Clustered mode is shown/discussed here. Single mode is analogous to having a sin
|
|
12
12
|
|
13
13
|
## Connection pipeline
|
14
14
|
|
15
|
-
![
|
15
|
+
![https://bit.ly/2zwzhEK](images/puma-connection-flow.png)
|
16
16
|
|
17
17
|
* Upon startup, Puma listens on a TCP or UNIX socket.
|
18
18
|
* The backlog of this socket is configured (with a default of 1024), determining how many established but unaccepted connections can exist concurrently.
|
@@ -29,7 +29,7 @@ Clustered mode is shown/discussed here. Single mode is analogous to having a sin
|
|
29
29
|
|
30
30
|
### Disabling `queue_requests`
|
31
31
|
|
32
|
-
![
|
32
|
+
![https://bit.ly/2zxCJ1Z](images/puma-connection-flow-no-reactor.png)
|
33
33
|
|
34
34
|
The `queue_requests` option is `true` by default, enabling the separate thread used to buffer requests as described above.
|
35
35
|
|
data/docs/deployment.md
CHANGED
@@ -20,7 +20,10 @@ Welcome back!
|
|
20
20
|
Puma was originally conceived as a thread-only webserver, but grew the ability to
|
21
21
|
also use processes in version 2.
|
22
22
|
|
23
|
-
|
23
|
+
To run puma in single mode (e.g. for a development environment) you will need to
|
24
|
+
set the number of workers to 0, anything above will run in cluster mode.
|
25
|
+
|
26
|
+
Here are some rules of thumb for cluster mode:
|
24
27
|
|
25
28
|
### MRI
|
26
29
|
|
@@ -66,7 +69,8 @@ thread to become available.
|
|
66
69
|
|
67
70
|
* Have your upstream proxy set a header with the time it received the request:
|
68
71
|
* nginx: `proxy_set_header X-Request-Start "${msec}";`
|
69
|
-
* haproxy: `http-request set-header X-Request-Start
|
72
|
+
* haproxy >= 1.9: `http-request set-header X-Request-Start t=%[date()]%[date_us()]`
|
73
|
+
* haproxy < 1.9: `http-request set-header X-Request-Start t=%[date()]`
|
70
74
|
* In your Rack middleware, determine the amount of time elapsed since `X-Request-Start`.
|
71
75
|
* To improve accuracy, you will want to subtract time spent waiting for slow clients:
|
72
76
|
* `env['puma.request_body_wait']` contains the number of milliseconds Puma spent
|
@@ -74,7 +78,9 @@ thread to become available.
|
|
74
78
|
* haproxy: `%Th` (TLS handshake time) and `%Ti` (idle time before request) can
|
75
79
|
can also be added as headers.
|
76
80
|
|
77
|
-
##
|
81
|
+
## Should I daemonize?
|
82
|
+
|
83
|
+
Daemonization was removed in Puma 5.0. For alternatives, continue reading.
|
78
84
|
|
79
85
|
I prefer to not daemonize my servers and use something like `runit` or `upstart` to
|
80
86
|
monitor them as child processes. This gives them fast response to crashes and
|
data/docs/fork_worker.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Fork-Worker Cluster Mode [Experimental]
|
2
|
+
|
3
|
+
Puma 5 introduces an experimental new cluster-mode configuration option, `fork_worker` (`--fork-worker` from the CLI). This mode causes Puma to fork additional workers from worker 0, instead of directly from the master process:
|
4
|
+
|
5
|
+
```
|
6
|
+
10000 \_ puma 4.3.3 (tcp://0.0.0.0:9292) [puma]
|
7
|
+
10001 \_ puma: cluster worker 0: 10000 [puma]
|
8
|
+
10002 \_ puma: cluster worker 1: 10000 [puma]
|
9
|
+
10003 \_ puma: cluster worker 2: 10000 [puma]
|
10
|
+
10004 \_ puma: cluster worker 3: 10000 [puma]
|
11
|
+
```
|
12
|
+
|
13
|
+
Similar to the `preload_app!` option, the `fork_worker` option allows your application to be initialized only once for copy-on-write memory savings, and it has two additional advantages:
|
14
|
+
|
15
|
+
1. **Compatible with phased restart.** Because the master process itself doesn't preload the application, this mode works with phased restart (`SIGUSR1` or `pumactl phased-restart`). When worker 0 reloads as part of a phased restart, it initializes a new copy of your application first, then the other workers reload by forking from this new worker already containing the new preloaded application.
|
16
|
+
|
17
|
+
This allows a phased restart to complete as quickly as a hot restart (`SIGUSR2` or `pumactl restart`), while still minimizing downtime by staggering the restart across cluster workers.
|
18
|
+
|
19
|
+
2. **'Refork' for additional copy-on-write improvements in running applications.** Fork-worker mode introduces a new `refork` command that re-loads all nonzero workers by re-forking them from worker 0.
|
20
|
+
|
21
|
+
This command can potentially improve memory utilization in large or complex applications that don't fully pre-initialize on startup, because the re-forked workers can share copy-on-write memory with a worker that has been running for a while and serving requests.
|
22
|
+
|
23
|
+
You can trigger a refork by sending the cluster the `SIGURG` signal or running the `pumactl refork` command at any time. A refork will also automatically trigger once, after a certain number of requests have been processed by worker 0 (default 1000). To configure the number of requests before the auto-refork, pass a positive integer argument to `fork_worker` (e.g., `fork_worker 1000`), or `0` to disable.
|
24
|
+
|
25
|
+
### Limitations
|
26
|
+
|
27
|
+
- This mode is still very experimental so there may be bugs or edge-cases, particularly around expected behavior of existing hooks. Please open a [bug report](https://github.com/puma/puma/issues/new?template=bug_report.md) if you encounter any issues.
|
28
|
+
|
29
|
+
- In order to fork new workers cleanly, worker 0 shuts down its server and stops serving requests so there are no open file descriptors or other kinds of shared global state between processes, and to maximize copy-on-write efficiency across the newly-forked workers. This may temporarily reduce total capacity of the cluster during a phased restart / refork.
|
30
|
+
|
31
|
+
In a cluster with `n` workers, a normal phased restart stops and restarts workers one by one while the application is loaded in each process, so `n-1` workers are available serving requests during the restart. In a phased restart in fork-worker mode, the application is first loaded in worker 0 while `n-1` workers are available, then worker 0 remains stopped while the rest of the workers are reloaded one by one, leaving only `n-2` workers to be available for a brief period of time. Reloading the rest of the workers should be quick because the application is preloaded at that point, but there may be situations where it can take longer (slow clients, long-running application code, slow worker-fork hooks, etc).
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Puma as a service
|
2
|
+
|
3
|
+
## Upstart
|
4
|
+
|
5
|
+
See `/docs/jungle/upstart` for Ubuntu's upstart scripts.
|
6
|
+
|
7
|
+
## Systemd
|
8
|
+
|
9
|
+
See [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md).
|
10
|
+
|
11
|
+
## rc.d
|
12
|
+
|
13
|
+
See `/docs/jungle/rc.d` for FreeBSD's rc.d scripts
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/docs/signals.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
The [unix signal](
|
1
|
+
The [unix signal](https://en.wikipedia.org/wiki/Unix_signal) is a method of sending messages between [processes](https://en.wikipedia.org/wiki/Process_(computing)). When a signal is sent, the operating system interrupts the target process's normal flow of execution. There are standard signals that are used to stop a process but there are also custom signals that can be used for other purposes. This document is an attempt to list all supported signals that Puma will respond to. In general, signals need only be sent to the master process of a cluster.
|
2
2
|
|
3
3
|
## Sending Signals
|
4
4
|
|
5
|
-
If you are new to signals it can be useful to see how they can be used. When a process is created in a *nix like operating system it will have a [PID - or process identifier](
|
5
|
+
If you are new to signals it can be useful to see how they can be used. When a process is created in a *nix like operating system it will have a [PID - or process identifier](https://en.wikipedia.org/wiki/Process_identifier) that can be used to send signals to the process. For demonstration we will create an infinitely running process by tailing a file:
|
6
6
|
|
7
7
|
```sh
|
8
8
|
$ echo "foo" >> my.log
|
@@ -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](
|
20
|
+
You can send a signal in Ruby using the [Process module](https://www.ruby-doc.org/core-2.1.1/Process.html#kill-method):
|
21
21
|
|
22
22
|
```
|
23
23
|
$ irb
|
24
24
|
> puts pid
|
25
25
|
=> 87152
|
26
|
-
Process.detach(pid) #
|
26
|
+
Process.detach(pid) # https://ruby-doc.org/core-2.1.1/Process.html#method-c-detach
|
27
27
|
Process.kill("TERM", pid)
|
28
28
|
```
|
29
29
|
|
@@ -41,6 +41,7 @@ Puma cluster responds to these signals:
|
|
41
41
|
- `HUP` reopen log files defined in stdout_redirect configuration parameter. If there is no stdout_redirect option provided it will behave like `INT`
|
42
42
|
- `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
|
43
43
|
- `CHLD`
|
44
|
+
- `URG` refork workers in phases from worker 0, if `fork_workers` option is enabled.
|
44
45
|
|
45
46
|
## Callbacks order in case of different signals
|
46
47
|
|
data/docs/systemd.md
CHANGED
@@ -13,9 +13,7 @@ desired, using an application or instance specific name.
|
|
13
13
|
|
14
14
|
Note that this uses the systemd preferred "simple" type where the
|
15
15
|
start command remains running in the foreground (does not fork and
|
16
|
-
exit).
|
17
|
-
[Alternative Forking Configuration](#alternative-forking-configuration)
|
18
|
-
below.
|
16
|
+
exit).
|
19
17
|
|
20
18
|
~~~~ ini
|
21
19
|
[Unit]
|
@@ -209,66 +207,6 @@ Apr 07 08:40:19 hx puma[28320]: * Activated ssl://0.0.0.0:9234?key=key.pem&cert=
|
|
209
207
|
Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
|
210
208
|
~~~~
|
211
209
|
|
212
|
-
## Alternative Forking Configuration
|
213
|
-
|
214
|
-
Other systems/tools might expect or need puma to be run as a
|
215
|
-
"traditional" forking server, for example so that the `pumactl`
|
216
|
-
command can be used directly and outside of systemd for
|
217
|
-
stop/start/restart. This use case is incompatible with systemd socket
|
218
|
-
activation, so it should not be configured. Below is an alternative
|
219
|
-
puma.service config sample, using `Type=forking` and the `--daemon`
|
220
|
-
flag in `ExecStart`. Here systemd is playing a role more equivalent to
|
221
|
-
SysV init.d, where it is responsible for starting Puma on boot
|
222
|
-
(multi-user.target) and stopping it on shutdown, but is not performing
|
223
|
-
continuous restarts. Therefore running Puma in cluster mode, where the
|
224
|
-
master can restart workers, is highly recommended. See the systemd
|
225
|
-
[Restart] directive for details.
|
226
|
-
|
227
|
-
~~~~ ini
|
228
|
-
[Unit]
|
229
|
-
Description=Puma HTTP Forking Server
|
230
|
-
After=network.target
|
231
|
-
|
232
|
-
[Service]
|
233
|
-
# Background process configuration (use with --daemon in ExecStart)
|
234
|
-
Type=forking
|
235
|
-
|
236
|
-
# Preferably configure a non-privileged user
|
237
|
-
# User=
|
238
|
-
|
239
|
-
# The path to the puma application root
|
240
|
-
# Also replace the "<WD>" place holders below with this path.
|
241
|
-
WorkingDirectory=
|
242
|
-
|
243
|
-
# The command to start Puma
|
244
|
-
# (replace "<WD>" below)
|
245
|
-
ExecStart=bundle exec puma -C <WD>/shared/puma.rb --daemon
|
246
|
-
|
247
|
-
# The command to stop Puma
|
248
|
-
# (replace "<WD>" below)
|
249
|
-
ExecStop=bundle exec pumactl -S <WD>/shared/tmp/pids/puma.state stop
|
250
|
-
|
251
|
-
# Path to PID file so that systemd knows which is the master process
|
252
|
-
PIDFile=<WD>/shared/tmp/pids/puma.pid
|
253
|
-
|
254
|
-
# Should systemd restart puma?
|
255
|
-
# Use "no" (the default) to ensure no interference when using
|
256
|
-
# stop/start/restart via `pumactl`. The "on-failure" setting might
|
257
|
-
# work better for this purpose, but you must test it.
|
258
|
-
# Use "always" if only `systemctl` is used for start/stop/restart, and
|
259
|
-
# reconsider if you actually need the forking config.
|
260
|
-
Restart=no
|
261
|
-
|
262
|
-
# `puma_ctl restart` wouldn't work without this. It's because `pumactl`
|
263
|
-
# changes PID on restart and systemd stops the service afterwards
|
264
|
-
# because of the PID change. This option prevents stopping after PID
|
265
|
-
# change.
|
266
|
-
RemainAfterExit=yes
|
267
|
-
|
268
|
-
[Install]
|
269
|
-
WantedBy=multi-user.target
|
270
|
-
~~~~
|
271
|
-
|
272
210
|
### capistrano3-puma
|
273
211
|
|
274
212
|
By default,
|