puma 3.5.0 → 3.12.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 (67) hide show
  1. checksums.yaml +5 -5
  2. data/{History.txt → History.md} +318 -75
  3. data/README.md +143 -227
  4. data/docs/architecture.md +36 -0
  5. data/{DEPLOYMENT.md → docs/deployment.md} +0 -0
  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 +28 -0
  10. data/docs/restart.md +39 -0
  11. data/docs/signals.md +56 -3
  12. data/docs/systemd.md +124 -22
  13. data/ext/puma_http11/extconf.rb +2 -0
  14. data/ext/puma_http11/http11_parser.c +85 -84
  15. data/ext/puma_http11/http11_parser.h +1 -0
  16. data/ext/puma_http11/http11_parser.rl +10 -9
  17. data/ext/puma_http11/io_buffer.c +7 -7
  18. data/ext/puma_http11/mini_ssl.c +67 -6
  19. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +13 -16
  20. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +15 -2
  21. data/ext/puma_http11/puma_http11.c +1 -0
  22. data/lib/puma.rb +13 -5
  23. data/lib/puma/app/status.rb +8 -0
  24. data/lib/puma/binder.rb +22 -17
  25. data/lib/puma/cli.rb +49 -33
  26. data/lib/puma/client.rb +149 -4
  27. data/lib/puma/cluster.rb +54 -12
  28. data/lib/puma/commonlogger.rb +19 -20
  29. data/lib/puma/compat.rb +3 -7
  30. data/lib/puma/configuration.rb +133 -130
  31. data/lib/puma/const.rb +19 -37
  32. data/lib/puma/control_cli.rb +38 -35
  33. data/lib/puma/convenient.rb +3 -3
  34. data/lib/puma/detect.rb +3 -1
  35. data/lib/puma/dsl.rb +80 -58
  36. data/lib/puma/events.rb +6 -8
  37. data/lib/puma/io_buffer.rb +1 -1
  38. data/lib/puma/jruby_restart.rb +0 -1
  39. data/lib/puma/launcher.rb +61 -30
  40. data/lib/puma/minissl.rb +85 -4
  41. data/lib/puma/null_io.rb +6 -13
  42. data/lib/puma/plugin.rb +12 -1
  43. data/lib/puma/plugin/tmp_restart.rb +1 -2
  44. data/lib/puma/rack/builder.rb +3 -0
  45. data/lib/puma/rack/urlmap.rb +9 -8
  46. data/lib/puma/reactor.rb +135 -0
  47. data/lib/puma/runner.rb +27 -1
  48. data/lib/puma/server.rb +134 -32
  49. data/lib/puma/single.rb +17 -3
  50. data/lib/puma/thread_pool.rb +67 -20
  51. data/lib/puma/util.rb +1 -5
  52. data/lib/rack/handler/puma.rb +58 -17
  53. data/tools/jungle/README.md +12 -2
  54. data/tools/jungle/init.d/README.md +9 -2
  55. data/tools/jungle/init.d/puma +32 -62
  56. data/tools/jungle/init.d/run-puma +5 -1
  57. data/tools/jungle/rc.d/README.md +74 -0
  58. data/tools/jungle/rc.d/puma +61 -0
  59. data/tools/jungle/rc.d/puma.conf +10 -0
  60. data/tools/trickletest.rb +1 -1
  61. metadata +22 -92
  62. data/Gemfile +0 -13
  63. data/Manifest.txt +0 -77
  64. data/Rakefile +0 -158
  65. data/lib/puma/rack/backports/uri/common_18.rb +0 -59
  66. data/lib/puma/rack/backports/uri/common_192.rb +0 -55
  67. data/puma.gemspec +0 -52
data/README.md CHANGED
@@ -1,338 +1,254 @@
1
+ <p align="center">
2
+ <img src="http://puma.io/images/logos/puma-logo-large.png">
3
+ </p>
4
+
1
5
  # Puma: A Ruby Web Server Built For Concurrency
2
6
 
3
7
  [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/puma/puma?utm\_source=badge&utm\_medium=badge&utm\_campaign=pr-badge)
4
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)
5
10
  [![Dependency Status](https://gemnasium.com/puma/puma.svg)](https://gemnasium.com/puma/puma)
6
11
  [![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
7
12
 
8
- ## Description
9
-
10
- Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications. Puma is intended for use in both development and production environments. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like Rubinius or JRuby.
13
+ Puma is a **simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications** in development and production.
11
14
 
12
15
  ## Built For Speed &amp; Concurrency
13
16
 
14
- Puma is a simple, fast, and highly concurrent HTTP 1.1 server for Ruby web applications. It can be used with any application that supports Rack, and is considered the replacement for Webrick and Mongrel. It was designed to be the go-to server for [Rubinius](http://rubini.us), but also works well with JRuby and MRI. Puma is intended for use in both development and production environments.
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.
15
18
 
16
- 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 (which you can control). This allows Puma to provide real concurrency for your web application!
19
+ Puma was designed to be the go-to server for [Rubinius](http://rubini.us), but also works well with JRuby and MRI.
17
20
 
18
- With Rubinius 2.0, Puma will utilize all cores on your CPU with real threads, meaning you won't have to spawn multiple processes to increase throughput. You can expect to see a similar benefit from JRuby.
19
-
20
- On MRI, there is a Global Interpreter Lock (GIL) that ensures only one thread can be run 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 (EventMachine-based servers such as Thin turn off this ability, requiring you to use special libraries). Your mileage may vary. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like [Rubinius](http://rubini.us) or [JRuby](http://jruby.org).
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
22
 
22
23
  ## Quick Start
23
24
 
24
- The easiest way to get started with Puma is to install it via RubyGems. You can do this easily:
25
-
26
- $ gem install puma
27
-
28
- Now you should have the `puma` command available in your PATH, so just do the following in the root folder of your Rack application:
29
-
30
- $ puma app.ru
31
-
32
- ## Plugins
33
-
34
- Puma 3.0 added support for plugins that can augment configuration and service operations.
35
-
36
- 2 canonical plugins to look to aid in development of further plugins:
37
-
38
- * [tmp\_restart](https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb): Restarts the server if the file `tmp/restart.txt` is touched
39
- * [heroku](https://github.com/puma/puma-heroku/blob/master/lib/puma/plugin/heroku.rb): Packages up the default configuration used by puma on Heroku
40
-
41
- Plugins are activated in a puma configuration file (such as `config/puma.rb'`) by adding `plugin "name"`, such as `plugin "heroku"`.
42
-
43
- Plugins are activated based simply on path requirements so, activating the `heroku` plugin will simply be doing `require "puma/plugin/heroku"`. This allows gems to provide multiple plugins (as well as unrelated gems to provide puma plugins).
44
-
45
- The `tmp_restart` plugin is bundled with puma, so it can always be used.
46
-
47
- To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
48
-
49
- ### API
25
+ ```
26
+ $ gem install puma
27
+ $ puma <any rackup (*.ru) file>
28
+ ```
50
29
 
51
- At present, there are 2 hooks that plugins can use: `start` and `config`.
30
+ ## Frameworks
52
31
 
53
- `start` runs when the server has started and allows the plugin to start other functionality to augment puma.
32
+ ### Rails
54
33
 
55
- `config` runs when the server is being configured and is passed a `Puma::DSL` object that can be used to add additional configuration.
34
+ Puma is the default server for Rails, and should already be included in your Gemfile.
56
35
 
57
- Any public methods in `Puma::Plugin` are the public API that any plugin may use.
36
+ Then start your server with the `rails` command:
58
37
 
59
- In the future, more hooks and APIs will be added.
38
+ ```
39
+ $ rails s
40
+ ```
60
41
 
42
+ Many configuration options are not available when using `rails s`. It is recommended that you use Puma's executable instead:
61
43
 
62
- ## Advanced Setup
44
+ ```
45
+ $ bundle exec puma
46
+ ```
63
47
 
64
48
  ### Sinatra
65
49
 
66
50
  You can run your Sinatra application with Puma from the command line like this:
67
51
 
68
- $ ruby app.rb -s Puma
52
+ ```
53
+ $ ruby app.rb -s Puma
54
+ ```
69
55
 
70
56
  Or you can configure your application to always use Puma:
71
57
 
72
- require 'sinatra'
73
- configure { set :server, :puma }
74
-
75
- If you use Bundler, make sure you add Puma to your Gemfile (see below).
76
-
77
- ### Rails
78
-
79
- First, make sure Puma is in your Gemfile:
80
-
81
- gem 'puma'
82
-
83
- Then start your server with the `rails` command:
84
-
85
- $ rails s Puma
86
-
87
- ### Rackup
88
-
89
- You can pass it as an option to `rackup`:
90
-
91
- $ rackup -s Puma
92
-
93
- Alternatively, you can modify your `config.ru` to choose Puma by default, by adding the following as the first line:
94
-
95
- #\ -s puma
58
+ ```ruby
59
+ require 'sinatra'
60
+ configure { set :server, :puma }
61
+ ```
96
62
 
97
63
  ## Configuration
98
64
 
99
- Puma provides numerous options for controlling the operation of the server. Consult `puma -h` (or `puma --help`) for a full list.
65
+ 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).
100
66
 
101
67
  ### Thread Pool
102
68
 
103
- Puma utilizes a dynamic thread pool which you can modify. You can set the minimum and maximum number of threads that are available in the pool with the `-t` (or `--threads`) flag:
69
+ 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:
70
+
71
+ ```
72
+ $ puma -t 8:32
73
+ ```
104
74
 
105
- $ puma -t 8:32
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).
106
76
 
107
- 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 very large number, as you may exhaust resources on the system (or hit resource limits).
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.
108
78
 
109
79
  ### Clustered mode
110
80
 
111
- Puma 2 offers clustered mode, allowing you to use forked processes to handle multiple incoming requests concurrently, in addition to threads already provided. You can tune the number of workers with the `-w` (or `--workers`) flag:
81
+ Puma also offers "clustered mode". Clustered mode `fork`s workers from a master process. Each child process still has its own thread pool. You can tune the number of workers with the `-w` (or `--workers`) flag:
112
82
 
113
- $ puma -t 8:32 -w 3
114
-
115
- On a ruby implementation that offers native threads, you should tune this number to match the number of cores available.
116
- 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 be 32 threads.
83
+ ```
84
+ $ puma -t 8:32 -w 3
85
+ ```
117
86
 
118
- If you're running in Clustered Mode you can optionally choose to preload your application before starting up the workers. This is necessary in order to take advantage of the [Copy on Write](http://en.wikipedia.org/wiki/Copy-on-write) feature introduced in [MRI Ruby 2.0](https://blog.heroku.com/archives/2013/3/6/matz_highlights_ruby_2_0_at_waza). To do this simply specify the `--preload` flag in invocation:
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.
119
88
 
120
- # CLI invocation
121
- $ puma -t 8:32 -w 3 --preload
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:
122
90
 
123
- If you're using a configuration file, use the `preload_app!` method, and be sure to specify your config file's location with the `-C` flag:
91
+ ```
92
+ $ puma -w 3 --preload
93
+ ```
124
94
 
125
- $ puma -C config/puma.rb
95
+ If you're using a configuration file, use the `preload_app!` method:
126
96
 
127
- # config/puma.rb
128
- threads 8,32
129
- workers 3
130
- preload_app!
97
+ ```ruby
98
+ # config/puma.rb
99
+ workers 3
100
+ preload_app!
101
+ ```
131
102
 
132
103
  Additionally, you can specify a block in your configuration file that will be run on boot of each worker:
133
104
 
134
- # config/puma.rb
135
- on_worker_boot do
136
- # configuration here
137
- end
105
+ ```ruby
106
+ # config/puma.rb
107
+ on_worker_boot do
108
+ # configuration here
109
+ end
110
+ ```
138
111
 
139
112
  This code can be used to setup the process before booting the application, allowing
140
113
  you to do some Puma-specific things that you don't want to embed in your application.
141
114
  For instance, you could fire a log notification that a worker booted or send something to statsd.
142
- This can be called multiple times to add hooks.
115
+ This can be called multiple times.
143
116
 
144
117
  If you're preloading your application and using ActiveRecord, it's recommended that you setup your connection pool here:
145
118
 
146
- # config/puma.rb
147
- on_worker_boot do
148
- ActiveSupport.on_load(:active_record) do
149
- ActiveRecord::Base.establish_connection
150
- end
151
- end
152
-
153
- On top of that, you can specify a block in your configuration file that will be run before workers are forked
154
-
155
- # config/puma.rb
156
- before_fork do
157
- # configuration here
158
- end
159
-
160
- This code can be used to clean up before forking to clients, allowing
161
- you to do some Puma-specific things that you don't want to embed in your application.
162
-
163
- If you're preloading your application and using ActiveRecord, it's recommended that you close any connections to the database here to prevent connection leakage:
164
-
165
- # config/puma.rb
166
- before_fork do
167
- ActiveRecord::Base.connection_pool.disconnect!
168
- end
169
-
170
- This rule applies to any connections to external services (Redis, databases, memcache, ...) that might be started automatically by the framework.
171
-
172
- When you use preload_app, all of your new code goes into the master process, and is then copied into the workers (meaning it’s only compatible with cluster mode). General rule is to use preload_app when your workers die often and need fast starts. If you don’t have many workers, you probably should not use preload_app.
173
-
174
- Note that preload_app can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preload_app is all about copying the code of master into the workers.
175
-
176
- ### Error handler for low-level errors
119
+ ```ruby
120
+ # config/puma.rb
121
+ on_worker_boot do
122
+ ActiveSupport.on_load(:active_record) do
123
+ ActiveRecord::Base.establish_connection
124
+ end
125
+ end
126
+ ```
177
127
 
178
- If puma encounters an error outside of the context of your application, it will respond with a 500 and a simple
179
- textual error message (see `lowlevel_error` in [this file](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
180
- You can specify custom behavior for this scenario. For example, you can report the error to your third-party
181
- error-tracking service (in this example, [rollbar](http://rollbar.com)):
128
+ On top of that, you can specify a block in your configuration file that will be run before workers are forked:
182
129
 
183
130
  ```ruby
184
- lowlevel_error_handler do |e|
185
- Rollbar.critical(e)
186
- [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"]]
131
+ # config/puma.rb
132
+ before_fork do
133
+ # configuration here
187
134
  end
188
135
  ```
189
136
 
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
+
190
139
  ### Binding TCP / Sockets
191
140
 
192
141
  In contrast to many other server configs which require multiple flags, Puma simply uses one URI parameter with the `-b` (or `--bind`) flag:
193
142
 
194
- $ puma -b tcp://127.0.0.1:9292
143
+ ```
144
+ $ puma -b tcp://127.0.0.1:9292
145
+ ```
195
146
 
196
- Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)? No problem!
147
+ Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)?
197
148
 
198
- $ puma -b unix:///var/run/puma.sock
149
+ ```
150
+ $ puma -b unix:///var/run/puma.sock
151
+ ```
199
152
 
200
153
  If you need to change the permissions of the UNIX socket, just add a umask parameter:
201
154
 
202
- $ puma -b 'unix:///var/run/puma.sock?umask=0111'
203
-
204
- Need a bit of security? Use SSL sockets!
155
+ ```
156
+ $ puma -b 'unix:///var/run/puma.sock?umask=0111'
157
+ ```
205
158
 
206
- $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
159
+ Need a bit of security? Use SSL sockets:
160
+ ```
161
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
162
+ ```
163
+ #### 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:
166
+ ```
167
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA'
168
+ ```
169
+ #####JRuby:
170
+ ```
171
+ $ 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
+ ```
173
+ See https://www.openssl.org/docs/man1.0.2/apps/ciphers.html for cipher filter format and full list of cipher suites.
207
174
 
208
175
  ### Control/Status Server
209
176
 
210
- Puma comes with a builtin status/control app that can be used to query and control Puma itself. Here is an example of starting Puma with the control server:
211
-
212
- $ puma --control tcp://127.0.0.1:9293 --control-token foo
213
-
214
- This directs Puma to start the control server on localhost port 9293. Additionally, 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.
215
-
216
- ### Configuration file
217
-
218
- You can also provide a configuration file which Puma will use with the `-C` (or `--config`) flag:
219
-
220
- $ puma -C /path/to/config
177
+ Puma has a built-in status/control app that can be used to query and control Puma itself.
221
178
 
222
- By default, 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.
179
+ ```
180
+ $ puma --control-url tcp://127.0.0.1:9293 --control-token foo
181
+ ```
223
182
 
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:
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.
225
184
 
226
- $ puma -C "-"
185
+ You can also interact with the control server via `pumactl`. This command will restart Puma:
227
186
 
228
- Take the following [sample configuration](https://github.com/puma/puma/blob/master/examples/config.rb) as inspiration or check out [configuration.rb](https://github.com/puma/puma/blob/master/lib/puma/configuration.rb) to see all available options.
187
+ ```
188
+ $ pumactl --control-url 'tcp://127.0.0.1:9293' --control-token foo restart
189
+ ```
229
190
 
230
- ## Restart
191
+ To see a list of `pumactl` options, use `pumactl --help`.
231
192
 
232
- Puma includes the ability to restart itself allowing easy upgrades to new versions. When available (MRI, Rubinius, JRuby), Puma performs a "hot restart". This is the same functionality available in *unicorn* and *nginx* which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.
193
+ ### Configuration File
233
194
 
234
- To perform a restart, there are 2 builtin mechanisms:
195
+ You can also provide a configuration file which Puma will use with the `-C` (or `--config`) flag:
235
196
 
236
- * Send the `puma` process the `SIGUSR2` signal
237
- * Use the status server and issue `/restart`
197
+ ```
198
+ $ puma -C /path/to/config
199
+ ```
238
200
 
239
- 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.
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`.
240
202
 
241
- If the new process is unable to load, it will simply exit. You should therefore run Puma under a process monitor (see below) when using it in production.
203
+ 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:
242
204
 
243
- ### Normal vs Hot vs Phased Restart
205
+ ```
206
+ $ puma -C "-"
207
+ ```
244
208
 
245
- A hot restart means that no requests will be lost while deploying your new code, since the server socket is kept open between restarts.
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.
246
210
 
247
- But beware, hot restart does not mean that the incoming requests won’t hang for multiple seconds while your new code has not fully deployed. If you need a zero downtime and zero hanging requests deploy, you must use phased restart.
211
+ ## Restart
248
212
 
249
- When you run pumactl phased-restart, Puma kills workers one-by-one, meaning that at least another worker is still available to serve requests, which lead to zero hanging requests (yay!).
213
+ Puma includes the ability to restart itself. When available (MRI, Rubinius, JRuby), Puma performs a "hot restart". This is the same functionality available in *Unicorn* and *NGINX* which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.
250
214
 
251
- But again beware, upgrading an application sometimes involves upgrading the database schema. With phased restart, there may be a moment during the deployment where processes belonging to the previous version and processes belonging to the new version both exist at the same time. Any database schema upgrades you perform must therefore be backwards-compatible with the old application version.
215
+ For more, see the [restart documentation](https://github.com/puma/puma/blob/master/docs/restart.md).
252
216
 
253
- 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 below).
217
+ ## Signals
254
218
 
255
- ### Puma Signals
219
+ Puma responds to several signals. A detailed guide to using UNIX signals with Puma can be found in the [signals documentation](https://github.com/puma/puma/blob/master/docs/signals.md).
256
220
 
257
- Puma cluster responds to these signals:
221
+ ## Platform Constraints
258
222
 
259
- - `TTIN` increment the worker count by 1
260
- - `TTOU` decrement the worker count by 1
261
- - `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
262
- - `USR2` restart workers
263
- - `USR1` restart workers in phases, a rolling restart.
264
- - `HUP` reopen log files defined in stdout_redirect configuration parameter
265
- - `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
266
- - `CHLD`
223
+ Some platforms do not support all Puma features.
267
224
 
268
- A detailed guide to using UNIX signals with Puma can be found in the [signals documentation](https://github.com/puma/puma/blob/master/docs/signals.md).
225
+ * **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).
269
227
 
270
- ### Release Directory
228
+ ## Known Bugs
271
229
 
272
- If you 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.
230
+ 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:
273
231
 
274
232
  ```ruby
275
- # config/puma.rb
276
-
277
- directory '/var/www/current'
233
+ if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
234
+ begin
235
+ require 'stopgap_13632'
236
+ rescue LoadError
237
+ end
238
+ end
278
239
  ```
279
240
 
280
- ### Cleanup Code
281
-
282
- Puma isn't able to understand all the resources that your app may use, so it provides a hook in the configuration file you pass to `-C` called `on_restart`. The block passed to `on_restart` will be called, unsurprisingly, just before Puma restarts itself.
283
-
284
- You should place code to close global log files, redis connections, etc in this block so that their file descriptors don't leak into the restarted process. Failure to do so will result in slowly running out of descriptors and eventually obscure crashes as the server is restarted many times.
285
-
286
- ### Platform Constraints
287
-
288
- Because of various platforms not being able to implement certain things, the following differences occur when Puma is used on different platforms:
289
-
290
- * **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
291
- * **JRuby**, **Windows**: cluster mode is not supported due to a lack of fork(2)
292
- * **Windows**: daemon mode is not supported due to a lack of fork(2)
293
-
294
- ## pumactl
295
-
296
- `pumactl` is a simple CLI frontend to the control/status app described above. Please refer to `pumactl --help` for available commands.
241
+ ## Deployment
297
242
 
298
- ## Process Monitors
243
+ Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
299
244
 
300
- Process monitors or supervisors will at minimum provide start of Puma
301
- on system boot. Modern process monitors like systemd or upstart
302
- further provide continuous monitoring and restarts for increased
245
+ It is common to use process monitors with Puma. Modern process monitors like systemd or upstart
246
+ provide continuous monitoring and restarts for increased
303
247
  reliability in production environments:
304
248
 
305
249
  * [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for sysvinit (init.d) and upstart
306
250
  * [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
307
251
 
308
- ## Capistrano deployment
309
-
310
- Puma has support for Capistrano3 with an [external gem](https://github.com/seuros/capistrano-puma), you just need require that in Gemfile:
311
-
312
- ```ruby
313
- gem 'capistrano3-puma'
314
- ```
315
- And then execute:
316
-
317
- ```bash
318
- bundle
319
- ```
320
-
321
- Then add to Capfile
322
-
323
- ```ruby
324
- require 'capistrano/puma'
325
- ```
326
-
327
- and then
328
-
329
- ```bash
330
- $ bundle exec cap puma:start
331
- $ bundle exec cap puma:restart
332
- $ bundle exec cap puma:stop
333
- $ bundle exec cap puma:phased-restart
334
- ```
335
-
336
252
  ## Contributing
337
253
 
338
254
  To run the test suite:
@@ -344,4 +260,4 @@ $ bundle exec rake
344
260
 
345
261
  ## License
346
262
 
347
- Puma is copyright 2014 Evan Phoenix and contributors. It is licensed under the BSD 3-Clause license. See the included LICENSE file for details.
263
+ Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.