puma 3.11.4 → 4.2.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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +130 -1
  3. data/README.md +100 -44
  4. data/docs/architecture.md +1 -0
  5. data/docs/deployment.md +24 -4
  6. data/docs/restart.md +4 -2
  7. data/docs/systemd.md +27 -9
  8. data/ext/puma_http11/PumaHttp11Service.java +2 -0
  9. data/ext/puma_http11/extconf.rb +8 -0
  10. data/ext/puma_http11/http11_parser.c +37 -62
  11. data/ext/puma_http11/http11_parser_common.rl +3 -3
  12. data/ext/puma_http11/mini_ssl.c +96 -5
  13. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
  14. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +21 -4
  15. data/lib/puma/accept_nonblock.rb +7 -1
  16. data/lib/puma/app/status.rb +35 -29
  17. data/lib/puma/binder.rb +47 -11
  18. data/lib/puma/cli.rb +21 -7
  19. data/lib/puma/client.rb +227 -191
  20. data/lib/puma/cluster.rb +70 -31
  21. data/lib/puma/commonlogger.rb +2 -0
  22. data/lib/puma/configuration.rb +6 -3
  23. data/lib/puma/const.rb +24 -18
  24. data/lib/puma/control_cli.rb +33 -14
  25. data/lib/puma/convenient.rb +2 -0
  26. data/lib/puma/delegation.rb +2 -0
  27. data/lib/puma/detect.rb +2 -0
  28. data/lib/puma/dsl.rb +308 -76
  29. data/lib/puma/events.rb +6 -1
  30. data/lib/puma/io_buffer.rb +3 -6
  31. data/lib/puma/jruby_restart.rb +2 -0
  32. data/lib/puma/launcher.rb +102 -55
  33. data/lib/puma/minissl.rb +41 -19
  34. data/lib/puma/null_io.rb +2 -0
  35. data/lib/puma/plugin/tmp_restart.rb +2 -0
  36. data/lib/puma/plugin.rb +7 -2
  37. data/lib/puma/rack/builder.rb +4 -1
  38. data/lib/puma/rack/urlmap.rb +2 -0
  39. data/lib/puma/rack_default.rb +2 -0
  40. data/lib/puma/reactor.rb +220 -34
  41. data/lib/puma/runner.rb +14 -4
  42. data/lib/puma/server.rb +82 -40
  43. data/lib/puma/single.rb +15 -3
  44. data/lib/puma/state_file.rb +2 -0
  45. data/lib/puma/tcp_logger.rb +2 -0
  46. data/lib/puma/thread_pool.rb +59 -36
  47. data/lib/puma/util.rb +2 -6
  48. data/lib/puma.rb +8 -0
  49. data/lib/rack/handler/puma.rb +6 -3
  50. data/tools/docker/Dockerfile +16 -0
  51. data/tools/jungle/init.d/puma +6 -6
  52. data/tools/trickletest.rb +0 -1
  53. metadata +22 -10
  54. data/lib/puma/compat.rb +0 -14
  55. data/lib/puma/daemon_ext.rb +0 -31
  56. data/lib/puma/java_io_buffer.rb +0 -45
  57. 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: 7f451a7278034b23b2a1537d6bde82ae318cd58750dbab2c0a6aa4eb0e72efb0
4
- data.tar.gz: 3841d52680598006e72b92c37c358d0f185980bfca81cdc55c19e25673156f61
3
+ metadata.gz: a3b55d391fabcf1d06ef5dec1bf340baa8f79bb259eda2c82b00f325fc43575a
4
+ data.tar.gz: c880b55b1277a9046d92c761dcf60d7bff9a059c9a0d54985607919c50a0653a
5
5
  SHA512:
6
- metadata.gz: 6273588bb47a3f85b40a358dc445733de687707111dd5aaffe4004be32a82eef00c227495abd9e68bd0b3f398395b64b685e8b78f5b428e3aee87be50f91cb1f
7
- data.tar.gz: 167dc9b6bdcf05050cff4d80af977ede8c4cd9b5fb0dd3397f8075e4657402cf5e7e084c248c2e23d06669cbce52cd13a84155612a3451c0ac5df6d0cff36730
6
+ metadata.gz: d384912b42fd6e839793c912c1bf534aae25a29b03ec1eaaaad3b8ececc786f3f72df22194479c38720d01c9463bf7868fb19ade35a3fe399f17f2757a99612d
7
+ data.tar.gz: 7b6b2f827c6c4c2bf33f6a88f00f8cae55a36b4f7bffe6b36c3d98d880e9f83c6c75398ded27c1ab1e5e6e1bad2dbc3f72713abcc1d37ba60ccdfb8d1c7764c1
data/History.md CHANGED
@@ -1,3 +1,123 @@
1
+ ## Master
2
+
3
+ * Features
4
+ * Your feature goes here (#Github Number)
5
+
6
+ * Bugfixes
7
+ * Your bugfix goes here (#Github Number)
8
+
9
+
10
+ ## 4.2.0 / 2019-09-23
11
+
12
+ * 6 features
13
+ * Pumactl has a new -e environment option and reads config/puma/<environment>.rb config files (#1885)
14
+ * Semicolons are now allowed in URL paths (MRI only), useful for Angular or Redmine (#1934)
15
+ * Allow extra dependencies to be defined when using prune_bundler (#1105)
16
+ * Puma now reports the correct port when binding to port 0, also reports other listeners when binding to localhost (#1786)
17
+ * Sending SIGINFO to any Puma worker now prints currently active threads and their backtraces (#1320)
18
+ * Puma threads all now have their name set on Ruby 2.3+ (#1968)
19
+ * 4 bugfixes
20
+ * Fix some misbehavior with phased restart and externally SIGTERMed workers (#1908, #1952)
21
+ * Fix socket closing on error (#1941)
22
+ * Removed unnecessary SIGINT trap for JRuby that caused some race conditions (#1961)
23
+ * Fix socket files being left around after process stopped (#1970)
24
+ * Absolutely thousands of lines of test improvements and fixes thanks to @MSP-Greg
25
+
26
+ ## 4.1.1 / 2019-09-05
27
+
28
+ * 3 bugfixes
29
+ * Revert our attempt to not dup STDOUT/STDERR (#1946)
30
+ * Fix socket close on error (#1941)
31
+ * Fix workers not shutting down correctly (#1908)
32
+
33
+ ## 4.1.0 / 2019-08-08
34
+
35
+ * 4 features
36
+ * Add REQUEST_PATH on parse error message (#1831)
37
+ * You can now easily add custom log formatters with the `log_formatter` config option (#1816)
38
+ * Puma.stats now provides process start times (#1844)
39
+ * Add support for disabling TLSv1.1 (#1836)
40
+
41
+ * 7 bugfixes
42
+ * Fix issue where Puma was creating zombie process entries (#1887)
43
+ * Fix bugs with line-endings and chunked encoding (#1812)
44
+ * RACK_URL_SCHEME is now set correctly in all conditions (#1491)
45
+ * We no longer mutate global STDOUT/STDERR, particularly the sync setting (#1837)
46
+ * SSL read_nonblock no longer blocks (#1857)
47
+ * Swallow connection errors when sending early hints (#1822)
48
+ * Backtrace no longer dumped when invalid pumactl commands are run (#1863)
49
+
50
+ * 5 other
51
+ * Avoid casting worker_timeout twice (#1838)
52
+ * Removed a call to private that wasn't doing anything (#1882)
53
+ * README, Rakefile, docs and test cleanups (#1848, #1847, #1846, #1853, #1859, #1850, #1866, #1870, #1872, #1833, #1888)
54
+ * Puma.io has proper documentation now (https://puma.io/puma/)
55
+ * Added the Contributor Covenant CoC
56
+
57
+ * 1 known issue
58
+ * Some users are still experiencing issues surrounding socket activation and Unix sockets (#1842)
59
+
60
+ ## 4.0.1 / 2019-07-11
61
+
62
+ * 2 bugfixes
63
+ * Fix socket removed after reload - should fix problems with systemd socket activation. (#1829)
64
+ * 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)
65
+ * 1 other
66
+ * Removed unnecessary RUBY_VERSION checks. (#1827)
67
+
68
+ ## 4.0.0 / 2019-06-25
69
+
70
+ * 9 features
71
+ * Add support for disabling TLSv1.0 (#1562)
72
+ * Request body read time metric (#1569)
73
+ * Add out_of_band hook (#1648)
74
+ * Re-implement (native) IOBuffer for JRuby (#1691)
75
+ * Min worker timeout (#1716)
76
+ * Add option to suppress SignalException on SIGTERM (#1690)
77
+ * Allow mutual TLS CA to be set using `ssl_bind` DSL (#1689)
78
+ * Reactor now uses nio4r instead of `select` (#1728)
79
+ * Add status to pumactl with pidfile (#1824)
80
+
81
+ * 10 bugfixes
82
+ * Do not accept new requests on shutdown (#1685, #1808)
83
+ * Fix 3 corner cases when request body is chunked (#1508)
84
+ * Change pid existence check's condition branches (#1650)
85
+ * Don't call .stop on a server that doesn't exist (#1655)
86
+ * Implemented NID_X9_62_prime256v1 (P-256) curve over P-521 (#1671)
87
+ * Fix @notify.close can't modify frozen IOError (RuntimeError) (#1583)
88
+ * Fix Java 8 support (#1773)
89
+ * Fix error `uninitialized constant Puma::Cluster` (#1731)
90
+ * Fix `not_token` being able to be set to true (#1803)
91
+ * Fix "Hang on SIGTERM with ruby 2.6 in clustered mode" ([PR #1741], [#1674], [#1720], [#1730], [#1755])
92
+
93
+ [PR #1741]: https://github.com/puma/puma/pull/1741
94
+ [#1674]: https://github.com/puma/puma/issues/1674
95
+ [#1720]: https://github.com/puma/puma/issues/1720
96
+ [#1730]: https://github.com/puma/puma/issues/1730
97
+ [#1755]: https://github.com/puma/puma/issues/1755
98
+
99
+ ## 3.12.1 / 2019-03-19
100
+
101
+ * 1 features
102
+ * Internal strings are frozen (#1649)
103
+ * 3 bugfixes
104
+ * Fix chunked ending check (#1607)
105
+ * Rack handler should use provided default host (#1700)
106
+ * Better support for detecting runtimes that support `fork` (#1630)
107
+
108
+ ## 3.12.0 / 2018-07-13
109
+
110
+ * 5 features:
111
+ * You can now specify which SSL ciphers the server should support, default is unchanged (#1478)
112
+ * The setting for Puma's `max_threads` is now in `Puma.stats` (#1604)
113
+ * Pool capacity is now in `Puma.stats` (#1579)
114
+ * Installs restricted to Ruby 2.2+ (#1506)
115
+ * `--control` is now deprecated in favor of `--control-url` (#1487)
116
+
117
+ * 2 bugfixes:
118
+ * Workers will no longer accept more web requests than they have capacity to process. This prevents an issue where one worker would accept lots of requests while starving other workers (#1563)
119
+ * In a test env puma now emits the stack on an exception (#1557)
120
+
1
121
  ## 3.11.4 / 2018-04-12
2
122
 
3
123
  * 2 features:
@@ -7,7 +127,7 @@
7
127
  * Fix parsing CLI options (#1482)
8
128
  * Order of stderr and stdout is made before redirecting to a log file (#1511)
9
129
  * Init.d fix of `ps -p` to check if pid exists (#1545)
10
- * Early hits bugfix (#1550)
130
+ * Early hints bugfix (#1550)
11
131
  * Purge interrupt queue when closing socket fails (#1553)
12
132
 
13
133
  ## 3.11.3 / 2018-03-05
@@ -1382,3 +1502,12 @@ be added back in a future date when a java Puma::MiniSSL is added.
1382
1502
  ## 1.0.0 / 2012-03-29
1383
1503
 
1384
1504
  * Released!
1505
+
1506
+ ## Ignore - this is for maintainers to copy-paste during release
1507
+ ## Master
1508
+
1509
+ * Features
1510
+ * Your feature goes here (#Github Number)
1511
+
1512
+ * Bugfixes
1513
+ * 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
@@ -162,33 +169,57 @@ Need a bit of security? Use SSL sockets:
162
169
  $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
163
170
  ```
164
171
 
172
+ #### Controlling SSL Cipher Suites
173
+
174
+ To use or avoid specific SSL cipher suites, use `ssl_cipher_filter` or `ssl_cipher_list` options.
175
+
176
+ ##### Ruby:
177
+
178
+ ```
179
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA'
180
+ ```
181
+
182
+ ##### JRuby:
183
+
184
+ ```
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'
186
+ ```
187
+
188
+ See https://www.openssl.org/docs/man1.0.2/apps/ciphers.html for cipher filter format and full list of cipher suites.
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
+
165
196
  ### Control/Status Server
166
197
 
167
- 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.
168
199
 
169
200
  ```
170
- $ puma --control tcp://127.0.0.1:9293 --control-token foo
201
+ $ puma --control-url tcp://127.0.0.1:9293 --control-token foo
171
202
  ```
172
203
 
173
- 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.
174
205
 
175
206
  You can also interact with the control server via `pumactl`. This command will restart Puma:
176
207
 
177
208
  ```
178
- $ pumactl -C 'tcp://127.0.0.1:9293' --control-token foo restart
209
+ $ pumactl --control-url 'tcp://127.0.0.1:9293' --control-token foo restart
179
210
  ```
180
211
 
181
212
  To see a list of `pumactl` options, use `pumactl --help`.
182
213
 
183
214
  ### Configuration File
184
215
 
185
- 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:
186
217
 
187
218
  ```
188
219
  $ puma -C /path/to/config
189
220
  ```
190
221
 
191
- 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`.
192
223
 
193
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:
194
225
 
@@ -196,7 +227,7 @@ If you want to prevent Puma from looking for a configuration file in those locat
196
227
  $ puma -C "-"
197
228
  ```
198
229
 
199
- 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.
200
231
 
201
232
  ## Restart
202
233
 
@@ -213,14 +244,14 @@ Puma responds to several signals. A detailed guide to using UNIX signals with Pu
213
244
  Some platforms do not support all Puma features.
214
245
 
215
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).
216
- * **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).
217
248
 
218
249
  ## Known Bugs
219
250
 
220
- For MRI versions 2.2.7, 2.2.8, 2.2.9, 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:
251
+ 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:
221
252
 
222
253
  ```ruby
223
- if %w(2.2.7 2.2.8 2.2.9 2.3.4 2.4.1).include? RUBY_VERSION
254
+ if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
224
255
  begin
225
256
  require 'stopgap_13632'
226
257
  rescue LoadError
@@ -239,6 +270,13 @@ reliability in production environments:
239
270
  * [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for sysvinit (init.d) and upstart
240
271
  * [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
241
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
+
242
280
  ## Contributing
243
281
 
244
282
  To run the test suite:
@@ -248,6 +286,24 @@ $ bundle install
248
286
  $ bundle exec rake
249
287
  ```
250
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
+
251
307
  ## License
252
308
 
253
309
  Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.
data/docs/architecture.md CHANGED
@@ -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)
data/docs/deployment.md CHANGED
@@ -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
data/docs/restart.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  To perform a restart, there are 3 builtin mechanisms:
4
4
 
5
- * Send the `puma` process the `SIGUSR2` signal
6
- * Send the `puma` process the `SIGUSR1` signal (rolling restart, cluster mode only)
5
+ * Send the `puma` process the `SIGUSR2` signal (normal restart)
6
+ * Send the `puma` process the `SIGUSR1` signal (restart in phases (a "rolling restart"), cluster mode only)
7
7
  * Use the status server and issue `/restart`
8
8
 
9
9
  No code is shared between the current and restarted process, so it should be safe to issue a restart any place where you would manually stop Puma and start it again.
@@ -22,6 +22,8 @@ But again beware, upgrading an application sometimes involves upgrading the data
22
22
 
23
23
  If you perform a lot of database migrations, you probably should not use phased restart and use a normal/hot restart instead (`pumactl restart`). That way, no code is shared while deploying (in that case, `preload_app!` might help for quicker deployment, see ["Clustered Mode" in the README](../README.md#clustered-mode)).
24
24
 
25
+ **Note**: Hot and phased restarts are only available on MRI, not on JRuby. They are also unavailable on Windows servers.
26
+
25
27
  ### Release Directory
26
28
 
27
29
  If your symlink releases into a common working directory (i.e., `/current` from Capistrano), Puma won't pick up your new changes when running phased restarts without additional configuration. You should set your working directory within Puma's config to specify the directory it should use. This is a change from earlier versions of Puma (< 2.15) that would infer the directory for you.
data/docs/systemd.md CHANGED
@@ -32,21 +32,26 @@ Type=simple
32
32
  # Preferably configure a non-privileged user
33
33
  # User=
34
34
 
35
- # The path to the puma application root
36
- # Also replace the "<WD>" place holders below with this path.
37
- WorkingDirectory=
35
+ # The path to the your application code root directory.
36
+ # Also replace the "<YOUR_APP_PATH>" place holders below with this path.
37
+ # Example /home/username/myapp
38
+ WorkingDirectory=<YOUR_APP_PATH>
38
39
 
39
40
  # Helpful for debugging socket activation, etc.
40
41
  # Environment=PUMA_DEBUG=1
41
42
 
42
- # The command to start Puma. This variant uses a binstub generated via
43
- # `bundle binstubs puma --path ./sbin` in the WorkingDirectory
44
- # (replace "<WD>" below)
45
- ExecStart=<WD>/sbin/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
43
+ # SystemD will not run puma even if it is in your path. You must specify
44
+ # an absolute URL to puma. For example /usr/local/bin/puma
45
+ # Alternatively, create a binstub with `bundle binstubs puma --path ./sbin` in the WorkingDirectory
46
+ ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/puma.rb
47
+
48
+ # Variant: Rails start.
49
+ # ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/config/puma.rb ../config.ru
46
50
 
47
- # Variant: Use config file with `bind` directives instead:
48
- # ExecStart=<WD>/sbin/puma -C config.rb
49
51
  # Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub
52
+ # Variant: Specify directives inline.
53
+ # ExecStart=/<FULLPATH>/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
54
+
50
55
 
51
56
  Restart=always
52
57
 
@@ -66,6 +71,13 @@ listening sockets open across puma restarts and achieves graceful
66
71
  restarts, including when upgraded puma, and is compatible with both
67
72
  clustered mode and application preload.
68
73
 
74
+ **Note:** Any wrapper scripts which `exec`, or other indirections in
75
+ `ExecStart`, may result in activated socket file descriptors being closed
76
+ before they reach the puma master process. For example, if using `bundle exec`,
77
+ pass the `--keep-file-descriptors` flag. `bundle exec` can be avoided by using a
78
+ `puma` executable generated by `bundle binstubs puma`. This is tracked in
79
+ [#1499].
80
+
69
81
  **Note:** Socket activation doesn't currently work on jruby. This is
70
82
  tracked in [#1367].
71
83
 
@@ -247,6 +259,12 @@ PIDFile=<WD>/shared/tmp/pids/puma.pid
247
259
  # reconsider if you actually need the forking config.
248
260
  Restart=no
249
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
+
250
268
  [Install]
251
269
  WantedBy=multi-user.target
252
270
  ~~~~
@@ -6,11 +6,13 @@ import org.jruby.Ruby;
6
6
  import org.jruby.runtime.load.BasicLibraryService;
7
7
 
8
8
  import org.jruby.puma.Http11;
9
+ import org.jruby.puma.IOBuffer;
9
10
  import org.jruby.puma.MiniSSL;
10
11
 
11
12
  public class PumaHttp11Service implements BasicLibraryService {
12
13
  public boolean basicLoad(final Ruby runtime) throws IOException {
13
14
  Http11.createHttp11(runtime);
15
+ IOBuffer.createIOBuffer(runtime);
14
16
  MiniSSL.createMiniSSL(runtime);
15
17
  return true;
16
18
  }
@@ -9,6 +9,14 @@ unless ENV["DISABLE_SSL"]
9
9
  %w'ssl ssleay32'.find {|ssl| have_library(ssl, 'SSL_CTX_new')}
10
10
 
11
11
  have_header "openssl/bio.h"
12
+
13
+ # below is yes for 1.0.2 & later
14
+ have_func "DTLS_method" , "openssl/ssl.h"
15
+
16
+ # below are yes for 1.1.0 & later, may need to check func rather than macro
17
+ # with versions after 1.1.1
18
+ have_func "TLS_server_method" , "openssl/ssl.h"
19
+ have_macro "SSL_CTX_set_min_proto_version", "openssl/ssl.h"
12
20
  end
13
21
  end
14
22