puma 3.12.2 → 4.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.

Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +106 -6
  3. data/README.md +91 -43
  4. data/docs/architecture.md +1 -0
  5. data/docs/deployment.md +24 -4
  6. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  7. data/docs/images/puma-connection-flow.png +0 -0
  8. data/docs/images/puma-general-arch.png +0 -0
  9. data/docs/plugins.md +20 -10
  10. data/docs/restart.md +4 -2
  11. data/docs/systemd.md +27 -9
  12. data/ext/puma_http11/PumaHttp11Service.java +2 -0
  13. data/ext/puma_http11/extconf.rb +8 -0
  14. data/ext/puma_http11/http11_parser.c +37 -62
  15. data/ext/puma_http11/http11_parser_common.rl +3 -3
  16. data/ext/puma_http11/mini_ssl.c +78 -8
  17. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
  18. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +15 -4
  19. data/lib/puma.rb +8 -0
  20. data/lib/puma/accept_nonblock.rb +7 -1
  21. data/lib/puma/app/status.rb +35 -29
  22. data/lib/puma/binder.rb +39 -5
  23. data/lib/puma/cli.rb +4 -0
  24. data/lib/puma/client.rb +221 -199
  25. data/lib/puma/cluster.rb +53 -30
  26. data/lib/puma/configuration.rb +4 -3
  27. data/lib/puma/const.rb +22 -25
  28. data/lib/puma/control_cli.rb +21 -4
  29. data/lib/puma/dsl.rb +297 -75
  30. data/lib/puma/events.rb +4 -1
  31. data/lib/puma/io_buffer.rb +1 -6
  32. data/lib/puma/launcher.rb +95 -53
  33. data/lib/puma/minissl.rb +35 -17
  34. data/lib/puma/plugin.rb +5 -2
  35. data/lib/puma/plugin/tmp_restart.rb +2 -0
  36. data/lib/puma/rack/builder.rb +2 -0
  37. data/lib/puma/rack/urlmap.rb +2 -0
  38. data/lib/puma/rack_default.rb +2 -0
  39. data/lib/puma/reactor.rb +109 -57
  40. data/lib/puma/runner.rb +4 -3
  41. data/lib/puma/server.rb +59 -62
  42. data/lib/puma/single.rb +3 -3
  43. data/lib/puma/thread_pool.rb +14 -32
  44. data/lib/puma/util.rb +1 -6
  45. data/lib/rack/handler/puma.rb +3 -3
  46. data/tools/docker/Dockerfile +16 -0
  47. data/tools/jungle/init.d/puma +6 -6
  48. data/tools/trickletest.rb +0 -1
  49. metadata +20 -8
  50. data/lib/puma/compat.rb +0 -14
  51. data/lib/puma/daemon_ext.rb +0 -33
  52. data/lib/puma/delegation.rb +0 -13
  53. data/lib/puma/java_io_buffer.rb +0 -47
  54. data/lib/puma/rack/backports/uri/common_193.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8483f2a5087645c3b4a3f066a9ad804849c9c81d9df9c50ee17cc5a6594071bb
4
- data.tar.gz: aee48433624d9efaeafe08c7747a38e8fd843645861ae82b3e2d8c59f1b7ecb5
3
+ metadata.gz: c9951b68e8fbc1851402ee152ae08df16681868b48cb8dd1ab94c409b12125b2
4
+ data.tar.gz: 250163367ab0f96dc67feb73e1105c48d20d69d5ad77095ce741d5ac63927e79
5
5
  SHA512:
6
- metadata.gz: 95aa82dbc1af85a87975c27f5061ccd55349950e3d17336ad62271788601821f835dc53b9f8542d008de0d6f7f4fc8b128a89cf5300488016f573c34e319ee62
7
- data.tar.gz: e4e97b12c6c3d285fb327201760f2ffcd80dd716f67b52aee02670940d141832ba28044ddfda969df173ebe9bbe1b58068714e6308897d62d308ee6daebe3f29
6
+ metadata.gz: 58c353b21da37a71ca1cca25f75ebc70bba0c1db97a3384d0169fb8258f5952a0ce80260330492fd7767d9ab423a834afd399d3ef1035cbbc248b0d767af8f06
7
+ data.tar.gz: 8143eeaccf5b22c0d99e2eb3c2852278833a927d31c6f7e7ed333866f3ce9753b67fe6b3dfd447078cae1269606075c2977a8d389b4169cc3738feacdf28c5db
data/History.md CHANGED
@@ -1,13 +1,104 @@
1
- ## Master
1
+ * Features
2
+ * Your feature goes here (#Github Number)
2
3
 
3
- * x features
4
+ * Bugfixes
5
+ * Your bugfix goes here (#Github Number)
4
6
 
5
- * x bugfixes
7
+ ## 4.2.1 / 2019-10-07
6
8
 
7
- ## 4.3.1 and 3.12.2 / 2019-12-05
9
+ * 3 bugfixes
10
+ * Fix socket activation of systemd (pre-existing) unix binder files (#1842, #1988)
11
+ * Deal with multiple calls to bind correctly (#1986, #1994, #2006)
12
+ * Accepts symbols for `verify_mode` (#1222)
13
+
14
+ ## 4.2.0 / 2019-09-23
15
+
16
+ * 6 features
17
+ * Pumactl has a new -e environment option and reads config/puma/<environment>.rb config files (#1885)
18
+ * Semicolons are now allowed in URL paths (MRI only), useful for Angular or Redmine (#1934)
19
+ * Allow extra dependencies to be defined when using prune_bundler (#1105)
20
+ * Puma now reports the correct port when binding to port 0, also reports other listeners when binding to localhost (#1786)
21
+ * Sending SIGINFO to any Puma worker now prints currently active threads and their backtraces (#1320)
22
+ * Puma threads all now have their name set on Ruby 2.3+ (#1968)
23
+ * 4 bugfixes
24
+ * Fix some misbehavior with phased restart and externally SIGTERMed workers (#1908, #1952)
25
+ * Fix socket closing on error (#1941)
26
+ * Removed unnecessary SIGINT trap for JRuby that caused some race conditions (#1961)
27
+ * Fix socket files being left around after process stopped (#1970)
28
+ * Absolutely thousands of lines of test improvements and fixes thanks to @MSP-Greg
29
+
30
+ ## 4.1.1 / 2019-09-05
8
31
 
9
- * Security
10
- * Fix: a poorly-behaved client could use keepalive requests to monopolize Puma's reactor and create a denial of service attack. CVE-2019-16770.
32
+ * 3 bugfixes
33
+ * Revert our attempt to not dup STDOUT/STDERR (#1946)
34
+ * Fix socket close on error (#1941)
35
+ * Fix workers not shutting down correctly (#1908)
36
+
37
+ ## 4.1.0 / 2019-08-08
38
+
39
+ * 4 features
40
+ * Add REQUEST_PATH on parse error message (#1831)
41
+ * You can now easily add custom log formatters with the `log_formatter` config option (#1816)
42
+ * Puma.stats now provides process start times (#1844)
43
+ * Add support for disabling TLSv1.1 (#1836)
44
+
45
+ * 7 bugfixes
46
+ * Fix issue where Puma was creating zombie process entries (#1887)
47
+ * Fix bugs with line-endings and chunked encoding (#1812)
48
+ * RACK_URL_SCHEME is now set correctly in all conditions (#1491)
49
+ * We no longer mutate global STDOUT/STDERR, particularly the sync setting (#1837)
50
+ * SSL read_nonblock no longer blocks (#1857)
51
+ * Swallow connection errors when sending early hints (#1822)
52
+ * Backtrace no longer dumped when invalid pumactl commands are run (#1863)
53
+
54
+ * 5 other
55
+ * Avoid casting worker_timeout twice (#1838)
56
+ * Removed a call to private that wasn't doing anything (#1882)
57
+ * README, Rakefile, docs and test cleanups (#1848, #1847, #1846, #1853, #1859, #1850, #1866, #1870, #1872, #1833, #1888)
58
+ * Puma.io has proper documentation now (https://puma.io/puma/)
59
+ * Added the Contributor Covenant CoC
60
+
61
+ * 1 known issue
62
+ * Some users are still experiencing issues surrounding socket activation and Unix sockets (#1842)
63
+
64
+ ## 4.0.1 / 2019-07-11
65
+
66
+ * 2 bugfixes
67
+ * Fix socket removed after reload - should fix problems with systemd socket activation. (#1829)
68
+ * Add extconf tests for DTLS_method & TLS_server_method, use in minissl.rb. Should fix "undefined symbol: DTLS_method" when compiling against old OpenSSL versions. (#1832)
69
+ * 1 other
70
+ * Removed unnecessary RUBY_VERSION checks. (#1827)
71
+
72
+ ## 4.0.0 / 2019-06-25
73
+
74
+ * 9 features
75
+ * Add support for disabling TLSv1.0 (#1562)
76
+ * Request body read time metric (#1569)
77
+ * Add out_of_band hook (#1648)
78
+ * Re-implement (native) IOBuffer for JRuby (#1691)
79
+ * Min worker timeout (#1716)
80
+ * Add option to suppress SignalException on SIGTERM (#1690)
81
+ * Allow mutual TLS CA to be set using `ssl_bind` DSL (#1689)
82
+ * Reactor now uses nio4r instead of `select` (#1728)
83
+ * Add status to pumactl with pidfile (#1824)
84
+
85
+ * 10 bugfixes
86
+ * Do not accept new requests on shutdown (#1685, #1808)
87
+ * Fix 3 corner cases when request body is chunked (#1508)
88
+ * Change pid existence check's condition branches (#1650)
89
+ * Don't call .stop on a server that doesn't exist (#1655)
90
+ * Implemented NID_X9_62_prime256v1 (P-256) curve over P-521 (#1671)
91
+ * Fix @notify.close can't modify frozen IOError (RuntimeError) (#1583)
92
+ * Fix Java 8 support (#1773)
93
+ * Fix error `uninitialized constant Puma::Cluster` (#1731)
94
+ * Fix `not_token` being able to be set to true (#1803)
95
+ * Fix "Hang on SIGTERM with ruby 2.6 in clustered mode" ([PR #1741], [#1674], [#1720], [#1730], [#1755])
96
+
97
+ [PR #1741]: https://github.com/puma/puma/pull/1741
98
+ [#1674]: https://github.com/puma/puma/issues/1674
99
+ [#1720]: https://github.com/puma/puma/issues/1720
100
+ [#1730]: https://github.com/puma/puma/issues/1730
101
+ [#1755]: https://github.com/puma/puma/issues/1755
11
102
 
12
103
  ## 3.12.1 / 2019-03-19
13
104
 
@@ -1415,3 +1506,12 @@ be added back in a future date when a java Puma::MiniSSL is added.
1415
1506
  ## 1.0.0 / 2012-03-29
1416
1507
 
1417
1508
  * Released!
1509
+
1510
+ ## Ignore - this is for maintainers to copy-paste during release
1511
+ ## Master
1512
+
1513
+ * Features
1514
+ * Your feature goes here (#Github Number)
1515
+
1516
+ * Bugfixes
1517
+ * Your bugfix goes here (#Github Number)
data/README.md CHANGED
@@ -1,45 +1,47 @@
1
1
  <p align="center">
2
- <img src="http://puma.io/images/logos/puma-logo-large.png">
2
+ <img src="https://puma.io/images/logos/puma-logo-large.png">
3
3
  </p>
4
4
 
5
5
  # Puma: A Ruby Web Server Built For Concurrency
6
6
 
7
7
  [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/puma/puma?utm\_source=badge&utm\_medium=badge&utm\_campaign=pr-badge)
8
- [![Build Status](https://secure.travis-ci.org/puma/puma.svg)](http://travis-ci.org/puma/puma)
9
- [![AppVeyor](https://img.shields.io/appveyor/ci/nateberkopec/puma.svg)](https://ci.appveyor.com/project/nateberkopec/puma)
10
- [![Dependency Status](https://gemnasium.com/puma/puma.svg)](https://gemnasium.com/puma/puma)
8
+ [![Travis Build Status](https://travis-ci.org/puma/puma.svg?branch=master)](https://travis-ci.org/puma/puma)
9
+
11
10
  [![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
11
+ [![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)
12
12
 
13
- Puma is a **simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications** in development and production.
13
+ Puma is a **simple, fast, multi-threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications**.
14
14
 
15
15
  ## Built For Speed &amp; Concurrency
16
16
 
17
- Under the hood, Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request in a thread from an internal thread pool. Since each request is served in a separate thread, truly concurrent Ruby implementations (JRuby, Rubinius) will use all available CPU cores.
17
+ Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request using a thread pool. Each request is served in a separate thread, so truly concurrent Ruby implementations (JRuby, Rubinius) will use all available CPU cores.
18
18
 
19
- Puma was designed to be the go-to server for [Rubinius](http://rubini.us), but also works well with JRuby and MRI.
19
+ Puma was designed to be the go-to server for [Rubinius](https://rubinius.com), but also works well with JRuby and MRI.
20
20
 
21
- On MRI, there is a Global VM Lock (GVL) that ensures only one thread can run Ruby code at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing blocking IO to be run concurrently.
21
+ On MRI, there is a Global VM Lock (GVL) that ensures only one thread can run Ruby code at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing IO waiting to be done in parallel.
22
22
 
23
23
  ## Quick Start
24
24
 
25
25
  ```
26
26
  $ gem install puma
27
- $ puma <any rackup (*.ru) file>
28
- ```
27
+ $ puma
28
+ ```
29
+
30
+ Without arguments, puma will look for a rackup (.ru) file in the current working directory called `config.ru`.
29
31
 
30
32
  ## Frameworks
31
33
 
32
34
  ### Rails
33
35
 
34
- Puma is the default server for Rails, and should already be included in your Gemfile.
36
+ Puma is the default server for Rails, included in the generated Gemfile.
35
37
 
36
- Then start your server with the `rails` command:
38
+ Start your server with the `rails` command:
37
39
 
38
40
  ```
39
- $ rails s
41
+ $ rails server
40
42
  ```
41
43
 
42
- Many configuration options are not available when using `rails s`. It is recommended that you use Puma's executable instead:
44
+ Many configuration options and Puma features are not available when using `rails server`. It is recommended that you use Puma's executable instead:
43
45
 
44
46
  ```
45
47
  $ bundle exec puma
@@ -53,7 +55,7 @@ You can run your Sinatra application with Puma from the command line like this:
53
55
  $ ruby app.rb -s Puma
54
56
  ```
55
57
 
56
- Or you can configure your application to always use Puma:
58
+ Or you can configure your Sinatra application to always use Puma:
57
59
 
58
60
  ```ruby
59
61
  require 'sinatra'
@@ -64,6 +66,9 @@ configure { set :server, :puma }
64
66
 
65
67
  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).
66
68
 
69
+ You can also find several configuration examples as part of the
70
+ [test](test/config) suite.
71
+
67
72
  ### Thread Pool
68
73
 
69
74
  Puma uses a thread pool. You can set the minimum and maximum number of threads that are available in the pool with the `-t` (or `--threads`) flag:
@@ -72,9 +77,9 @@ Puma uses a thread pool. You can set the minimum and maximum number of threads t
72
77
  $ puma -t 8:32
73
78
  ```
74
79
 
75
- 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 hit resource limits).
80
+ 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).
76
81
 
77
- 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.
82
+ 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.
78
83
 
79
84
  ### Clustered mode
80
85
 
@@ -84,9 +89,9 @@ Puma also offers "clustered mode". Clustered mode `fork`s workers from a master
84
89
  $ puma -t 8:32 -w 3
85
90
  ```
86
91
 
87
- Note that threads are still used in clustered mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will spawn 32 threads in total.
92
+ Note that threads are still used in clustered mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will spawn 32 threads in total, with 16 in each worker process.
88
93
 
89
- In clustered mode, Puma may "preload" your application. This loads all the application code *prior* to forking. Preloading reduces total memory usage of your application via an operating system feature called [copy-on-write](https://en.wikipedia.org/wiki/Copy-on-write) (Ruby 2.0+ only). Use the `--preload` flag from the command line:
94
+ In clustered mode, Puma can "preload" your application. This loads all the application code *prior* to forking. Preloading reduces total memory usage of your application via an operating system feature called [copy-on-write](https://en.wikipedia.org/wiki/Copy-on-write) (Ruby 2.0+ only). Use the `--preload` flag from the command line:
90
95
 
91
96
  ```
92
97
  $ puma -w 3 --preload
@@ -111,40 +116,42 @@ end
111
116
 
112
117
  This code can be used to setup the process before booting the application, allowing
113
118
  you to do some Puma-specific things that you don't want to embed in your application.
114
- For instance, you could fire a log notification that a worker booted or send something to statsd.
115
- This can be called multiple times.
119
+ For instance, you could fire a log notification that a worker booted or send something to statsd. This can be called multiple times.
116
120
 
117
- If you're preloading your application and using ActiveRecord, it's recommended that you setup your connection pool here:
121
+ `before_fork` specifies a block to be run before workers are forked:
118
122
 
119
123
  ```ruby
120
124
  # config/puma.rb
121
- on_worker_boot do
122
- ActiveSupport.on_load(:active_record) do
123
- ActiveRecord::Base.establish_connection
124
- end
125
+ before_fork do
126
+ # configuration here
125
127
  end
126
128
  ```
127
129
 
128
- On top of that, you can specify a block in your configuration file that will be run before workers are forked:
130
+ Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preload_app copies the code of master into the workers.
131
+
132
+ ### Error handling
133
+
134
+ If puma encounters an error outside of the context of your application, it will respond with a 500 and a simple
135
+ textual error message (see `lowlevel_error` in [this file](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
136
+ You can specify custom behavior for this scenario. For example, you can report the error to your third-party
137
+ error-tracking service (in this example, [rollbar](http://rollbar.com)):
129
138
 
130
139
  ```ruby
131
- # config/puma.rb
132
- before_fork do
133
- # configuration here
140
+ lowlevel_error_handler do |e|
141
+ Rollbar.critical(e)
142
+ [500, {}, ["An error has occurred, and engineers have been informed. Please reload the page. If you continue to have problems, contact support@example.com\n"]]
134
143
  end
135
144
  ```
136
145
 
137
- Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preload_app copies the code of master into the workers.
138
-
139
146
  ### Binding TCP / Sockets
140
147
 
141
- In contrast to many other server configs which require multiple flags, Puma simply uses one URI parameter with the `-b` (or `--bind`) flag:
148
+ Bind Puma to a socket with the `-b` (or `--bind`) flag:
142
149
 
143
150
  ```
144
151
  $ puma -b tcp://127.0.0.1:9292
145
152
  ```
146
153
 
147
- Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)?
154
+ To use a UNIX Socket instead of TCP:
148
155
 
149
156
  ```
150
157
  $ puma -b unix:///var/run/puma.sock
@@ -157,30 +164,44 @@ $ puma -b 'unix:///var/run/puma.sock?umask=0111'
157
164
  ```
158
165
 
159
166
  Need a bit of security? Use SSL sockets:
167
+
160
168
  ```
161
169
  $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
162
170
  ```
171
+
163
172
  #### Controlling SSL Cipher Suites
164
- Need to use or avoid specific SSL cipher suites? Use ssl_cipher_filter or ssl_cipher_list options.
165
- #####Ruby:
173
+
174
+ To use or avoid specific SSL cipher suites, use `ssl_cipher_filter` or `ssl_cipher_list` options.
175
+
176
+ ##### Ruby:
177
+
166
178
  ```
167
179
  $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA'
168
180
  ```
169
- #####JRuby:
181
+
182
+ ##### JRuby:
183
+
170
184
  ```
171
185
  $ puma -b 'ssl://127.0.0.1:9292?keystore=path_to_keystore&keystore-pass=keystore_password&ssl_cipher_list=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA'
172
186
  ```
187
+
173
188
  See https://www.openssl.org/docs/man1.0.2/apps/ciphers.html for cipher filter format and full list of cipher suites.
174
189
 
190
+ Disable TLS v1 with the `no_tlsv1` option:
191
+
192
+ ```
193
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true'
194
+ ```
195
+
175
196
  ### Control/Status Server
176
197
 
177
- Puma has a built-in status/control app that can be used to query and control Puma itself.
198
+ Puma has a built-in status and control app that can be used to query and control Puma.
178
199
 
179
200
  ```
180
201
  $ puma --control-url tcp://127.0.0.1:9293 --control-token foo
181
202
  ```
182
203
 
183
- Puma will start the control server on localhost port 9293. All requests to the control server will need to include `token=foo` as a query parameter. This allows for simple authentication. Check out [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the app has available.
204
+ Puma will start the control server on localhost port 9293. All requests to the control server will need to include control token (in this case, `token=foo`) as a query parameter. This allows for simple authentication. Check out [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the status app has available.
184
205
 
185
206
  You can also interact with the control server via `pumactl`. This command will restart Puma:
186
207
 
@@ -192,13 +213,13 @@ To see a list of `pumactl` options, use `pumactl --help`.
192
213
 
193
214
  ### Configuration File
194
215
 
195
- You can also provide a configuration file which Puma will use with the `-C` (or `--config`) flag:
216
+ You can also provide a configuration file with the `-C` (or `--config`) flag:
196
217
 
197
218
  ```
198
219
  $ puma -C /path/to/config
199
220
  ```
200
221
 
201
- 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 variable, the default file location will be `config/puma/environment_name.rb`.
222
+ 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 variable, Puma looks for configuration at `config/puma/<environment_name>.rb`.
202
223
 
203
224
  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:
204
225
 
@@ -206,7 +227,7 @@ If you want to prevent Puma from looking for a configuration file in those locat
206
227
  $ puma -C "-"
207
228
  ```
208
229
 
209
- Take the following [sample configuration](https://github.com/puma/puma/blob/master/examples/config.rb) as inspiration or check out [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb) to see all available options.
230
+ Check out [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb) to see all available options.
210
231
 
211
232
  ## Restart
212
233
 
@@ -223,7 +244,7 @@ Puma responds to several signals. A detailed guide to using UNIX signals with Pu
223
244
  Some platforms do not support all Puma features.
224
245
 
225
246
  * **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).
226
- * **Windows**: daemon mode is not supported due to a lack of fork(2).
247
+ * **Windows**: Cluster mode is not supported due to a lack of fork(2).
227
248
 
228
249
  ## Known Bugs
229
250
 
@@ -249,6 +270,13 @@ reliability in production environments:
249
270
  * [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for sysvinit (init.d) and upstart
250
271
  * [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
251
272
 
273
+ ## Community Plugins
274
+
275
+ * [puma-heroku](https://github.com/evanphx/puma-heroku) — default Puma configuration for running on Heroku
276
+ * [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
277
+ * [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
278
+ * [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog
279
+
252
280
  ## Contributing
253
281
 
254
282
  To run the test suite:
@@ -258,6 +286,26 @@ $ bundle install
258
286
  $ bundle exec rake
259
287
  ```
260
288
 
289
+ To run a single test file, run only that file:
290
+
291
+ ```bash
292
+ $ ruby -Ilib test/test_integration.rb
293
+ ```
294
+
295
+ Or use [`m`](https://github.com/qrush/m):
296
+
297
+ ```
298
+ $ bundle exec m test/test_binder.rb
299
+ ```
300
+
301
+ Which can also be used to run a single test case:
302
+
303
+ ```
304
+ $ bundle exec m test/test_binder.rb:37
305
+ ```
306
+
307
+ If you open a pull request with a change that doesn't need to be noted in the changelog ([`History.md`](History.md)), add the text `[changelog skip]` to the pull request title to skip [the changelog check](https://github.com/puma/puma/pull/1991).
308
+
261
309
  ## License
262
310
 
263
311
  Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.
@@ -20,6 +20,7 @@ Clustered mode is shown/discussed here. Single mode is analogous to having a sin
20
20
  * By default, a single, separate thread is used to receive HTTP requests across the socket.
21
21
  * When at least one worker thread is available for work, a connection is accepted and placed in this request buffer
22
22
  * This thread waits for entire HTTP requests to be received over the connection
23
+ * The time spent waiting for the HTTP request body to be received is exposed to the Rack app as `env['puma.request_body_wait']` (milliseconds)
23
24
  * Once received, the connection is pushed into the "todo" set
24
25
  * Worker threads pop work off the "todo" set for processing
25
26
  * The thread processes the request via the rack application (which generates the HTTP response)
@@ -38,22 +38,42 @@ Here are some rules of thumb:
38
38
  * As you grow more confident in the thread safety of your app, you can tune the
39
39
  workers down and the threads up.
40
40
 
41
+ #### Ubuntu / Systemd (Systemctl) Installation
42
+
43
+ See [systemd.md](systemd.md)
44
+
41
45
  #### Worker utilization
42
46
 
43
- **How do you know if you're got enough (or too many workers)?**
47
+ **How do you know if you've got enough (or too many workers)?**
44
48
 
45
49
  A good question. Due to MRI's GIL, only one thread can be executing Ruby code at a time.
46
50
  But since so many apps are waiting on IO from DBs, etc., they can utilize threads
47
51
  to make better use of the process.
48
52
 
49
53
  The rule of thumb is you never want processes that are pegged all the time. This
50
- means that there is more work to do that the process can get through. On the other
54
+ means that there is more work to do than the process can get through. On the other
51
55
  hand, if you have processes that sit around doing nothing, then they're just eating
52
56
  up resources.
53
57
 
54
- Watching your CPU utilization over time and aim for about 70% on average. This means
58
+ Watch your CPU utilization over time and aim for about 70% on average. This means
55
59
  you've got capacity still but aren't starving threads.
56
60
 
61
+ **Measuring utilization**
62
+
63
+ Using a timestamp header from an upstream proxy server (eg. nginx or haproxy), it's
64
+ possible to get an indication of how long requests have been waiting for a Puma
65
+ thread to become available.
66
+
67
+ * Have your upstream proxy set a header with the time it received the request:
68
+ * nginx: `proxy_set_header X-Request-Start "${msec}";`
69
+ * haproxy: `http-request set-header X-Request-Start "%t";`
70
+ * In your Rack middleware, determine the amount of time elapsed since `X-Request-Start`.
71
+ * To improve accuracy, you will want to subtract time spent waiting for slow clients:
72
+ * `env['puma.request_body_wait']` contains the number of milliseconds Puma spent
73
+ waiting for the client to send the request body.
74
+ * haproxy: `%Th` (TLS handshake time) and `%Ti` (idle time before request) can
75
+ can also be added as headers.
76
+
57
77
  ## Daemonizing
58
78
 
59
79
  I prefer to not daemonize my servers and use something like `runit` or `upstart` to
@@ -62,7 +82,7 @@ makes it easy to figure out what is going on. Additionally, unlike `unicorn`,
62
82
  puma does not require daemonization to do zero-downtime restarts.
63
83
 
64
84
  I see people using daemonization because they start puma directly via capistrano
65
- task and thus want it to live on past the `cap deploy`. To this people I said:
85
+ task and thus want it to live on past the `cap deploy`. To these people I say:
66
86
  You need to be using a process monitor. Nothing is making sure puma stays up in
67
87
  this scenario! You're just waiting for something weird to happen, puma to die,
68
88
  and to get paged at 3am. Do yourself a favor, at least the process monitoring