puma 5.2.2 → 6.3.0

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.

Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +483 -4
  3. data/README.md +101 -20
  4. data/bin/puma-wild +1 -1
  5. data/docs/architecture.md +50 -16
  6. data/docs/compile_options.md +38 -2
  7. data/docs/deployment.md +53 -67
  8. data/docs/fork_worker.md +1 -3
  9. data/docs/jungle/rc.d/README.md +1 -1
  10. data/docs/kubernetes.md +1 -1
  11. data/docs/nginx.md +1 -1
  12. data/docs/plugins.md +15 -15
  13. data/docs/rails_dev_mode.md +2 -3
  14. data/docs/restart.md +7 -7
  15. data/docs/signals.md +11 -10
  16. data/docs/stats.md +8 -8
  17. data/docs/systemd.md +65 -69
  18. data/docs/testing_benchmarks_local_files.md +150 -0
  19. data/docs/testing_test_rackup_ci_files.md +36 -0
  20. data/ext/puma_http11/extconf.rb +44 -13
  21. data/ext/puma_http11/http11_parser.c +24 -11
  22. data/ext/puma_http11/http11_parser.h +2 -2
  23. data/ext/puma_http11/http11_parser.java.rl +2 -2
  24. data/ext/puma_http11/http11_parser.rl +2 -2
  25. data/ext/puma_http11/http11_parser_common.rl +3 -3
  26. data/ext/puma_http11/mini_ssl.c +150 -23
  27. data/ext/puma_http11/org/jruby/puma/Http11.java +3 -3
  28. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +50 -48
  29. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +188 -102
  30. data/ext/puma_http11/puma_http11.c +18 -10
  31. data/lib/puma/app/status.rb +10 -7
  32. data/lib/puma/binder.rb +112 -62
  33. data/lib/puma/cli.rb +24 -20
  34. data/lib/puma/client.rb +162 -36
  35. data/lib/puma/cluster/worker.rb +31 -27
  36. data/lib/puma/cluster/worker_handle.rb +12 -1
  37. data/lib/puma/cluster.rb +102 -61
  38. data/lib/puma/commonlogger.rb +21 -14
  39. data/lib/puma/configuration.rb +78 -54
  40. data/lib/puma/const.rb +135 -97
  41. data/lib/puma/control_cli.rb +25 -20
  42. data/lib/puma/detect.rb +12 -2
  43. data/lib/puma/dsl.rb +308 -58
  44. data/lib/puma/error_logger.rb +20 -11
  45. data/lib/puma/events.rb +6 -126
  46. data/lib/puma/io_buffer.rb +39 -4
  47. data/lib/puma/jruby_restart.rb +2 -1
  48. data/lib/puma/{json.rb → json_serialization.rb} +1 -1
  49. data/lib/puma/launcher/bundle_pruner.rb +104 -0
  50. data/lib/puma/launcher.rb +114 -173
  51. data/lib/puma/log_writer.rb +147 -0
  52. data/lib/puma/minissl/context_builder.rb +30 -16
  53. data/lib/puma/minissl.rb +132 -38
  54. data/lib/puma/null_io.rb +5 -0
  55. data/lib/puma/plugin/systemd.rb +90 -0
  56. data/lib/puma/plugin/tmp_restart.rb +1 -1
  57. data/lib/puma/plugin.rb +2 -2
  58. data/lib/puma/rack/builder.rb +7 -7
  59. data/lib/puma/rack_default.rb +19 -4
  60. data/lib/puma/reactor.rb +19 -10
  61. data/lib/puma/request.rb +373 -153
  62. data/lib/puma/runner.rb +74 -28
  63. data/lib/puma/sd_notify.rb +149 -0
  64. data/lib/puma/server.rb +127 -136
  65. data/lib/puma/single.rb +13 -11
  66. data/lib/puma/state_file.rb +39 -7
  67. data/lib/puma/thread_pool.rb +33 -26
  68. data/lib/puma/util.rb +20 -15
  69. data/lib/puma.rb +28 -11
  70. data/lib/rack/handler/puma.rb +113 -86
  71. data/tools/Dockerfile +1 -1
  72. metadata +15 -10
  73. data/lib/puma/queue_close.rb +0 -26
  74. data/lib/puma/systemd.rb +0 -46
data/docs/plugins.md CHANGED
@@ -3,22 +3,22 @@
3
3
  Puma 3.0 added support for plugins that can augment configuration and service
4
4
  operations.
5
5
 
6
- 2 canonical plugins to look to aid in development of further plugins:
6
+ There are two canonical plugins to aid in the development of new plugins:
7
7
 
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 (being sunset with the release of Puma 5.0)
11
+ Packages up the default configuration used by Puma on Heroku (being sunset
12
+ with the release of Puma 5.0)
12
13
 
13
- Plugins are activated in a puma configuration file (such as `config/puma.rb'`)
14
+ Plugins are activated in a Puma configuration file (such as `config/puma.rb'`)
14
15
  by adding `plugin "name"`, such as `plugin "heroku"`.
15
16
 
16
- Plugins are activated based simply on path requirements so, activating the
17
- `heroku` plugin will simply be doing `require "puma/plugin/heroku"`. This
18
- allows gems to provide multiple plugins (as well as unrelated gems to provide
19
- puma plugins).
17
+ Plugins are activated based on path requirements so, activating the `heroku`
18
+ plugin is much like `require "puma/plugin/heroku"`. This allows gems to provide
19
+ multiple plugins (as well as unrelated gems to provide Puma plugins).
20
20
 
21
- The `tmp_restart` plugin is bundled with puma, so it can always be used.
21
+ The `tmp_restart` plugin comes with Puma, so it is always available.
22
22
 
23
23
  To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
24
24
 
@@ -26,13 +26,13 @@ To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
26
26
 
27
27
  ## Server-wide hooks
28
28
 
29
- Plugins can use a couple of hooks at server level: `start` and `config`.
29
+ Plugins can use a couple of hooks at the server level: `start` and `config`.
30
30
 
31
- `start` runs when the server has started and allows the plugin to start other
32
- functionality to augment puma.
31
+ `start` runs when the server has started and allows the plugin to initiate other
32
+ functionality to augment Puma.
33
33
 
34
- `config` runs when the server is being configured and is passed a `Puma::DSL`
35
- object that can be used to add additional configuration.
34
+ `config` runs when the server is being configured and receives a `Puma::DSL`
35
+ object that is useful for additional configuration.
36
36
 
37
- Any public methods in `Puma::Plugin` are the public API that any plugin may
38
- use.
37
+ Public methods in [`Puma::Plugin`](../lib/puma/plugin.rb) are treated as a
38
+ public API for plugins.
@@ -2,16 +2,15 @@
2
2
 
3
3
  ## "Loopback requests"
4
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.
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 completes. 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
6
 
7
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
8
 
9
9
  ### Solutions
10
10
 
11
-
12
11
  #### 1. Bypass Rails' load interlock with `.permit_concurrent_loads`
13
12
 
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.
13
+ 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
14
 
16
15
  ###### Example
17
16
 
data/docs/restart.md CHANGED
@@ -1,8 +1,8 @@
1
- Puma provides three distinct kinds of restart operations, each for different use cases. Hot restarts and phased restarts are described here. The third kind of restart operation is called "refork" and is described in the documentation for [`fork_worker`](fork_worker.md).
1
+ Puma provides three distinct kinds of restart operations, each for different use cases. This document describes "hot restarts" and "phased restarts." The third kind of restart operation is called "refork" and is described in the documentation for [`fork_worker`](fork_worker.md).
2
2
 
3
3
  ## Hot restart
4
4
 
5
- To perform a "hot" restart, Puma performs an `exec` operation to start the process up again, so no memory is shared between the old process and the new process. As a result, it is safe to issue a restart any place where you would manually stop Puma and start it again. In particular, it is safe to upgrade Puma itself using a hot restart.
5
+ To perform a "hot" restart, Puma performs an `exec` operation to start the process up again, so no memory is shared between the old process and the new process. As a result, it is safe to issue a restart at any place where you would manually stop Puma and start it again. In particular, it is safe to upgrade Puma itself using a hot restart.
6
6
 
7
7
  If the new process is unable to load, it will simply exit. You should therefore run Puma under a process monitor when using it in production.
8
8
 
@@ -16,14 +16,14 @@ Any of the following will cause a Puma server to perform a hot restart:
16
16
 
17
17
  ### Supported configurations
18
18
 
19
- * Works in cluster mode and in single mode
19
+ * Works in cluster mode and single mode
20
20
  * Supported on all platforms
21
21
 
22
22
  ### Client experience
23
23
 
24
- * All platforms: for clients with an in-flight request, those clients will be served responses before the connection is closed gracefully. Puma gracefully disconnects any idle HTTP persistent connections before restarting.
24
+ * All platforms: clients with an in-flight request are served responses before the connection is closed gracefully. Puma gracefully disconnects any idle HTTP persistent connections before restarting.
25
25
  * On MRI or TruffleRuby on Linux and BSD: Clients who connect just before the server restarts may experience increased latency while the server stops and starts again, but their connections will not be closed prematurely.
26
- * On Windows and on JRuby: Clients who connect just before a restart may experience "connection reset" errors.
26
+ * On Windows and JRuby: Clients who connect just before a restart may experience "connection reset" errors.
27
27
 
28
28
  ### Additional notes
29
29
 
@@ -32,7 +32,7 @@ Any of the following will cause a Puma server to perform a hot restart:
32
32
 
33
33
  ## Phased restart
34
34
 
35
- Phased restarts replace all running workers in a Puma cluster. This is a useful way to gracefully upgrade the application that Puma is serving. A phased restart works by first killing an old worker, then starting a new worker, waiting until the new worker has successfully started before proceeding to the next worker. This process continues until all workers have been replaced. The master process is not restarted.
35
+ Phased restarts replace all running workers in a Puma cluster. This is a useful way to upgrade the application that Puma is serving gracefully. A phased restart works by first killing an old worker, then starting a new worker, waiting until the new worker has successfully started before proceeding to the next worker. This process continues until all workers are replaced. The master process is not restarted.
36
36
 
37
37
  ### How-to
38
38
 
@@ -45,7 +45,7 @@ Any of the following will cause a Puma server to perform a phased restart:
45
45
  ### Supported configurations
46
46
 
47
47
  * Works in cluster mode only
48
- * To support upgrading the application that Puma is serving, ensure `prune_bundler` is enabled and that `preload_app` is disabled (it is disabled by default).
48
+ * To support upgrading the application that Puma is serving, ensure `prune_bundler` is enabled and that `preload_app!` is disabled
49
49
  * Supported on all platforms where cluster mode is supported
50
50
 
51
51
  ### Client experience
data/docs/signals.md CHANGED
@@ -1,8 +1,8 @@
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.
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](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:
5
+ If you are new to signals, it can be helpful to see how they are used. When a process starts 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
@@ -10,7 +10,7 @@ $ irb
10
10
  > pid = Process.spawn 'tail -f my.log'
11
11
  ```
12
12
 
13
- From here we can see that the tail process is running by using the `ps` command:
13
+ From here, we can see that the tail process is running by using the `ps` command:
14
14
 
15
15
  ```sh
16
16
  $ ps aux | grep tail
@@ -27,7 +27,7 @@ Process.detach(pid) # https://ruby-doc.org/core-2.1.1/Process.html#method-c-deta
27
27
  Process.kill("TERM", pid)
28
28
  ```
29
29
 
30
- Now you will see via `ps` that there is no more `tail` process. Sometimes when referring to signals the `SIG` prefix will be used for instance `SIGTERM` is equivalent to sending `TERM` via `Process.kill`.
30
+ Now you will see via `ps` that there is no more `tail` process. Sometimes when referring to signals, the `SIG` prefix will be used. For example, `SIGTERM` is equivalent to sending `TERM` via `Process.kill`.
31
31
 
32
32
  ## Puma Signals
33
33
 
@@ -35,13 +35,14 @@ Puma cluster responds to these signals:
35
35
 
36
36
  - `TTIN` increment the worker count by 1
37
37
  - `TTOU` decrement the worker count by 1
38
- - `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
39
- - `USR2` restart workers. This also reloads puma configuration file, if there is one.
40
- - `USR1` restart workers in phases, a rolling restart. This will not reload configuration file.
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
- - `INT ` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
38
+ - `TERM` send `TERM` to worker. The worker will attempt to finish then exit.
39
+ - `USR2` restart workers. This also reloads the Puma configuration file, if there is one.
40
+ - `USR1` restart workers in phases, a rolling restart. This will not reload the configuration file.
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
+ - `INT ` equivalent of sending Ctrl-C to cluster. Puma 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
+ - `URG ` refork workers in phases from worker 0 if `fork_workers` option is enabled.
45
+ - `INFO` print backtraces of all puma threads
45
46
 
46
47
  ## Callbacks order in case of different signals
47
48
 
data/docs/stats.md CHANGED
@@ -1,4 +1,4 @@
1
- ## accessing stats
1
+ ## Accessing stats
2
2
 
3
3
  Stats can be accessed in two ways:
4
4
 
@@ -47,18 +47,18 @@ end
47
47
 
48
48
  ## Explanation of stats
49
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:
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
51
 
52
- * started_at: when puma was started
52
+ * started_at: when Puma was started
53
53
 
54
54
  ### single mode and individual workers in cluster mode
55
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.
56
+ When Puma runs in single mode, these stats are available at the top level. When Puma runs in cluster mode, these stats are available within the `worker_status` array in a hash labeled `last_status`, in an array of hashes where one hash represents each worker.
57
57
 
58
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
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
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 per worker
62
62
  * requests_count: the number of requests this worker has served since starting
63
63
 
64
64
 
@@ -72,9 +72,9 @@ When Puma is run in single mode, these stats ar available at the top level. When
72
72
 
73
73
  ### worker status
74
74
 
75
- * started_at: when the worker was started
75
+ * started_at: when the worker started
76
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
77
+ * index: each worker gets a number. if Puma is configured to have 3 workers, then this will be 0, 1, or 2
78
78
  * booted: if it's done booting [?]
79
79
  * last_checkin: Last time the worker responded to the master process' heartbeat check.
80
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.
data/docs/systemd.md CHANGED
@@ -1,19 +1,18 @@
1
1
  # systemd
2
2
 
3
- [systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a
4
- commonly available init system (PID 1) on many Linux distributions. It
5
- offers process monitoring (including automatic restarts) and other
6
- useful features for running Puma in production.
3
+ [systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a commonly
4
+ available init system (PID 1) on many Linux distributions. It offers process
5
+ monitoring (including automatic restarts) and other useful features for running
6
+ Puma in production.
7
7
 
8
8
  ## Service Configuration
9
9
 
10
- Below is a sample puma.service configuration file for systemd, which
11
- can be copied or symlinked to /etc/systemd/system/puma.service, or if
12
- desired, using an application or instance specific name.
10
+ Below is a sample puma.service configuration file for systemd, which can be
11
+ copied or symlinked to `/etc/systemd/system/puma.service`, or if desired, using
12
+ an application or instance-specific name.
13
13
 
14
- Note that this uses the systemd preferred "simple" type where the
15
- start command remains running in the foreground (does not fork and
16
- exit).
14
+ Note that this uses the systemd preferred "simple" type where the start command
15
+ remains running in the foreground (does not fork and exit).
17
16
 
18
17
  ~~~~ ini
19
18
  [Unit]
@@ -25,8 +24,7 @@ After=network.target
25
24
 
26
25
  [Service]
27
26
  # Puma supports systemd's `Type=notify` and watchdog service
28
- # monitoring, if the [sd_notify](https://github.com/agis/ruby-sdnotify) gem is installed,
29
- # as of Puma 5.1 or later.
27
+ # monitoring, as of Puma 5.1 or later.
30
28
  # On earlier versions of Puma or JRuby, change this to `Type=simple` and remove
31
29
  # the `WatchdogSec` line.
32
30
  Type=notify
@@ -37,8 +35,8 @@ WatchdogSec=10
37
35
  # Preferably configure a non-privileged user
38
36
  # User=
39
37
 
40
- # The path to the your application code root directory.
41
- # Also replace the "<YOUR_APP_PATH>" place holders below with this path.
38
+ # The path to your application code root directory.
39
+ # Also replace the "<YOUR_APP_PATH>" placeholders below with this path.
42
40
  # Example /home/username/myapp
43
41
  WorkingDirectory=<YOUR_APP_PATH>
44
42
 
@@ -64,33 +62,31 @@ Restart=always
64
62
  WantedBy=multi-user.target
65
63
  ~~~~
66
64
 
67
- See [systemd.exec](https://www.freedesktop.org/software/systemd/man/systemd.exec.html)
65
+ See
66
+ [systemd.exec](https://www.freedesktop.org/software/systemd/man/systemd.exec.html)
68
67
  for additional details.
69
68
 
70
69
  ## Socket Activation
71
70
 
72
- systemd and puma also support socket activation, where systemd opens
73
- the listening socket(s) in advance and provides them to the puma
74
- master process on startup. Among other advantages, this keeps
75
- listening sockets open across puma restarts and achieves graceful
76
- restarts, including when upgraded puma, and is compatible with both
77
- clustered mode and application preload.
78
-
79
- **Note:** Any wrapper scripts which `exec`, or other indirections in
80
- `ExecStart`, may result in activated socket file descriptors being closed
81
- before they reach the puma master process. For example, if using `bundle exec`,
82
- pass the `--keep-file-descriptors` flag. `bundle exec` can be avoided by using a
83
- `puma` executable generated by `bundle binstubs puma`. This is tracked in
84
- [#1499].
85
-
86
- **Note:** Socket activation doesn't currently work on JRuby. This is
87
- tracked in [#1367].
88
-
89
- To use socket activation, configure one or more `ListenStream` sockets
90
- in a companion `*.socket` unit file. Also uncomment the associated
91
- `Requires` directive for the socket unit in the service file (see
92
- above.) Here is a sample puma.socket, matching the ports used in the
93
- above puma.service:
71
+ systemd and Puma also support socket activation, where systemd opens the
72
+ listening socket(s) in advance and provides them to the Puma master process on
73
+ startup. Among other advantages, this keeps listening sockets open across puma
74
+ restarts and achieves graceful restarts, including when upgraded Puma, and is
75
+ compatible with both clustered mode and application preload.
76
+
77
+ **Note:** Any wrapper scripts which `exec`, or other indirections in `ExecStart`
78
+ may result in activated socket file descriptors being closed before reaching the
79
+ puma master process. For example, if using `bundle exec`, pass the
80
+ `--keep-file-descriptors` flag. `bundle exec` can be avoided by using a `puma`
81
+ executable generated by `bundle binstubs puma`. This is tracked in [#1499].
82
+
83
+ **Note:** Socket activation doesn't currently work on JRuby. This is tracked in
84
+ [#1367].
85
+
86
+ Configure one or more `ListenStream` sockets in a companion `*.socket` unit file
87
+ to use socket activation. Also, uncomment the associated `Requires` directive
88
+ for the socket unit in the service file (see above.) Here is a sample
89
+ puma.socket, matching the ports used in the above puma.service:
94
90
 
95
91
  ~~~~ ini
96
92
  [Unit]
@@ -113,31 +109,32 @@ Backlog=1024
113
109
  WantedBy=sockets.target
114
110
  ~~~~
115
111
 
116
- See [systemd.socket](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)
112
+ See
113
+ [systemd.socket](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)
117
114
  for additional configuration details.
118
115
 
119
- Note that the above configurations will work with Puma in either
120
- single process or cluster mode.
116
+ Note that the above configurations will work with Puma in either single process
117
+ or cluster mode.
121
118
 
122
119
  ### Sockets and symlinks
123
120
 
124
- When using releases folders, you should set the socket path using the
125
- shared folder path (ex. `/srv/projet/shared/tmp/puma.sock`), not the
126
- release folder path (`/srv/projet/releases/1234/tmp/puma.sock`).
121
+ When using releases folders, you should set the socket path using the shared
122
+ folder path (ex. `/srv/projet/shared/tmp/puma.sock`), not the release folder
123
+ path (`/srv/projet/releases/1234/tmp/puma.sock`).
127
124
 
128
125
  Puma will detect the release path socket as different than the one provided by
129
- systemd and attempt to bind it again, resulting in the exception
130
- `There is already a server bound to:`.
126
+ systemd and attempt to bind it again, resulting in the exception `There is
127
+ already a server bound to:`.
131
128
 
132
129
  ### Binding
133
130
 
134
- By default you need to configure puma to have binds matching with all
131
+ By default, you need to configure Puma to have binds matching with all
135
132
  ListenStream statements. Any mismatched systemd ListenStreams will be closed by
136
- puma.
133
+ Puma.
137
134
 
138
135
  To automatically bind to all activated sockets, the option
139
136
  `--bind-to-activated-sockets` can be used. This matches the config DSL
140
- `bind_to_activated_sockets` statement. This will cause puma to create a bind
137
+ `bind_to_activated_sockets` statement. This will cause Puma to create a bind
141
138
  automatically for any activated socket. When systemd socket activation is not
142
139
  enabled, this option does nothing.
143
140
 
@@ -146,8 +143,8 @@ binds that's not socket activated.
146
143
 
147
144
  ## Usage
148
145
 
149
- Without socket activation, use `systemctl` as root (e.g. via `sudo`) as
150
- with other system services:
146
+ Without socket activation, use `systemctl` as root (i.e., via `sudo`) as with
147
+ other system services:
151
148
 
152
149
  ~~~~ sh
153
150
  # After installing or making changes to puma.service
@@ -156,35 +153,35 @@ systemctl daemon-reload
156
153
  # Enable so it starts on boot
157
154
  systemctl enable puma.service
158
155
 
159
- # Initial start up.
156
+ # Initial startup.
160
157
  systemctl start puma.service
161
158
 
162
159
  # Check status
163
160
  systemctl status puma.service
164
161
 
165
- # A normal restart. Warning: listeners sockets will be closed
162
+ # A normal restart. Warning: listener's sockets will be closed
166
163
  # while a new puma process initializes.
167
164
  systemctl restart puma.service
168
165
  ~~~~
169
166
 
170
- With socket activation, several but not all of these commands should
171
- be run for both socket and service:
167
+ With socket activation, several but not all of these commands should be run for
168
+ both socket and service:
172
169
 
173
170
  ~~~~ sh
174
171
  # After installing or making changes to either puma.socket or
175
172
  # puma.service.
176
173
  systemctl daemon-reload
177
174
 
178
- # Enable both socket and service so they start on boot. Alternatively
179
- # you could leave puma.service disabled and systemd will start it on
180
- # first use (with startup lag on first request)
175
+ # Enable both socket and service, so they start on boot. Alternatively
176
+ # you could leave puma.service disabled, and systemd will start it on
177
+ # the first use (with startup lag on the first request)
181
178
  systemctl enable puma.socket puma.service
182
179
 
183
- # Initial start up. The Requires directive (see above) ensures the
180
+ # Initial startup. The Requires directive (see above) ensures the
184
181
  # socket is started before the service.
185
182
  systemctl start puma.socket puma.service
186
183
 
187
- # Check status of both socket and service.
184
+ # Check the status of both socket and service.
188
185
  systemctl status puma.socket puma.service
189
186
 
190
187
  # A "hot" restart, with systemd keeping puma.socket listening and
@@ -197,8 +194,8 @@ systemctl restart puma.service
197
194
  systemctl restart puma.socket puma.service
198
195
  ~~~~
199
196
 
200
- Here is sample output from `systemctl status` with both service and
201
- socket running:
197
+ Here is sample output from `systemctl status` with both service and socket
198
+ running:
202
199
 
203
200
  ~~~~
204
201
  ● puma.socket - Puma HTTP Server Accept Sockets
@@ -231,14 +228,12 @@ Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
231
228
 
232
229
  ### capistrano3-puma
233
230
 
234
- By default,
235
- [capistrano3-puma](https://github.com/seuros/capistrano-puma) uses
236
- `pumactl` for deployment restarts, outside of systemd. To learn the
237
- exact commands that this tool would use for `ExecStart` and
238
- `ExecStop`, use the following `cap` commands in dry-run mode, and
239
- update from the above forking service configuration accordingly. Note
240
- also that the configured `User` should likely be the same as the
241
- capistrano3-puma `:puma_user` option.
231
+ By default, [capistrano3-puma](https://github.com/seuros/capistrano-puma) uses
232
+ `pumactl` for deployment restarts outside of systemd. To learn the exact
233
+ commands that this tool would use for `ExecStart` and `ExecStop`, use the
234
+ following `cap` commands in dry-run mode, and update from the above forking
235
+ service configuration accordingly. Note also that the configured `User` should
236
+ likely be the same as the capistrano3-puma `:puma_user` option.
242
237
 
243
238
  ~~~~ sh
244
239
  stage=production # or different stage, as needed
@@ -248,3 +243,4 @@ cap $stage puma:stop --dry-run
248
243
 
249
244
  [Restart]: https://www.freedesktop.org/software/systemd/man/systemd.service.html#Restart=
250
245
  [#1367]: https://github.com/puma/puma/issues/1367
246
+ [#1499]: https://github.com/puma/puma/issues/1499
@@ -0,0 +1,150 @@
1
+ # Testing - benchmark/local files
2
+
3
+ These files generate data that shows request-per-second (RPS), etc. Typically, files are in
4
+ pairs, a shell script and a Ruby script. The shell script starts the server, then runs the
5
+ Ruby file, which starts client request stream(s), then collects and logs metrics.
6
+
7
+ ## response_time_wrk.sh
8
+
9
+ This uses [wrk] for generating data. One or more wrk runs are performed. Summarizes RPS and
10
+ wrk latency times. The default for the `-b` argument runs 28 different client request streams,
11
+ and takes a bit over 5 minutes. See 'Request Stream Configuration' below for `-b` argument
12
+ description.
13
+
14
+ <details>
15
+ <summary>Summary output for<br/><code>benchmarks/local/response_time_wrk.sh -w2 -t5:5 -s tcp6</code>:</summary>
16
+
17
+ ```
18
+ Type req/sec 50% 75% 90% 99% 100% Resp Size
19
+ ───────────────────────────────────────────────────────────────── 1kB
20
+ array 13710 0.74 2.52 5.23 7.76 37.45 1024
21
+ chunk 13502 0.76 2.55 5.28 7.84 11.23 1042
22
+ string 13794 0.74 2.51 5.20 7.75 14.07 1024
23
+ io 9615 1.16 3.45 7.13 10.57 15.75 1024
24
+ ───────────────────────────────────────────────────────────────── 10kB
25
+ array 13458 0.76 2.57 5.31 7.93 13.94 10239
26
+ chunk 13066 0.78 2.64 5.46 8.18 38.48 10320
27
+ string 13500 0.76 2.55 5.29 7.88 11.42 10240
28
+ io 9293 1.18 3.59 7.39 10.94 16.99 10240
29
+ ───────────────────────────────────────────────────────────────── 100kB
30
+ array 11315 0.96 3.06 6.33 9.49 17.69 102424
31
+ chunk 9916 1.10 3.48 7.20 10.73 15.14 103075
32
+ string 10948 1.00 3.17 6.57 9.83 17.88 102378
33
+ io 8901 1.21 3.72 7.48 11.27 59.98 102407
34
+ ───────────────────────────────────────────────────────────────── 256kB
35
+ array 9217 1.15 3.82 7.88 11.74 17.12 262212
36
+ chunk 7339 1.45 4.76 9.81 14.63 22.70 264007
37
+ string 8574 1.19 3.81 7.73 11.21 15.80 262147
38
+ io 8911 1.19 3.80 7.55 15.25 60.01 262183
39
+ ───────────────────────────────────────────────────────────────── 512kB
40
+ array 6951 1.49 5.03 10.28 15.90 25.08 524378
41
+ chunk 5234 2.03 6.56 13.57 20.46 32.15 527862
42
+ string 6438 1.55 5.04 10.12 16.28 72.87 524275
43
+ io 8533 1.15 4.62 8.79 48.15 70.51 524327
44
+ ───────────────────────────────────────────────────────────────── 1024kB
45
+ array 4122 1.80 15.59 41.87 67.79 121.00 1048565
46
+ chunk 3158 2.82 15.22 31.00 71.39 99.90 1055654
47
+ string 4710 2.24 6.66 13.65 20.38 70.44 1048575
48
+ io 8355 1.23 3.95 7.94 14.08 68.54 1048498
49
+ ───────────────────────────────────────────────────────────────── 2048kB
50
+ array 2454 4.12 14.02 27.70 43.48 88.89 2097415
51
+ chunk 1743 6.26 17.65 36.98 55.78 92.10 2111358
52
+ string 2479 4.38 12.52 25.65 38.44 95.62 2097502
53
+ io 8264 1.25 3.83 7.76 11.73 65.69 2097090
54
+
55
+ Body ────────── req/sec ────────── ─────── req 50% times ───────
56
+ KB array chunk string io array chunk string io
57
+ 1 13710 13502 13794 9615 0.745 0.757 0.741 1.160
58
+ 10 13458 13066 13500 9293 0.760 0.784 0.759 1.180
59
+ 100 11315 9916 10948 8901 0.960 1.100 1.000 1.210
60
+ 256 9217 7339 8574 8911 1.150 1.450 1.190 1.190
61
+ 512 6951 5234 6438 8533 1.490 2.030 1.550 1.150
62
+ 1024 4122 3158 4710 8355 1.800 2.820 2.240 1.230
63
+ 2048 2454 1743 2479 8264 4.120 6.260 4.380 1.250
64
+ ─────────────────────────────────────────────────────────────────────
65
+ wrk -t8 -c16 -d10s
66
+ benchmarks/local/response_time_wrk.sh -w2 -t5:5 -s tcp6 -Y
67
+ Server cluster mode -w2 -t5:5, bind: tcp6
68
+ Puma repo branch 00-response-refactor
69
+ ruby 3.2.0dev (2022-06-14T01:21:55Z master 048f14221c) +YJIT [x86_64-linux]
70
+
71
+ [2136] - Gracefully shutting down workers...
72
+ [2136] === puma shutdown: 2022-06-13 21:16:13 -0500 ===
73
+ [2136] - Goodbye!
74
+
75
+ 5:15 Total Time
76
+ ```
77
+ </details><br/>
78
+
79
+ ## bench_base.sh, bench_base.rb
80
+
81
+ These two files setup parameters for the Puma server, which is normally started in a shell
82
+ script. It then starts a Ruby file (a subclass of BenchBase), passing arguments to it. The
83
+ Ruby file is normally used to generate a client request stream(s).
84
+
85
+ ### Puma Configuration
86
+
87
+ The following arguments are used for the Puma server:
88
+
89
+ * **`-C`** - configuration file
90
+ * **`-d`** - app delay
91
+ * **`-r`** - rackup file, often defaults to test/rackup/ci_select.ru
92
+ * **`-s`** - bind socket type, default is tcp/tcp4, also tcp6, ssl/ssl4, ssl6, unix, or aunix
93
+ (unix & abstract unix are not available with wrk).
94
+ * **`-t`** - threads, expressed as '5:5', same as Puma --thread
95
+ * **`-w`** - workers, same as Puma --worker
96
+ * **`-Y`** - enable Ruby YJIT
97
+
98
+ ### Request Stream Configuration
99
+
100
+ The following arguments are used for request streams:
101
+
102
+ * **`-b`** - response body configuration. Body type options are a array, c chunked, s string,
103
+ and i for File/IO. None or any combination can be specified, they should start the option.
104
+ Then, any combination of comma separated integers can be used for the response body size
105
+ in kB. The string 'ac50,100' would create four runs, 50kb array, 50kB chunked, 100kB array,
106
+ and 100kB chunked. See 'Testing - test/rackup/ci-*.ru files' for more info.
107
+ * **`-c`** - connections per client request stream thread, defaults to 2 for wrk.
108
+ * **`-D`** - duration of client request stream in seconds.
109
+ * **`-T`** - number of threads in the client request stream. For wrk, this defaults to
110
+ 80% of Puma workers * max_threads.
111
+
112
+ ### Notes - Configuration
113
+
114
+ The above lists script arguments.
115
+
116
+ `bench_base.sh` contains most server defaults. Many can be set via ENV variables.
117
+
118
+ `bench_base.rb` contains the client request stream defaults. The default value for
119
+ `-b` is `acsi1,10,100,256,512,1024,2048`, which is a 4 x 7 matrix, and hence, runs
120
+ 28 jobs. Also, the i body type (File/IO) generates files, they are placed in the
121
+ `"#{Dir.tmpdir}/.puma_response_body_io"` directory, which is created.
122
+
123
+ ### Notes - wrk
124
+
125
+ The shell scripts use `-T` for wrk's thread count, since `-t` is used for Puma
126
+ server threads. Regarding the `-c` argument, wrk has an interesting behavior.
127
+ The total number of connections is set by `(connections/threads).to_i`. The scripts
128
+ here use `-c` as connections per thread. Hence, using `-T4 -c2` will yield a total
129
+ of eight wrk connections, two per thread. The equivalent wrk arguments would be `-t4 -c8`.
130
+
131
+ Puma can only process so many requests, and requests will queue in the backlog
132
+ until Puma can respond to them. With wrk, if the number of total connections is
133
+ too high, one will see the upper latency times increase, pushing into the lower
134
+ latency times as the connections are increased. The default values for wrk's
135
+ threads and connections were chosen to minimize requests' time in the backlog.
136
+
137
+ An example with four wrk runs using `-b s10`. Notice that `req/sec` varies by
138
+ less than 1%, but the `75%` times increase by an order of magnitude:
139
+ ```
140
+ req/sec 50% 75% 90% 99% 100% Resp Size wrk cmd line
141
+ ─────────────────────────────────────────────────────────────────────────────
142
+ 13597 0.755 2.550 5.260 7.800 13.310 12040 wrk -t8 -c16 -d10
143
+ 13549 0.793 4.430 8.140 11.220 16.600 12002 wrk -t10 -c20 -d10
144
+ 13570 1.040 25.790 40.010 49.070 58.300 11982 wrk -t8 -c64 -d10
145
+ 13684 1.050 25.820 40.080 49.160 66.190 12033 wrk -t16 -c64 -d10
146
+ ```
147
+ Finally, wrk's output may cause rounding errors, so the response body size calculation is
148
+ imprecise.
149
+
150
+ [wrk]: <https://github.com/ioquatix/wrk>