puma 4.3.3-java → 5.0.0.beta2-java

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +79 -8
  3. data/LICENSE +23 -20
  4. data/README.md +18 -12
  5. data/docs/architecture.md +3 -3
  6. data/docs/deployment.md +9 -3
  7. data/docs/fork_worker.md +31 -0
  8. data/docs/jungle/README.md +13 -0
  9. data/{tools → docs}/jungle/rc.d/README.md +0 -0
  10. data/{tools → docs}/jungle/rc.d/puma +0 -0
  11. data/{tools → docs}/jungle/rc.d/puma.conf +0 -0
  12. data/{tools → docs}/jungle/upstart/README.md +0 -0
  13. data/{tools → docs}/jungle/upstart/puma-manager.conf +0 -0
  14. data/{tools → docs}/jungle/upstart/puma.conf +0 -0
  15. data/docs/signals.md +5 -4
  16. data/docs/systemd.md +1 -63
  17. data/ext/puma_http11/PumaHttp11Service.java +2 -4
  18. data/ext/puma_http11/extconf.rb +4 -3
  19. data/ext/puma_http11/http11_parser.c +3 -1
  20. data/ext/puma_http11/http11_parser.rl +3 -1
  21. data/ext/puma_http11/mini_ssl.c +12 -2
  22. data/ext/puma_http11/org/jruby/puma/Http11.java +3 -3
  23. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +37 -6
  24. data/ext/puma_http11/puma_http11.c +3 -38
  25. data/lib/puma.rb +5 -0
  26. data/lib/puma/app/status.rb +18 -3
  27. data/lib/puma/binder.rb +66 -63
  28. data/lib/puma/cli.rb +7 -15
  29. data/lib/puma/client.rb +64 -14
  30. data/lib/puma/cluster.rb +183 -74
  31. data/lib/puma/commonlogger.rb +2 -2
  32. data/lib/puma/configuration.rb +30 -42
  33. data/lib/puma/const.rb +2 -3
  34. data/lib/puma/control_cli.rb +27 -17
  35. data/lib/puma/detect.rb +8 -0
  36. data/lib/puma/dsl.rb +72 -36
  37. data/lib/puma/error_logger.rb +96 -0
  38. data/lib/puma/events.rb +33 -31
  39. data/lib/puma/io_buffer.rb +9 -2
  40. data/lib/puma/jruby_restart.rb +0 -58
  41. data/lib/puma/launcher.rb +46 -31
  42. data/lib/puma/minissl.rb +47 -10
  43. data/lib/puma/null_io.rb +1 -1
  44. data/lib/puma/plugin.rb +1 -10
  45. data/lib/puma/puma_http11.jar +0 -0
  46. data/lib/puma/rack/builder.rb +0 -4
  47. data/lib/puma/reactor.rb +8 -3
  48. data/lib/puma/runner.rb +6 -35
  49. data/lib/puma/server.rb +138 -182
  50. data/lib/puma/single.rb +7 -64
  51. data/lib/puma/state_file.rb +6 -3
  52. data/lib/puma/thread_pool.rb +90 -49
  53. data/lib/rack/handler/puma.rb +1 -3
  54. data/tools/{docker/Dockerfile → Dockerfile} +0 -0
  55. metadata +18 -21
  56. data/docs/tcp_mode.md +0 -96
  57. data/ext/puma_http11/io_buffer.c +0 -155
  58. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +0 -72
  59. data/lib/puma/tcp_logger.rb +0 -41
  60. data/tools/jungle/README.md +0 -19
  61. data/tools/jungle/init.d/README.md +0 -61
  62. data/tools/jungle/init.d/puma +0 -421
  63. data/tools/jungle/init.d/run-puma +0 -18
@@ -14,11 +14,9 @@ module Puma
14
14
  # that this inherits from.
15
15
  class Single < Runner
16
16
  def stats
17
- b = @server.backlog || 0
18
- r = @server.running || 0
19
- t = @server.pool_capacity || 0
20
- m = @server.max_threads || 0
21
- %Q!{ "started_at": "#{@started_at.utc.iso8601}", "backlog": #{b}, "running": #{r}, "pool_capacity": #{t}, "max_threads": #{m} }!
17
+ {
18
+ started_at: @started_at.utc.iso8601
19
+ }.merge(@server.stats)
22
20
  end
23
21
 
24
22
  def restart
@@ -39,64 +37,10 @@ module Puma
39
37
  @server.stop(true) if @server
40
38
  end
41
39
 
42
- def jruby_daemon?
43
- daemon? and Puma.jruby?
44
- end
45
-
46
- def jruby_daemon_start
47
- require 'puma/jruby_restart'
48
- JRubyRestart.daemon_start(@restart_dir, @launcher.restart_args)
49
- end
50
-
51
40
  def run
52
- already_daemon = false
53
-
54
- if jruby_daemon?
55
- require 'puma/jruby_restart'
56
-
57
- if JRubyRestart.daemon?
58
- # load and bind before redirecting IO so errors show up on stdout/stderr
59
- load_and_bind
60
- redirect_io
61
- end
62
-
63
- already_daemon = JRubyRestart.daemon_init
64
- end
65
-
66
41
  output_header "single"
67
42
 
68
- if jruby_daemon?
69
- if already_daemon
70
- JRubyRestart.perm_daemonize
71
- else
72
- pid = nil
73
-
74
- Signal.trap "SIGUSR2" do
75
- log "* Started new process #{pid} as daemon..."
76
-
77
- # Must use exit! so we don't unwind and run the ensures
78
- # that will be run by the new child (such as deleting the
79
- # pidfile)
80
- exit!(true)
81
- end
82
-
83
- Signal.trap "SIGCHLD" do
84
- log "! Error starting new process as daemon, exiting"
85
- exit 1
86
- end
87
-
88
- jruby_daemon_start
89
- sleep
90
- end
91
- else
92
- if daemon?
93
- log "* Daemonizing..."
94
- Process.daemon(true)
95
- redirect_io
96
- end
97
-
98
- load_and_bind
99
- end
43
+ load_and_bind
100
44
 
101
45
  Plugins.fire_background
102
46
 
@@ -106,10 +50,9 @@ module Puma
106
50
 
107
51
  @server = server = start_server
108
52
 
109
- unless daemon?
110
- log "Use Ctrl-C to stop"
111
- redirect_io
112
- end
53
+
54
+ log "Use Ctrl-C to stop"
55
+ redirect_io
113
56
 
114
57
  @launcher.events.fire_on_booted!
115
58
 
@@ -8,15 +8,18 @@ module Puma
8
8
  @options = {}
9
9
  end
10
10
 
11
- def save(path)
12
- File.write path, YAML.dump(@options)
11
+ def save(path, permission = nil)
12
+ File.open(path, "w") do |file|
13
+ file.chmod(permission) if permission
14
+ file.write(YAML.dump(@options))
15
+ end
13
16
  end
14
17
 
15
18
  def load(path)
16
19
  @options = YAML.load File.read(path)
17
20
  end
18
21
 
19
- FIELDS = %w!control_url control_auth_token pid!
22
+ FIELDS = %w!control_url control_auth_token pid running_from!
20
23
 
21
24
  FIELDS.each do |f|
22
25
  define_method f do
@@ -47,6 +47,7 @@ module Puma
47
47
  @shutdown = false
48
48
 
49
49
  @trim_requested = 0
50
+ @out_of_band_pending = false
50
51
 
51
52
  @workers = []
52
53
 
@@ -54,7 +55,10 @@ module Puma
54
55
  @reaper = nil
55
56
 
56
57
  @mutex.synchronize do
57
- @min.times { spawn_thread }
58
+ @min.times do
59
+ spawn_thread
60
+ @not_full.wait(@mutex)
61
+ end
58
62
  end
59
63
 
60
64
  @clean_thread_locals = false
@@ -62,6 +66,7 @@ module Puma
62
66
 
63
67
  attr_reader :spawned, :trim_requested, :waiting
64
68
  attr_accessor :clean_thread_locals
69
+ attr_accessor :out_of_band_hook
65
70
 
66
71
  def self.clean_thread_locals
67
72
  Thread.current.keys.each do |key| # rubocop: disable Performance/HashEachMethods
@@ -72,13 +77,17 @@ module Puma
72
77
  # How many objects have yet to be processed by the pool?
73
78
  #
74
79
  def backlog
75
- @mutex.synchronize { @todo.size }
80
+ with_mutex { @todo.size }
76
81
  end
77
82
 
78
83
  def pool_capacity
79
84
  waiting + (@max - spawned)
80
85
  end
81
86
 
87
+ def busy_threads
88
+ with_mutex { @spawned - @waiting + @todo.size }
89
+ end
90
+
82
91
  # :nodoc:
83
92
  #
84
93
  # Must be called with @mutex held!
@@ -99,48 +108,40 @@ module Puma
99
108
  while true
100
109
  work = nil
101
110
 
102
- continue = true
103
-
104
111
  mutex.synchronize do
105
112
  while todo.empty?
106
113
  if @trim_requested > 0
107
114
  @trim_requested -= 1
108
- continue = false
109
- not_full.signal
110
- break
111
- end
112
-
113
- if @shutdown
114
- continue = false
115
- break
115
+ @spawned -= 1
116
+ @workers.delete th
117
+ Thread.exit
116
118
  end
117
119
 
118
120
  @waiting += 1
121
+ if @out_of_band_pending && trigger_out_of_band_hook
122
+ @out_of_band_pending = false
123
+ end
119
124
  not_full.signal
120
- not_empty.wait mutex
121
- @waiting -= 1
125
+ begin
126
+ not_empty.wait mutex
127
+ ensure
128
+ @waiting -= 1
129
+ end
122
130
  end
123
131
 
124
- work = todo.shift if continue
132
+ work = todo.shift
125
133
  end
126
134
 
127
- break unless continue
128
-
129
135
  if @clean_thread_locals
130
136
  ThreadPool.clean_thread_locals
131
137
  end
132
138
 
133
139
  begin
134
- block.call(work, *extra)
140
+ @out_of_band_pending = true if block.call(work, *extra)
135
141
  rescue Exception => e
136
142
  STDERR.puts "Error reached top of thread-pool: #{e.message} (#{e.class})"
137
143
  end
138
144
  end
139
-
140
- mutex.synchronize do
141
- @spawned -= 1
142
- @workers.delete th
143
- end
144
145
  end
145
146
 
146
147
  @workers << th
@@ -150,9 +151,30 @@ module Puma
150
151
 
151
152
  private :spawn_thread
152
153
 
154
+ def trigger_out_of_band_hook
155
+ return false unless out_of_band_hook && out_of_band_hook.any?
156
+
157
+ # we execute on idle hook when all threads are free
158
+ return false unless @spawned == @waiting
159
+
160
+ out_of_band_hook.each(&:call)
161
+ true
162
+ rescue Exception => e
163
+ STDERR.puts "Exception calling out_of_band_hook: #{e.message} (#{e.class})"
164
+ true
165
+ end
166
+
167
+ private :trigger_out_of_band_hook
168
+
169
+ def with_mutex(&block)
170
+ @mutex.owned? ?
171
+ yield :
172
+ @mutex.synchronize(&block)
173
+ end
174
+
153
175
  # Add +work+ to the todo list for a Thread to pickup and process.
154
176
  def <<(work)
155
- @mutex.synchronize do
177
+ with_mutex do
156
178
  if @shutdown
157
179
  raise "Unable to add work while shutting down"
158
180
  end
@@ -193,11 +215,8 @@ module Puma
193
215
  # method would not block and another request would be added into the reactor
194
216
  # by the server. This would continue until a fully bufferend request
195
217
  # makes it through the reactor and can then be processed by the thread pool.
196
- #
197
- # Returns the current number of busy threads, or +nil+ if shutting down.
198
- #
199
218
  def wait_until_not_full
200
- @mutex.synchronize do
219
+ with_mutex do
201
220
  while true
202
221
  return if @shutdown
203
222
 
@@ -205,21 +224,40 @@ module Puma
205
224
  # is work queued that cannot be handled by waiting
206
225
  # threads, then accept more work until we would
207
226
  # spin up the max number of threads.
208
- busy_threads = @spawned - @waiting + @todo.size
209
- return busy_threads if @max > busy_threads
227
+ return if busy_threads < @max
210
228
 
211
229
  @not_full.wait @mutex
212
230
  end
213
231
  end
214
232
  end
215
233
 
216
- # If too many threads are in the pool, tell one to finish go ahead
234
+ def wait_for_less_busy_worker(delay_s)
235
+ # Ruby MRI does GVL, this can result
236
+ # in processing contention when multiple threads
237
+ # (requests) are running concurrently
238
+ return unless Puma.mri?
239
+ return unless delay_s > 0
240
+
241
+ with_mutex do
242
+ return if @shutdown
243
+
244
+ # do not delay, if we are not busy
245
+ return unless busy_threads > 0
246
+
247
+ # this will be signaled once a request finishes,
248
+ # which can happen earlier than delay
249
+ @not_full.wait @mutex, delay_s
250
+ end
251
+ end
252
+
253
+ # If there are any free threads in the pool, tell one to go ahead
217
254
  # and exit. If +force+ is true, then a trim request is requested
218
255
  # even if all threads are being utilized.
219
256
  #
220
257
  def trim(force=false)
221
- @mutex.synchronize do
222
- if (force or @waiting > 0) and @spawned - @trim_requested > @min
258
+ with_mutex do
259
+ free = @waiting - @todo.size
260
+ if (force or free > 0) and @spawned - @trim_requested > @min
223
261
  @trim_requested += 1
224
262
  @not_empty.signal
225
263
  end
@@ -229,7 +267,7 @@ module Puma
229
267
  # If there are dead threads in the pool make them go away while decreasing
230
268
  # spawned counter so that new healthy threads could be created again.
231
269
  def reap
232
- @mutex.synchronize do
270
+ with_mutex do
233
271
  dead_workers = @workers.reject(&:alive?)
234
272
 
235
273
  dead_workers.each do |worker|
@@ -281,10 +319,14 @@ module Puma
281
319
  end
282
320
 
283
321
  # Tell all threads in the pool to exit and wait for them to finish.
322
+ # Wait +timeout+ seconds then raise +ForceShutdown+ in remaining threads.
323
+ # Next, wait an extra +grace+ seconds then force-kill remaining threads.
324
+ # Finally, wait +kill_grace+ seconds for remaining threads to exit.
284
325
  #
285
326
  def shutdown(timeout=-1)
286
- threads = @mutex.synchronize do
327
+ threads = with_mutex do
287
328
  @shutdown = true
329
+ @trim_requested = @spawned
288
330
  @not_empty.broadcast
289
331
  @not_full.broadcast
290
332
 
@@ -298,27 +340,26 @@ module Puma
298
340
  # Wait for threads to finish without force shutdown.
299
341
  threads.each(&:join)
300
342
  else
301
- # Wait for threads to finish after n attempts (+timeout+).
302
- # If threads are still running, it will forcefully kill them.
303
- timeout.times do
304
- threads.delete_if do |t|
305
- t.join 1
306
- end
307
-
308
- if threads.empty?
309
- break
310
- else
311
- sleep 1
343
+ join = ->(inner_timeout) do
344
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
345
+ threads.reject! do |t|
346
+ elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
347
+ t.join inner_timeout - elapsed
312
348
  end
313
349
  end
314
350
 
351
+ # Wait +timeout+ seconds for threads to finish.
352
+ join.call(timeout)
353
+
354
+ # If threads are still running, raise ForceShutdown and wait to finish.
315
355
  threads.each do |t|
316
356
  t.raise ForceShutdown
317
357
  end
358
+ join.call(SHUTDOWN_GRACE_TIME)
318
359
 
319
- threads.each do |t|
320
- t.join SHUTDOWN_GRACE_TIME
321
- end
360
+ # If threads are _still_ running, forcefully kill them and wait to finish.
361
+ threads.each(&:kill)
362
+ join.call(1)
322
363
  end
323
364
 
324
365
  @spawned = 0
@@ -30,8 +30,6 @@ module Rack
30
30
  end
31
31
 
32
32
  conf = ::Puma::Configuration.new(options, default_options) do |user_config, file_config, default_config|
33
- user_config.quiet
34
-
35
33
  if options.delete(:Verbose)
36
34
  app = Rack::CommonLogger.new(app, STDOUT)
37
35
  end
@@ -61,7 +59,7 @@ module Rack
61
59
  conf
62
60
  end
63
61
 
64
- def self.run(app, options = {})
62
+ def self.run(app, **options)
65
63
  conf = self.config(app, options)
66
64
 
67
65
  events = options.delete(:Silent) ? ::Puma::Events.strings : ::Puma::Events.stdio
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.3
4
+ version: 5.0.0.beta2
5
5
  platform: java
6
6
  authors:
7
7
  - Evan Phoenix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2020-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -44,15 +44,22 @@ files:
44
44
  - bin/pumactl
45
45
  - docs/architecture.md
46
46
  - docs/deployment.md
47
+ - docs/fork_worker.md
47
48
  - docs/images/puma-connection-flow-no-reactor.png
48
49
  - docs/images/puma-connection-flow.png
49
50
  - docs/images/puma-general-arch.png
51
+ - docs/jungle/README.md
52
+ - docs/jungle/rc.d/README.md
53
+ - docs/jungle/rc.d/puma
54
+ - docs/jungle/rc.d/puma.conf
55
+ - docs/jungle/upstart/README.md
56
+ - docs/jungle/upstart/puma-manager.conf
57
+ - docs/jungle/upstart/puma.conf
50
58
  - docs/nginx.md
51
59
  - docs/plugins.md
52
60
  - docs/restart.md
53
61
  - docs/signals.md
54
62
  - docs/systemd.md
55
- - docs/tcp_mode.md
56
63
  - ext/puma_http11/PumaHttp11Service.java
57
64
  - ext/puma_http11/ext_help.h
58
65
  - ext/puma_http11/extconf.rb
@@ -61,11 +68,9 @@ files:
61
68
  - ext/puma_http11/http11_parser.java.rl
62
69
  - ext/puma_http11/http11_parser.rl
63
70
  - ext/puma_http11/http11_parser_common.rl
64
- - ext/puma_http11/io_buffer.c
65
71
  - ext/puma_http11/mini_ssl.c
66
72
  - ext/puma_http11/org/jruby/puma/Http11.java
67
73
  - ext/puma_http11/org/jruby/puma/Http11Parser.java
68
- - ext/puma_http11/org/jruby/puma/IOBuffer.java
69
74
  - ext/puma_http11/org/jruby/puma/MiniSSL.java
70
75
  - ext/puma_http11/puma_http11.c
71
76
  - lib/puma.rb
@@ -81,6 +86,7 @@ files:
81
86
  - lib/puma/control_cli.rb
82
87
  - lib/puma/detect.rb
83
88
  - lib/puma/dsl.rb
89
+ - lib/puma/error_logger.rb
84
90
  - lib/puma/events.rb
85
91
  - lib/puma/io_buffer.rb
86
92
  - lib/puma/jruby_restart.rb
@@ -99,28 +105,19 @@ files:
99
105
  - lib/puma/server.rb
100
106
  - lib/puma/single.rb
101
107
  - lib/puma/state_file.rb
102
- - lib/puma/tcp_logger.rb
103
108
  - lib/puma/thread_pool.rb
104
109
  - lib/puma/util.rb
105
110
  - lib/rack/handler/puma.rb
106
- - tools/docker/Dockerfile
107
- - tools/jungle/README.md
108
- - tools/jungle/init.d/README.md
109
- - tools/jungle/init.d/puma
110
- - tools/jungle/init.d/run-puma
111
- - tools/jungle/rc.d/README.md
112
- - tools/jungle/rc.d/puma
113
- - tools/jungle/rc.d/puma.conf
114
- - tools/jungle/upstart/README.md
115
- - tools/jungle/upstart/puma-manager.conf
116
- - tools/jungle/upstart/puma.conf
111
+ - tools/Dockerfile
117
112
  - tools/trickletest.rb
118
- homepage: http://puma.io
113
+ homepage: https://puma.io
119
114
  licenses:
120
115
  - BSD-3-Clause
121
116
  metadata:
122
- msys2_mingw_dependencies: openssl
117
+ bug_tracker_uri: https://github.com/puma/puma/issues
123
118
  changelog_uri: https://github.com/puma/puma/blob/master/History.md
119
+ homepage_uri: https://puma.io
120
+ source_code_uri: https://github.com/puma/puma
124
121
  post_install_message:
125
122
  rdoc_options: []
126
123
  require_paths:
@@ -132,9 +129,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
129
  version: '2.2'
133
130
  required_rubygems_version: !ruby/object:Gem::Requirement
134
131
  requirements:
135
- - - ">="
132
+ - - ">"
136
133
  - !ruby/object:Gem::Version
137
- version: '0'
134
+ version: 1.3.1
138
135
  requirements: []
139
136
  rubygems_version: 3.0.6
140
137
  signing_key: