puma 3.0.0.rc1 → 5.0.0.beta1

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 (91) hide show
  1. checksums.yaml +5 -5
  2. data/{History.txt → History.md} +703 -70
  3. data/LICENSE +23 -20
  4. data/README.md +173 -163
  5. data/docs/architecture.md +37 -0
  6. data/{DEPLOYMENT.md → docs/deployment.md} +28 -6
  7. data/docs/fork_worker.md +31 -0
  8. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  9. data/docs/images/puma-connection-flow.png +0 -0
  10. data/docs/images/puma-general-arch.png +0 -0
  11. data/docs/jungle/README.md +13 -0
  12. data/docs/jungle/rc.d/README.md +74 -0
  13. data/docs/jungle/rc.d/puma +61 -0
  14. data/docs/jungle/rc.d/puma.conf +10 -0
  15. data/{tools → docs}/jungle/upstart/README.md +0 -0
  16. data/{tools → docs}/jungle/upstart/puma-manager.conf +0 -0
  17. data/{tools → docs}/jungle/upstart/puma.conf +1 -1
  18. data/docs/nginx.md +2 -2
  19. data/docs/plugins.md +38 -0
  20. data/docs/restart.md +41 -0
  21. data/docs/signals.md +57 -3
  22. data/docs/systemd.md +228 -0
  23. data/ext/puma_http11/PumaHttp11Service.java +2 -2
  24. data/ext/puma_http11/extconf.rb +16 -0
  25. data/ext/puma_http11/http11_parser.c +287 -468
  26. data/ext/puma_http11/http11_parser.h +1 -0
  27. data/ext/puma_http11/http11_parser.java.rl +21 -37
  28. data/ext/puma_http11/http11_parser.rl +10 -9
  29. data/ext/puma_http11/http11_parser_common.rl +4 -4
  30. data/ext/puma_http11/mini_ssl.c +159 -10
  31. data/ext/puma_http11/org/jruby/puma/Http11.java +108 -116
  32. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +99 -132
  33. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +30 -6
  34. data/ext/puma_http11/puma_http11.c +6 -38
  35. data/lib/puma.rb +25 -5
  36. data/lib/puma/accept_nonblock.rb +7 -1
  37. data/lib/puma/app/status.rb +53 -26
  38. data/lib/puma/binder.rb +150 -119
  39. data/lib/puma/cli.rb +56 -38
  40. data/lib/puma/client.rb +277 -80
  41. data/lib/puma/cluster.rb +326 -130
  42. data/lib/puma/commonlogger.rb +21 -20
  43. data/lib/puma/configuration.rb +160 -161
  44. data/lib/puma/const.rb +50 -47
  45. data/lib/puma/control_cli.rb +104 -63
  46. data/lib/puma/detect.rb +13 -1
  47. data/lib/puma/dsl.rb +463 -114
  48. data/lib/puma/events.rb +22 -13
  49. data/lib/puma/io_buffer.rb +9 -5
  50. data/lib/puma/jruby_restart.rb +2 -59
  51. data/lib/puma/launcher.rb +195 -105
  52. data/lib/puma/minissl.rb +110 -4
  53. data/lib/puma/minissl/context_builder.rb +76 -0
  54. data/lib/puma/null_io.rb +9 -14
  55. data/lib/puma/plugin.rb +32 -12
  56. data/lib/puma/plugin/tmp_restart.rb +19 -6
  57. data/lib/puma/rack/builder.rb +7 -5
  58. data/lib/puma/rack/urlmap.rb +11 -8
  59. data/lib/puma/rack_default.rb +2 -0
  60. data/lib/puma/reactor.rb +242 -32
  61. data/lib/puma/runner.rb +41 -30
  62. data/lib/puma/server.rb +265 -183
  63. data/lib/puma/single.rb +22 -63
  64. data/lib/puma/state_file.rb +9 -2
  65. data/lib/puma/thread_pool.rb +179 -68
  66. data/lib/puma/util.rb +3 -11
  67. data/lib/rack/handler/puma.rb +60 -11
  68. data/tools/Dockerfile +16 -0
  69. data/tools/trickletest.rb +1 -2
  70. metadata +35 -99
  71. data/COPYING +0 -55
  72. data/Gemfile +0 -13
  73. data/Manifest.txt +0 -79
  74. data/Rakefile +0 -158
  75. data/docs/config.md +0 -0
  76. data/ext/puma_http11/io_buffer.c +0 -155
  77. data/lib/puma/capistrano.rb +0 -94
  78. data/lib/puma/compat.rb +0 -18
  79. data/lib/puma/convenient.rb +0 -23
  80. data/lib/puma/daemon_ext.rb +0 -31
  81. data/lib/puma/delegation.rb +0 -11
  82. data/lib/puma/java_io_buffer.rb +0 -45
  83. data/lib/puma/rack/backports/uri/common_18.rb +0 -56
  84. data/lib/puma/rack/backports/uri/common_192.rb +0 -52
  85. data/lib/puma/rack/backports/uri/common_193.rb +0 -29
  86. data/lib/puma/tcp_logger.rb +0 -32
  87. data/puma.gemspec +0 -52
  88. data/tools/jungle/README.md +0 -9
  89. data/tools/jungle/init.d/README.md +0 -54
  90. data/tools/jungle/init.d/puma +0 -394
  91. data/tools/jungle/init.d/run-puma +0 -3
data/LICENSE CHANGED
@@ -1,26 +1,29 @@
1
- Some code copyright (c) 2005, Zed Shaw
2
- Copyright (c) 2011, Evan Phoenix
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2019, Evan Phoenix. Some code by Zed Shaw, (c) 2005.
3
4
  All rights reserved.
4
5
 
5
- Redistribution and use in source and binary forms, with or without
6
+ Redistribution and use in source and binary forms, with or without
6
7
  modification, are permitted provided that the following conditions are met:
7
8
 
8
- * Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
- * Redistributions in binary form must reproduce the above copyright notice
11
- this list of conditions and the following disclaimer in the documentation
12
- and/or other materials provided with the distribution.
13
- * Neither the name of the Evan Phoenix nor the names of its contributors
14
- may be used to endorse or promote products derived from this software
15
- without specific prior written permission.
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
16
19
 
17
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
29
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,149 +1,136 @@
1
+ <p align="center">
2
+ <img src="https://puma.io/images/logos/puma-logo-large.png">
3
+ </p>
4
+
1
5
  # Puma: A Ruby Web Server Built For Concurrency
2
6
 
3
- [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/puma/puma?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
4
- [![Build Status](https://secure.travis-ci.org/puma/puma.svg)](http://travis-ci.org/puma/puma)
5
- [![Dependency Status](https://gemnasium.com/puma/puma.svg)](https://gemnasium.com/puma/puma)
6
- [![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
7
+ [![Actions Build Status](https://github.com/puma/puma/workflows/CI/badge.svg?branch=master)](https://github.com/puma/puma/actions)
7
8
 
8
- ## Description
9
+ [![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
10
+ [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=puma&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=puma&package-manager=bundler&version-scheme=semver)
11
+ [![StackOverflow](http://img.shields.io/badge/stackoverflow-Puma-blue.svg)]( http://stackoverflow.com/questions/tagged/puma )
9
12
 
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, multi-threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications**.
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
+ 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.
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](https://rubinius.com), 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 IO waiting to be done in parallel.
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
- ## Advanced Setup
33
-
34
- ### Sinatra
35
-
36
- You can run your Sinatra application with Puma from the command line like this:
37
-
38
- $ ruby app.rb -s Puma
39
-
40
- Or you can configure your application to always use Puma:
25
+ ```
26
+ $ gem install puma
27
+ $ puma
28
+ ```
41
29
 
42
- require 'sinatra'
43
- configure { set :server, :puma }
30
+ Without arguments, puma will look for a rackup (.ru) file in
31
+ working directory called `config.ru`.
44
32
 
45
- If you use Bundler, make sure you add Puma to your Gemfile (see below).
33
+ ## Frameworks
46
34
 
47
35
  ### Rails
48
36
 
49
- First, make sure Puma is in your Gemfile:
37
+ Puma is the default server for Rails, included in the generated Gemfile.
50
38
 
51
- gem 'puma'
39
+ Start your server with the `rails` command:
52
40
 
53
- Then start your server with the `rails` command:
41
+ ```
42
+ $ rails server
43
+ ```
54
44
 
55
- $ rails s Puma
45
+ Many configuration options and Puma features are not available when using `rails server`. It is recommended that you use Puma's executable instead:
56
46
 
57
- ### Rackup
47
+ ```
48
+ $ bundle exec puma
49
+ ```
58
50
 
59
- You can pass it as an option to `rackup`:
51
+ ### Sinatra
52
+
53
+ You can run your Sinatra application with Puma from the command line like this:
60
54
 
61
- $ rackup -s Puma
55
+ ```
56
+ $ ruby app.rb -s Puma
57
+ ```
62
58
 
63
- Alternatively, you can modify your `config.ru` to choose Puma by default, by adding the following as the first line:
59
+ Or you can configure your Sinatra application to always use Puma:
64
60
 
65
- #\ -s puma
61
+ ```ruby
62
+ require 'sinatra'
63
+ configure { set :server, :puma }
64
+ ```
66
65
 
67
66
  ## Configuration
68
67
 
69
- Puma provides numerous options for controlling the operation of the server. Consult `puma -h` (or `puma --help`) for a full list.
68
+ Puma provides numerous options. Consult `puma -h` (or `puma --help`) for a full list of CLI options, or see [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb).
69
+
70
+ You can also find several configuration examples as part of the
71
+ [test](https://github.com/puma/puma/tree/master/test/config) suite.
70
72
 
71
73
  ### Thread Pool
72
74
 
73
- 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:
75
+ 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:
76
+
77
+ ```
78
+ $ puma -t 8:32
79
+ ```
74
80
 
75
- $ puma -t 8:32
81
+ Puma will automatically scale the number of threads, from the minimum until it caps out at the maximum, based on how much traffic is present. The current default is `0:16` and on MRI is `0:5`. Feel free to experiment, but be careful not to set the number of maximum threads to a large number, as you may exhaust resources on the system (or cause contention for the Global VM Lock, when using MRI).
76
82
 
77
- Puma will automatically scale the number of threads 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).
83
+ Be aware that additionally Puma creates threads on its own for internal purposes (e.g. handling slow clients). So, even if you specify -t 1:1, expect around 7 threads created in your application.
78
84
 
79
85
  ### Clustered mode
80
86
 
81
- 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:
82
-
83
- $ puma -t 8:32 -w 3
87
+ 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:
84
88
 
85
- On a ruby implementation that offers native threads, you should tune this number to match the number of cores available.
86
- 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.
89
+ ```
90
+ $ puma -t 8:32 -w 3
91
+ ```
87
92
 
88
- 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:
93
+ 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.
89
94
 
90
- # CLI invocation
91
- $ puma -t 8:32 -w 3 --preload
95
+ 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:
92
96
 
93
- 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:
97
+ ```
98
+ $ puma -w 3 --preload
99
+ ```
94
100
 
95
- $ puma -C config/puma.rb
101
+ If you're using a configuration file, use the `preload_app!` method:
96
102
 
97
- # config/puma.rb
98
- threads 8,32
99
- workers 3
100
- preload_app!
103
+ ```ruby
104
+ # config/puma.rb
105
+ workers 3
106
+ preload_app!
107
+ ```
101
108
 
102
109
  Additionally, you can specify a block in your configuration file that will be run on boot of each worker:
103
110
 
104
- # config/puma.rb
105
- on_worker_boot do
106
- # configuration here
107
- end
111
+ ```ruby
112
+ # config/puma.rb
113
+ on_worker_boot do
114
+ # configuration here
115
+ end
116
+ ```
108
117
 
109
118
  This code can be used to setup the process before booting the application, allowing
110
119
  you to do some Puma-specific things that you don't want to embed in your application.
111
- For instance, you could fire a log notification that a worker booted or send something to statsd.
112
- This can be called multiple times to add hooks.
113
-
114
- If you're preloading your application and using ActiveRecord, it's recommend you setup your connection pool here:
115
-
116
- # config/puma.rb
117
- on_worker_boot do
118
- ActiveSupport.on_load(:active_record) do
119
- ActiveRecord::Base.establish_connection
120
- end
121
- end
122
-
123
- On top of that, you can specify a block in your configuration file that will be run before workers are forked
124
-
125
- # config/puma.rb
126
- before_fork do
127
- # configuration here
128
- end
129
-
130
- This code can be used to clean up before forking to clients, allowing
131
- you to do some Puma-specific things that you don't want to embed in your application.
132
-
133
- If you're preloading your application and using ActiveRecord, it's recommend you close any connections to the database here to prevent connection leakage:
134
-
135
- # config/puma.rb
136
- before_fork do
137
- ActiveRecord::Base.connection_pool.disconnect!
138
- end
120
+ For instance, you could fire a log notification that a worker booted or send something to statsd. This can be called multiple times.
139
121
 
140
- This rule applies to any connections to external services (Redis, databases, memcache, ...) that might be started automatically by the framework.
122
+ `before_fork` specifies a block to be run before workers are forked:
141
123
 
142
- When you use preload_app, your new code goes all in the master process, and is then copied in 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.
124
+ ```ruby
125
+ # config/puma.rb
126
+ before_fork do
127
+ # configuration here
128
+ end
129
+ ```
143
130
 
144
- 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.
131
+ 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.
145
132
 
146
- ### Error handler for low-level errors
133
+ ### Error handling
147
134
 
148
135
  If puma encounters an error outside of the context of your application, it will respond with a 500 and a simple
149
136
  textual error message (see `lowlevel_error` in [this file](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
@@ -159,129 +146,152 @@ end
159
146
 
160
147
  ### Binding TCP / Sockets
161
148
 
162
- In contrast to many other server configs which require multiple flags, Puma simply uses one URI parameter with the `-b` (or `--bind`) flag:
149
+ Bind Puma to a socket with the `-b` (or `--bind`) flag:
163
150
 
164
- $ puma -b tcp://127.0.0.1:9292
151
+ ```
152
+ $ puma -b tcp://127.0.0.1:9292
153
+ ```
165
154
 
166
- Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)? No problem!
155
+ To use a UNIX Socket instead of TCP:
167
156
 
168
- $ puma -b unix:///var/run/puma.sock
157
+ ```
158
+ $ puma -b unix:///var/run/puma.sock
159
+ ```
169
160
 
170
161
  If you need to change the permissions of the UNIX socket, just add a umask parameter:
171
162
 
172
- $ puma -b 'unix:///var/run/puma.sock?umask=0111'
173
-
174
- Need a bit of security? Use SSL sockets!
175
-
176
- $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
163
+ ```
164
+ $ puma -b 'unix:///var/run/puma.sock?umask=0111'
165
+ ```
177
166
 
178
- ### Control/Status Server
167
+ Need a bit of security? Use SSL sockets:
179
168
 
180
- Puma comes with a builtin status/control app that can be used query and control Puma itself. Here is an example of starting Puma with the control server:
169
+ ```
170
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
171
+ ```
181
172
 
182
- $ puma --control tcp://127.0.0.1:9293 --control-token foo
173
+ #### Controlling SSL Cipher Suites
183
174
 
184
- 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.
175
+ To use or avoid specific SSL cipher suites, use `ssl_cipher_filter` or `ssl_cipher_list` options.
185
176
 
186
- ### Configuration file
177
+ ##### Ruby:
187
178
 
188
- You can also provide a configuration file which Puma will use with the `-C` (or `--config`) flag:
179
+ ```
180
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA'
181
+ ```
189
182
 
190
- $ puma -C /path/to/config
183
+ ##### JRuby:
191
184
 
192
- 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.
185
+ ```
186
+ $ 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'
187
+ ```
193
188
 
194
- 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:
189
+ See https://www.openssl.org/docs/man1.0.2/apps/ciphers.html for cipher filter format and full list of cipher suites.
195
190
 
196
- $ puma -C "-"
191
+ Disable TLS v1 with the `no_tlsv1` option:
197
192
 
198
- 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.
193
+ ```
194
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true'
195
+ ```
199
196
 
200
- ## Restart
197
+ ### Control/Status Server
201
198
 
202
- 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.
199
+ Puma has a built-in status and control app that can be used to query and control Puma.
203
200
 
204
- To perform a restart, there are 2 builtin mechanisms:
201
+ ```
202
+ $ puma --control-url tcp://127.0.0.1:9293 --control-token foo
203
+ ```
205
204
 
206
- * Send the `puma` process the `SIGUSR2` signal
207
- * Use the status server and issue `/restart`
205
+ 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.
208
206
 
209
- 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.
207
+ You can also interact with the control server via `pumactl`. This command will restart Puma:
210
208
 
211
- If the new process is unable to load, it will simply exit. You should therefore run Puma under a supervisor when using it in production.
209
+ ```
210
+ $ pumactl --control-url 'tcp://127.0.0.1:9293' --control-token foo restart
211
+ ```
212
212
 
213
- ### Normal vs Hot vs Phased Restart
213
+ To see a list of `pumactl` options, use `pumactl --help`.
214
214
 
215
- A hot restart means that no requests while deploying your new code will be lost, since the server socket is kept open between restarts.
215
+ ### Configuration File
216
216
 
217
- 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.
217
+ You can also provide a configuration file with the `-C` (or `--config`) flag:
218
218
 
219
- 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 in zero hanging request (yay!).
219
+ ```
220
+ $ puma -C /path/to/config
221
+ ```
220
222
 
221
- 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.
223
+ If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` or the `RAILS_ENV` environment variables, Puma looks for configuration at `config/puma/<environment_name>.rb`.
222
224
 
223
- 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).
225
+ If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:
224
226
 
227
+ ```
228
+ $ puma -C "-"
229
+ ```
225
230
 
226
- ### Cleanup Code
231
+ The other side-effects of setting the environment are whether to show stack traces (in `development` or `test`), and setting RACK_ENV may potentially affect middleware looking for this value to change their behavior. The default puma RACK_ENV value is `development`. You can see all config default values [here](https://github.com/puma/puma/blob/12d1706ddc71b89ed2ee26275e31c788e94ff541/lib/puma/configuration.rb#L170).
227
232
 
228
- 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.
233
+ Check out [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb) to see all available options.
229
234
 
230
- 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 restart many times.
235
+ ## Restart
231
236
 
232
- ### Platform Constraints
237
+ 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.
233
238
 
234
- Because of various platforms not being implement certain things, the following differences occur when Puma is used on different platforms:
239
+ For more, see the [restart documentation](https://github.com/puma/puma/blob/master/docs/restart.md).
235
240
 
236
- * **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
237
- * **JRuby**, **Windows**: cluster mode is not supported due to a lack of fork(2)
238
- * **Windows**: daemon mode is not supported due to a lack of fork(2)
241
+ ## Signals
239
242
 
240
- ## pumactl
243
+ 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).
241
244
 
242
- `pumactl` is a simple CLI frontend to the control/status app described above. Please refer to `pumactl --help` for available commands.
245
+ ## Platform Constraints
243
246
 
244
- ## Managing multiple Pumas / init.d / upstart scripts
247
+ Some platforms do not support all Puma features.
245
248
 
246
- If you want an easy way to manage multiple scripts at once check [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for init.d and upstart scripts.
249
+ * **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).
250
+ * **Windows**: Cluster mode is not supported due to a lack of fork(2).
247
251
 
248
- ## Capistrano deployment
252
+ ## Known Bugs
249
253
 
250
- Puma has support for Capistrano3 with an [external gem](https://github.com/seuros/capistrano-puma), you just need require that in Gemfile:
254
+ For MRI versions 2.2.7, 2.2.8, 2.2.9, 2.2.10, 2.3.4 and 2.4.1, you may see ```stream closed in another thread (IOError)```. It may be caused by a [Ruby bug](https://bugs.ruby-lang.org/issues/13632). It can be fixed with the gem https://rubygems.org/gems/stopgap_13632:
251
255
 
252
256
  ```ruby
253
- gem 'capistrano3-puma'
257
+ if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
258
+ begin
259
+ require 'stopgap_13632'
260
+ rescue LoadError
261
+ end
262
+ end
254
263
  ```
255
- And then execute:
256
264
 
257
- ```bash
258
- bundle
259
- ```
265
+ ## Deployment
260
266
 
261
- Then add to Capfile
267
+ Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
262
268
 
263
- ```ruby
264
- require 'capistrano/puma'
265
- ```
269
+ It is common to use process monitors with Puma. Modern process monitors like systemd or upstart
270
+ provide continuous monitoring and restarts for increased
271
+ reliability in production environments:
266
272
 
267
- and then
273
+ * [docs/jungle](https://github.com/puma/puma/tree/master/docs/jungle) for rc.d and upstart
274
+ * [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
268
275
 
269
- ```bash
270
- $ bundle exec cap puma:start
271
- $ bundle exec cap puma:restart
272
- $ bundle exec cap puma:stop
273
- $ bundle exec cap puma:phased-restart
274
- ```
276
+ ## Community Extensions
277
+
278
+ ### Plugins
279
+
280
+ * [puma-heroku](https://github.com/puma/puma-heroku) — default Puma configuration for running on Heroku
281
+ * [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
282
+ * [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
283
+ * [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog
284
+
285
+ ### Monitoring
286
+
287
+ * [puma-status](https://github.com/ylecuyer/puma-status) — Monitor CPU/Mem/Load of running puma instances from the CLI
275
288
 
276
289
  ## Contributing
277
290
 
278
- To run the test suite:
291
+ Find details for contributing in the [contribution guide].
279
292
 
280
- ```bash
281
- $ bundle install
282
- $ bundle exec rake
283
- ```
293
+ [contribution guide]: https://github.com/puma/puma/blob/master/CONTRIBUTING.md
284
294
 
285
295
  ## License
286
296
 
287
- Puma is copyright 2014 Evan Phoenix and contributors. It is licensed under the BSD 3-Clause license. See the include LICENSE file for details.
297
+ Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.