jun-puma 1.0.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/History.md +2897 -0
- data/LICENSE +29 -0
- data/README.md +475 -0
- data/bin/puma +10 -0
- data/bin/puma-wild +25 -0
- data/bin/pumactl +12 -0
- data/docs/architecture.md +74 -0
- data/docs/compile_options.md +55 -0
- data/docs/deployment.md +102 -0
- data/docs/fork_worker.md +35 -0
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/jungle/README.md +9 -0
- data/docs/jungle/rc.d/README.md +74 -0
- data/docs/jungle/rc.d/puma +61 -0
- data/docs/jungle/rc.d/puma.conf +10 -0
- data/docs/kubernetes.md +78 -0
- data/docs/nginx.md +80 -0
- data/docs/plugins.md +38 -0
- data/docs/rails_dev_mode.md +28 -0
- data/docs/restart.md +65 -0
- data/docs/signals.md +98 -0
- data/docs/stats.md +142 -0
- data/docs/systemd.md +253 -0
- data/docs/testing_benchmarks_local_files.md +150 -0
- data/docs/testing_test_rackup_ci_files.md +36 -0
- data/ext/puma_http11/PumaHttp11Service.java +17 -0
- data/ext/puma_http11/ext_help.h +15 -0
- data/ext/puma_http11/extconf.rb +80 -0
- data/ext/puma_http11/http11_parser.c +1057 -0
- data/ext/puma_http11/http11_parser.h +65 -0
- data/ext/puma_http11/http11_parser.java.rl +145 -0
- data/ext/puma_http11/http11_parser.rl +149 -0
- data/ext/puma_http11/http11_parser_common.rl +54 -0
- data/ext/puma_http11/mini_ssl.c +842 -0
- data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
- data/ext/puma_http11/org/jruby/puma/Http11.java +228 -0
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +455 -0
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +509 -0
- data/ext/puma_http11/puma_http11.c +495 -0
- data/lib/puma/app/status.rb +96 -0
- data/lib/puma/binder.rb +502 -0
- data/lib/puma/cli.rb +247 -0
- data/lib/puma/client.rb +682 -0
- data/lib/puma/cluster/worker.rb +180 -0
- data/lib/puma/cluster/worker_handle.rb +96 -0
- data/lib/puma/cluster.rb +616 -0
- data/lib/puma/commonlogger.rb +115 -0
- data/lib/puma/configuration.rb +390 -0
- data/lib/puma/const.rb +307 -0
- data/lib/puma/control_cli.rb +316 -0
- data/lib/puma/detect.rb +45 -0
- data/lib/puma/dsl.rb +1425 -0
- data/lib/puma/error_logger.rb +113 -0
- data/lib/puma/events.rb +57 -0
- data/lib/puma/io_buffer.rb +46 -0
- data/lib/puma/jruby_restart.rb +11 -0
- data/lib/puma/json_serialization.rb +96 -0
- data/lib/puma/launcher/bundle_pruner.rb +104 -0
- data/lib/puma/launcher.rb +488 -0
- data/lib/puma/log_writer.rb +147 -0
- data/lib/puma/minissl/context_builder.rb +96 -0
- data/lib/puma/minissl.rb +459 -0
- data/lib/puma/null_io.rb +84 -0
- data/lib/puma/plugin/systemd.rb +90 -0
- data/lib/puma/plugin/tmp_restart.rb +36 -0
- data/lib/puma/plugin.rb +111 -0
- data/lib/puma/puma_http11.jar +0 -0
- data/lib/puma/rack/builder.rb +297 -0
- data/lib/puma/rack/urlmap.rb +93 -0
- data/lib/puma/rack_default.rb +24 -0
- data/lib/puma/reactor.rb +125 -0
- data/lib/puma/request.rb +688 -0
- data/lib/puma/runner.rb +213 -0
- data/lib/puma/sd_notify.rb +149 -0
- data/lib/puma/server.rb +680 -0
- data/lib/puma/single.rb +69 -0
- data/lib/puma/state_file.rb +68 -0
- data/lib/puma/thread_pool.rb +434 -0
- data/lib/puma/util.rb +141 -0
- data/lib/puma.rb +78 -0
- data/lib/rack/handler/puma.rb +144 -0
- data/tools/Dockerfile +16 -0
- data/tools/trickletest.rb +44 -0
- metadata +153 -0
data/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2019, Evan Phoenix. Some code by Zed Shaw, (c) 2005.
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
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.
|
19
|
+
|
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
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,475 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<img src="https://puma.io/images/logos/puma-logo-large.png">
|
3
|
+
</p>
|
4
|
+
|
5
|
+
# Puma: A Ruby Web Server Built For Parallelism
|
6
|
+
|
7
|
+
[](https://github.com/puma/puma/actions?query=workflow%3ATests)
|
8
|
+
[](https://codeclimate.com/github/puma/puma)
|
9
|
+
[]( https://stackoverflow.com/questions/tagged/puma )
|
10
|
+
|
11
|
+
Puma is a **simple, fast, multi-threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications**.
|
12
|
+
|
13
|
+
## Built For Speed & Parallelism
|
14
|
+
|
15
|
+
Puma is a server for [Rack](https://github.com/rack/rack)-powered HTTP applications written in Ruby. It is:
|
16
|
+
* **Multi-threaded**. Each request is served in a separate thread. This helps you serve more requests per second with less memory use.
|
17
|
+
* **Multi-process**. "Pre-forks" in cluster mode, using less memory per-process thanks to copy-on-write memory.
|
18
|
+
* **Standalone**. With SSL support, zero-downtime rolling restarts and a built-in request bufferer, you can deploy Puma without any reverse proxy.
|
19
|
+
* **Battle-tested**. Our HTTP parser is inherited from Mongrel and has over 15 years of production use. Puma is currently the most popular Ruby webserver, and is the default server for Ruby on Rails.
|
20
|
+
|
21
|
+
Originally designed as a server for [Rubinius](https://github.com/rubinius/rubinius), Puma also works well with Ruby (MRI) and JRuby.
|
22
|
+
|
23
|
+
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. Truly parallel Ruby implementations (TruffleRuby, JRuby) don't have this limitation.
|
24
|
+
|
25
|
+
## Quick Start
|
26
|
+
|
27
|
+
```
|
28
|
+
$ gem install puma
|
29
|
+
$ puma
|
30
|
+
```
|
31
|
+
|
32
|
+
Without arguments, puma will look for a rackup (.ru) file in
|
33
|
+
working directory called `config.ru`.
|
34
|
+
|
35
|
+
## SSL Connection Support
|
36
|
+
|
37
|
+
Puma will install/compile with support for ssl sockets, assuming OpenSSL
|
38
|
+
development files are installed on the system.
|
39
|
+
|
40
|
+
If the system does not have OpenSSL development files installed, Puma will
|
41
|
+
install/compile, but it will not allow ssl connections.
|
42
|
+
|
43
|
+
## Frameworks
|
44
|
+
|
45
|
+
### Rails
|
46
|
+
|
47
|
+
Puma is the default server for Rails, included in the generated Gemfile.
|
48
|
+
|
49
|
+
Start your server with the `rails` command:
|
50
|
+
|
51
|
+
```
|
52
|
+
$ rails server
|
53
|
+
```
|
54
|
+
|
55
|
+
Many configuration options and Puma features are not available when using `rails server`. It is recommended that you use Puma's executable instead:
|
56
|
+
|
57
|
+
```
|
58
|
+
$ bundle exec puma
|
59
|
+
```
|
60
|
+
|
61
|
+
### Sinatra
|
62
|
+
|
63
|
+
You can run your Sinatra application with Puma from the command line like this:
|
64
|
+
|
65
|
+
```
|
66
|
+
$ ruby app.rb -s Puma
|
67
|
+
```
|
68
|
+
|
69
|
+
In order to actually configure Puma using a config file, like `puma.rb`, however, you need to use the `puma` executable. To do this, you must add a rackup file to your Sinatra app:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# config.ru
|
73
|
+
require './app'
|
74
|
+
run Sinatra::Application
|
75
|
+
```
|
76
|
+
|
77
|
+
You can then start your application using:
|
78
|
+
|
79
|
+
```
|
80
|
+
$ bundle exec puma
|
81
|
+
```
|
82
|
+
|
83
|
+
## Configuration
|
84
|
+
|
85
|
+
Puma provides numerous options. Consult `puma -h` (or `puma --help`) for a full list of CLI options, or see `Puma::DSL` or [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb).
|
86
|
+
|
87
|
+
You can also find several configuration examples as part of the
|
88
|
+
[test](https://github.com/puma/puma/tree/master/test/config) suite.
|
89
|
+
|
90
|
+
For debugging purposes, you can set the environment variable `PUMA_LOG_CONFIG` with a value
|
91
|
+
and the loaded configuration will be printed as part of the boot process.
|
92
|
+
|
93
|
+
### Thread Pool
|
94
|
+
|
95
|
+
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:
|
96
|
+
|
97
|
+
```
|
98
|
+
$ puma -t 8:32
|
99
|
+
```
|
100
|
+
|
101
|
+
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).
|
102
|
+
|
103
|
+
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.
|
104
|
+
|
105
|
+
### Clustered mode
|
106
|
+
|
107
|
+
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:
|
108
|
+
|
109
|
+
```
|
110
|
+
$ puma -t 8:32 -w 3
|
111
|
+
```
|
112
|
+
|
113
|
+
Or with the `WEB_CONCURRENCY` environment variable:
|
114
|
+
|
115
|
+
```
|
116
|
+
$ WEB_CONCURRENCY=3 puma -t 8:32
|
117
|
+
```
|
118
|
+
|
119
|
+
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.
|
120
|
+
|
121
|
+
For an in-depth discussion of the tradeoffs of thread and process count settings, [see our docs](https://github.com/puma/puma/blob/9282a8efa5a0c48e39c60d22ca70051a25df9f55/docs/kubernetes.md#workers-per-pod-and-other-config-issues).
|
122
|
+
|
123
|
+
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).
|
124
|
+
|
125
|
+
If the `WEB_CONCURRENCY` environment variable is set to a value > 1 (and `--prune-bundler` has not been specified), preloading will be enabled by default. Otherwise, you can use the `--preload` flag from the command line:
|
126
|
+
|
127
|
+
```
|
128
|
+
$ puma -w 3 --preload
|
129
|
+
```
|
130
|
+
|
131
|
+
Or, if you're using a configuration file, you can use the `preload_app!` method:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
# config/puma.rb
|
135
|
+
workers 3
|
136
|
+
preload_app!
|
137
|
+
```
|
138
|
+
|
139
|
+
Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preloading copies the code of master into the workers.
|
140
|
+
|
141
|
+
#### Clustered mode hooks
|
142
|
+
|
143
|
+
When using clustered mode, Puma's configuration DSL provides `before_fork` and `on_worker_boot`
|
144
|
+
hooks to run code when the master process forks and child workers are booted respectively.
|
145
|
+
|
146
|
+
It is recommended to use these hooks with `preload_app!`, otherwise constants loaded by your
|
147
|
+
application (such as `Rails`) will not be available inside the hooks.
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
# config/puma.rb
|
151
|
+
before_fork do
|
152
|
+
# Add code to run inside the Puma master process before it forks a worker child.
|
153
|
+
end
|
154
|
+
|
155
|
+
on_worker_boot do
|
156
|
+
# Add code to run inside the Puma worker process after forking.
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
In addition, there is an `on_refork` hook which is used only in [`fork_worker` mode](docs/fork_worker.md),
|
161
|
+
when the worker 0 child process forks a grandchild worker:
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
on_refork do
|
165
|
+
# Used only when fork_worker mode is enabled. Add code to run inside the Puma worker 0
|
166
|
+
# child process before it forks a grandchild worker.
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
Importantly, note the following considerations when Ruby forks a child process:
|
171
|
+
|
172
|
+
1. File descriptors such as network sockets **are** copied from the parent to the forked
|
173
|
+
child process. Dual-use of the same sockets by parent and child will result in I/O conflicts
|
174
|
+
such as `SocketError`, `Errno::EPIPE`, and `EOFError`.
|
175
|
+
2. Background Ruby threads, including threads used by various third-party gems for connection
|
176
|
+
monitoring, etc., are **not** copied to the child process. Often this does not cause
|
177
|
+
immediate problems until a third-party connection goes down, at which point there will
|
178
|
+
be no supervisor to reconnect it.
|
179
|
+
|
180
|
+
Therefore, we recommend the following:
|
181
|
+
|
182
|
+
1. If possible, do not establish any socket connections (HTTP, database connections, etc.)
|
183
|
+
inside Puma's master process when booting.
|
184
|
+
2. If (1) is not possible, use `before_fork` and `on_refork` to disconnect the parent's socket
|
185
|
+
connections when forking, so that they are not accidentally copied to the child process.
|
186
|
+
3. Use `on_worker_boot` to restart any background threads on the forked child.
|
187
|
+
|
188
|
+
#### Master process lifecycle hooks
|
189
|
+
|
190
|
+
Puma's configuration DSL provides master process lifecycle hooks `on_booted`, `on_restart`, and `on_stopped`
|
191
|
+
which may be used to specify code blocks to run on each event:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
# config/puma.rb
|
195
|
+
on_booted do
|
196
|
+
# Add code to run in the Puma master process after it boots,
|
197
|
+
# and also after a phased restart completes.
|
198
|
+
end
|
199
|
+
|
200
|
+
on_restart do
|
201
|
+
# Add code to run in the Puma master process when it receives
|
202
|
+
# a restart command but before it restarts.
|
203
|
+
end
|
204
|
+
|
205
|
+
on_stopped do
|
206
|
+
# Add code to run in the Puma master process when it receives
|
207
|
+
# a stop command but before it shuts down.
|
208
|
+
end
|
209
|
+
```
|
210
|
+
|
211
|
+
### Error handling
|
212
|
+
|
213
|
+
If Puma encounters an error outside of the context of your application, it will respond with a 400/500 and a simple
|
214
|
+
textual error message (see `Puma::Server#lowlevel_error` or [server.rb](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
|
215
|
+
You can specify custom behavior for this scenario. For example, you can report the error to your third-party
|
216
|
+
error-tracking service (in this example, [rollbar](https://rollbar.com)):
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
lowlevel_error_handler do |e, env, status|
|
220
|
+
if status == 400
|
221
|
+
message = "The server could not process the request due to an error, such as an incorrectly typed URL, malformed syntax, or a URL that contains illegal characters.\n"
|
222
|
+
else
|
223
|
+
message = "An error has occurred, and engineers have been informed. Please reload the page. If you continue to have problems, contact support@example.com\n"
|
224
|
+
Rollbar.critical(e)
|
225
|
+
end
|
226
|
+
|
227
|
+
[status, {}, [message]]
|
228
|
+
end
|
229
|
+
```
|
230
|
+
|
231
|
+
### Binding TCP / Sockets
|
232
|
+
|
233
|
+
Bind Puma to a socket with the `-b` (or `--bind`) flag:
|
234
|
+
|
235
|
+
```
|
236
|
+
$ puma -b tcp://127.0.0.1:9292
|
237
|
+
```
|
238
|
+
|
239
|
+
To use a UNIX Socket instead of TCP:
|
240
|
+
|
241
|
+
```
|
242
|
+
$ puma -b unix:///var/run/puma.sock
|
243
|
+
```
|
244
|
+
|
245
|
+
If you need to change the permissions of the UNIX socket, just add a umask parameter:
|
246
|
+
|
247
|
+
```
|
248
|
+
$ puma -b 'unix:///var/run/puma.sock?umask=0111'
|
249
|
+
```
|
250
|
+
|
251
|
+
Need a bit of security? Use SSL sockets:
|
252
|
+
|
253
|
+
```
|
254
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
|
255
|
+
```
|
256
|
+
#### Self-signed SSL certificates (via the [`localhost`] gem, for development use):
|
257
|
+
|
258
|
+
Puma supports the [`localhost`] gem for self-signed certificates. This is particularly useful if you want to use Puma with SSL locally, and self-signed certificates will work for your use-case. Currently, the integration can only be used in MRI.
|
259
|
+
|
260
|
+
Puma automatically configures SSL when the [`localhost`] gem is loaded in a `development` environment:
|
261
|
+
|
262
|
+
Add the gem to your Gemfile:
|
263
|
+
```ruby
|
264
|
+
group(:development) do
|
265
|
+
gem 'localhost'
|
266
|
+
end
|
267
|
+
```
|
268
|
+
|
269
|
+
And require it implicitly using bundler:
|
270
|
+
```ruby
|
271
|
+
require "bundler"
|
272
|
+
Bundler.require(:default, ENV["RACK_ENV"].to_sym)
|
273
|
+
```
|
274
|
+
|
275
|
+
Alternatively, you can require the gem in your configuration file, either `config/puma/development.rb`, `config/puma.rb`, or set via the `-C` cli option:
|
276
|
+
```ruby
|
277
|
+
require 'localhost'
|
278
|
+
# configuration methods (from Puma::DSL) as needed
|
279
|
+
```
|
280
|
+
|
281
|
+
Additionally, Puma must be listening to an SSL socket:
|
282
|
+
|
283
|
+
```shell
|
284
|
+
$ puma -b 'ssl://localhost:9292' -C config/use_local_host.rb
|
285
|
+
|
286
|
+
# The following options allow you to reach Puma over HTTP as well:
|
287
|
+
$ puma -b ssl://localhost:9292 -b tcp://localhost:9393 -C config/use_local_host.rb
|
288
|
+
```
|
289
|
+
|
290
|
+
[`localhost`]: https://github.com/socketry/localhost
|
291
|
+
|
292
|
+
#### Controlling SSL Cipher Suites
|
293
|
+
|
294
|
+
To use or avoid specific SSL ciphers for TLSv1.2 and below, use `ssl_cipher_filter` or `ssl_cipher_list` options.
|
295
|
+
|
296
|
+
##### Ruby:
|
297
|
+
|
298
|
+
```
|
299
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA'
|
300
|
+
```
|
301
|
+
|
302
|
+
##### JRuby:
|
303
|
+
|
304
|
+
```
|
305
|
+
$ 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'
|
306
|
+
```
|
307
|
+
|
308
|
+
To configure the available TLSv1.3 ciphersuites, use `ssl_ciphersuites` option (not available for JRuby).
|
309
|
+
|
310
|
+
##### Ruby:
|
311
|
+
|
312
|
+
```
|
313
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_ciphersuites=TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256'
|
314
|
+
```
|
315
|
+
|
316
|
+
See https://www.openssl.org/docs/man1.1.1/man1/ciphers.html for cipher filter format and full list of cipher suites.
|
317
|
+
|
318
|
+
Disable TLS v1 with the `no_tlsv1` option:
|
319
|
+
|
320
|
+
```
|
321
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true'
|
322
|
+
```
|
323
|
+
|
324
|
+
#### Controlling OpenSSL Verification Flags
|
325
|
+
|
326
|
+
To enable verification flags offered by OpenSSL, use `verification_flags` (not available for JRuby):
|
327
|
+
|
328
|
+
```
|
329
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&verification_flags=PARTIAL_CHAIN'
|
330
|
+
```
|
331
|
+
|
332
|
+
You can also set multiple verification flags (by separating them with a comma):
|
333
|
+
|
334
|
+
```
|
335
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&verification_flags=PARTIAL_CHAIN,CRL_CHECK'
|
336
|
+
```
|
337
|
+
|
338
|
+
List of available flags: `USE_CHECK_TIME`, `CRL_CHECK`, `CRL_CHECK_ALL`, `IGNORE_CRITICAL`, `X509_STRICT`, `ALLOW_PROXY_CERTS`, `POLICY_CHECK`, `EXPLICIT_POLICY`, `INHIBIT_ANY`, `INHIBIT_MAP`, `NOTIFY_POLICY`, `EXTENDED_CRL_SUPPORT`, `USE_DELTAS`, `CHECK_SS_SIGNATURE`, `TRUSTED_FIRST`, `SUITEB_128_LOS_ONLY`, `SUITEB_192_LOS`, `SUITEB_128_LOS`, `PARTIAL_CHAIN`, `NO_ALT_CHAINS`, `NO_CHECK_TIME`
|
339
|
+
(see https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_hostflags.html#VERIFICATION-FLAGS).
|
340
|
+
|
341
|
+
#### Controlling OpenSSL Password Decryption
|
342
|
+
|
343
|
+
To enable runtime decryption of an encrypted SSL key (not available for JRuby), use `key_password_command`:
|
344
|
+
|
345
|
+
```
|
346
|
+
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&key_password_command=/path/to/command.sh'
|
347
|
+
```
|
348
|
+
|
349
|
+
`key_password_command` must:
|
350
|
+
|
351
|
+
1. Be executable by Puma.
|
352
|
+
2. Print the decryption password to stdout.
|
353
|
+
|
354
|
+
For example:
|
355
|
+
|
356
|
+
```shell
|
357
|
+
#!/bin/sh
|
358
|
+
|
359
|
+
echo "this is my password"
|
360
|
+
```
|
361
|
+
|
362
|
+
`key_password_command` can be used with `key` or `key_pem`. If the key
|
363
|
+
is not encrypted, the executable will not be called.
|
364
|
+
|
365
|
+
### Control/Status Server
|
366
|
+
|
367
|
+
Puma has a built-in status and control app that can be used to query and control Puma.
|
368
|
+
|
369
|
+
```
|
370
|
+
$ puma --control-url tcp://127.0.0.1:9293 --control-token foo
|
371
|
+
```
|
372
|
+
|
373
|
+
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 `Puma::App::Status` or [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the status app has available.
|
374
|
+
|
375
|
+
You can also interact with the control server via `pumactl`. This command will restart Puma:
|
376
|
+
|
377
|
+
```
|
378
|
+
$ pumactl --control-url 'tcp://127.0.0.1:9293' --control-token foo restart
|
379
|
+
```
|
380
|
+
|
381
|
+
To see a list of `pumactl` options, use `pumactl --help`.
|
382
|
+
|
383
|
+
### Configuration File
|
384
|
+
|
385
|
+
You can also provide a configuration file with the `-C` (or `--config`) flag:
|
386
|
+
|
387
|
+
```
|
388
|
+
$ puma -C /path/to/config
|
389
|
+
```
|
390
|
+
|
391
|
+
If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified (via the `--environment` flag or through the `APP_ENV`, `RACK_ENV`, or `RAILS_ENV` environment variables) Puma looks for a configuration file at `config/puma/<environment_name>.rb` and then falls back to `config/puma.rb`.
|
392
|
+
|
393
|
+
If you want to prevent Puma from looking for a configuration file in those locations, include the `--no-config` flag:
|
394
|
+
|
395
|
+
```
|
396
|
+
$ puma --no-config
|
397
|
+
|
398
|
+
# or
|
399
|
+
|
400
|
+
$ puma -C "-"
|
401
|
+
```
|
402
|
+
|
403
|
+
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 in `Puma::Configuration#puma_default_options` or [configuration.rb](https://github.com/puma/puma/blob/61c6213fbab/lib/puma/configuration.rb#L182-L204).
|
404
|
+
|
405
|
+
Check out `Puma::DSL` or [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb) to see all available options.
|
406
|
+
|
407
|
+
## Restart
|
408
|
+
|
409
|
+
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.
|
410
|
+
|
411
|
+
For more, see the [Restart documentation](docs/restart.md).
|
412
|
+
|
413
|
+
## Signals
|
414
|
+
|
415
|
+
Puma responds to several signals. A detailed guide to using UNIX signals with Puma can be found in the [Signals documentation](docs/signals.md).
|
416
|
+
|
417
|
+
## Platform Constraints
|
418
|
+
|
419
|
+
Some platforms do not support all Puma features.
|
420
|
+
|
421
|
+
* **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).
|
422
|
+
* **Windows**: Cluster mode is not supported due to a lack of fork(2).
|
423
|
+
* **Kubernetes**: The way Kubernetes handles pod shutdowns interacts poorly with server processes implementing graceful shutdown, like Puma. See the [kubernetes section of the documentation](docs/kubernetes.md) for more details.
|
424
|
+
|
425
|
+
## Known Bugs
|
426
|
+
|
427
|
+
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:
|
428
|
+
|
429
|
+
```ruby
|
430
|
+
if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
|
431
|
+
begin
|
432
|
+
require 'stopgap_13632'
|
433
|
+
rescue LoadError
|
434
|
+
end
|
435
|
+
end
|
436
|
+
```
|
437
|
+
|
438
|
+
## Deployment
|
439
|
+
|
440
|
+
* Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
|
441
|
+
|
442
|
+
* Additionally, Puma has support for built-in daemonization via the [puma-daemon](https://github.com/kigster/puma-daemon) ruby gem. The gem restores the `daemonize` option that was removed from Puma starting version 5, but only for MRI Ruby.
|
443
|
+
|
444
|
+
|
445
|
+
It is common to use process monitors with Puma. Modern process monitors like systemd or rc.d
|
446
|
+
provide continuous monitoring and restarts for increased reliability in production environments:
|
447
|
+
|
448
|
+
* [rc.d](docs/jungle/rc.d/README.md)
|
449
|
+
* [systemd](docs/systemd.md)
|
450
|
+
|
451
|
+
Community guides:
|
452
|
+
|
453
|
+
* [Deploying Puma on OpenBSD using relayd and httpd](https://gist.github.com/anon987654321/4532cf8d6c59c1f43ec8973faa031103)
|
454
|
+
|
455
|
+
## Community Extensions
|
456
|
+
|
457
|
+
### Plugins
|
458
|
+
|
459
|
+
* [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
|
460
|
+
* [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
|
461
|
+
* [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog. Puma 5.1.0 integrated notify and watchdog, which probably conflicts with this plugin. Puma 6.1.0 added status support which obsoletes the plugin entirely.
|
462
|
+
* [puma-plugin-telemetry](https://github.com/babbel/puma-plugin-telemetry) - telemetry plugin for Puma offering various targets to publish
|
463
|
+
* [puma-acme](https://github.com/anchordotdev/puma-acme) - automatic SSL/HTTPS certificate provisioning and setup
|
464
|
+
|
465
|
+
### Monitoring
|
466
|
+
|
467
|
+
* [puma-status](https://github.com/ylecuyer/puma-status) — Monitor CPU/Mem/Load of running puma instances from the CLI
|
468
|
+
|
469
|
+
## Contributing
|
470
|
+
|
471
|
+
Find details for contributing in the [contribution guide](CONTRIBUTING.md).
|
472
|
+
|
473
|
+
## License
|
474
|
+
|
475
|
+
Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.
|
data/bin/puma
ADDED
data/bin/puma-wild
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014 Evan Phoenix
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
cli_arg = ARGV.shift
|
9
|
+
|
10
|
+
inc = ""
|
11
|
+
|
12
|
+
if cli_arg == "-I"
|
13
|
+
inc = ARGV.shift
|
14
|
+
$LOAD_PATH.concat inc.split(":")
|
15
|
+
end
|
16
|
+
|
17
|
+
module Puma; end
|
18
|
+
|
19
|
+
Puma.const_set(:WILD_ARGS, ["-I", inc])
|
20
|
+
|
21
|
+
require 'puma/cli'
|
22
|
+
|
23
|
+
cli = Puma::CLI.new ARGV
|
24
|
+
|
25
|
+
cli.run
|
data/bin/pumactl
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Architecture
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
Puma is a threaded Ruby HTTP application server processing requests across a TCP
|
8
|
+
and/or UNIX socket.
|
9
|
+
|
10
|
+
|
11
|
+
Puma processes (there can be one or many) accept connections from the socket via
|
12
|
+
a thread (in the [`Reactor`](../lib/puma/reactor.rb) class). The connection,
|
13
|
+
once fully buffered and read, moves into the `todo` list, where an available
|
14
|
+
thread will pick it up (in the [`ThreadPool`](../lib/puma/thread_pool.rb)
|
15
|
+
class).
|
16
|
+
|
17
|
+
Puma works in two main modes: cluster and single. In single mode, only one Puma
|
18
|
+
process boots. In cluster mode, a `master` process is booted, which prepares
|
19
|
+
(and may boot) the application and then uses the `fork()` system call to create
|
20
|
+
one or more `child` processes. These `child` processes all listen to the same
|
21
|
+
socket. The `master` process does not listen to the socket or process requests -
|
22
|
+
its purpose is primarily to manage and listen for UNIX signals and possibly kill
|
23
|
+
or boot `child` processes.
|
24
|
+
|
25
|
+
We sometimes call `child` processes (or Puma processes in `single` mode)
|
26
|
+
_workers_, and we sometimes call the threads created by Puma's
|
27
|
+
[`ThreadPool`](../lib/puma/thread_pool.rb) _worker threads_.
|
28
|
+
|
29
|
+
## How Requests Work
|
30
|
+
|
31
|
+

|
32
|
+
|
33
|
+
* Upon startup, Puma listens on a TCP or UNIX socket.
|
34
|
+
* The backlog of this socket is configured with a default of 1024, but the
|
35
|
+
actual backlog value is capped by the `net.core.somaxconn` sysctl value.
|
36
|
+
The backlog determines the size of the queue for unaccepted connections. If
|
37
|
+
the backlog is full, the operating system is not accepting new connections.
|
38
|
+
* This socket backlog is distinct from the `backlog` of work as reported by
|
39
|
+
`Puma.stats` or the control server. The backlog that `Puma.stats` refers to
|
40
|
+
represents the number of connections in the process' `todo` set waiting for
|
41
|
+
a thread from the [`ThreadPool`](../lib/puma/thread_pool.rb).
|
42
|
+
* By default, a single, separate thread (created by the
|
43
|
+
[`Reactor`](../lib/puma/reactor.rb) class) reads and buffers requests from the
|
44
|
+
socket.
|
45
|
+
* When at least one worker thread is available for work, the reactor thread
|
46
|
+
listens to the socket and accepts a request (if one is waiting).
|
47
|
+
* The reactor thread waits for the entire HTTP request to be received.
|
48
|
+
* Puma exposes the time spent waiting for the HTTP request body to be
|
49
|
+
received to the Rack app as `env['puma.request_body_wait']`
|
50
|
+
(milliseconds).
|
51
|
+
* Once fully buffered and received, the connection is pushed into the "todo"
|
52
|
+
set.
|
53
|
+
* Worker threads pop work off the "todo" set for processing.
|
54
|
+
* The worker thread processes the request via `call`ing the configured Rack
|
55
|
+
application. The Rack application generates the HTTP response.
|
56
|
+
* The worker thread writes the response to the connection. While Puma buffers
|
57
|
+
requests via a separate thread, it does not use a separate thread for
|
58
|
+
responses.
|
59
|
+
* Once done, the thread becomes available to process another connection in the
|
60
|
+
"todo" set.
|
61
|
+
|
62
|
+
### `queue_requests`
|
63
|
+
|
64
|
+

|
65
|
+
|
66
|
+
The `queue_requests` option is `true` by default, enabling the separate reactor
|
67
|
+
thread used to buffer requests as described above.
|
68
|
+
|
69
|
+
If set to `false`, this buffer will not be used for connections while waiting
|
70
|
+
for the request to arrive.
|
71
|
+
|
72
|
+
In this mode, when a connection is accepted, it is added to the "todo" queue
|
73
|
+
immediately, and a worker will synchronously do any waiting necessary to read
|
74
|
+
the HTTP request from the socket.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Compile Options
|
2
|
+
|
3
|
+
There are some `cflags` provided to change Puma's default configuration for its
|
4
|
+
C extension.
|
5
|
+
|
6
|
+
## Query String, `PUMA_QUERY_STRING_MAX_LENGTH`
|
7
|
+
|
8
|
+
By default, the max length of `QUERY_STRING` is `1024 * 10`. But you may want to
|
9
|
+
adjust it to accept longer queries in GET requests.
|
10
|
+
|
11
|
+
For manual install, pass the `PUMA_QUERY_STRING_MAX_LENGTH` option like this:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install puma -- --with-cflags="-D PUMA_QUERY_STRING_MAX_LENGTH=64000"
|
15
|
+
```
|
16
|
+
|
17
|
+
For Bundler, use its configuration system:
|
18
|
+
|
19
|
+
```
|
20
|
+
bundle config build.puma "--with-cflags='-D PUMA_QUERY_STRING_MAX_LENGTH=64000'"
|
21
|
+
```
|
22
|
+
|
23
|
+
## Request Path, `PUMA_REQUEST_PATH_MAX_LENGTH`
|
24
|
+
|
25
|
+
By default, the max length of `REQUEST_PATH` is `8192`. But you may want to
|
26
|
+
adjust it to accept longer paths in requests.
|
27
|
+
|
28
|
+
For manual install, pass the `PUMA_REQUEST_PATH_MAX_LENGTH` option like this:
|
29
|
+
|
30
|
+
```
|
31
|
+
gem install puma -- --with-cflags="-D PUMA_REQUEST_PATH_MAX_LENGTH=64000"
|
32
|
+
```
|
33
|
+
|
34
|
+
For Bundler, use its configuration system:
|
35
|
+
|
36
|
+
```
|
37
|
+
bundle config build.puma "--with-cflags='-D PUMA_REQUEST_PATH_MAX_LENGTH=64000'"
|
38
|
+
```
|
39
|
+
|
40
|
+
## Request URI, `PUMA_REQUEST_URI_MAX_LENGTH`
|
41
|
+
|
42
|
+
By default, the max length of `REQUEST_URI` is `1024 * 12`. But you may want to
|
43
|
+
adjust it to accept longer URIs in requests.
|
44
|
+
|
45
|
+
For manual install, pass the `PUMA_REQUEST_URI_MAX_LENGTH` option like this:
|
46
|
+
|
47
|
+
```
|
48
|
+
gem install puma -- --with-cflags="-D PUMA_REQUEST_URI_MAX_LENGTH=64000"
|
49
|
+
```
|
50
|
+
|
51
|
+
For Bundler, use its configuration system:
|
52
|
+
|
53
|
+
```
|
54
|
+
bundle config build.puma "--with-cflags='-D PUMA_REQUEST_URI_MAX_LENGTH=64000'"
|
55
|
+
```
|