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.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +2897 -0
  3. data/LICENSE +29 -0
  4. data/README.md +475 -0
  5. data/bin/puma +10 -0
  6. data/bin/puma-wild +25 -0
  7. data/bin/pumactl +12 -0
  8. data/docs/architecture.md +74 -0
  9. data/docs/compile_options.md +55 -0
  10. data/docs/deployment.md +102 -0
  11. data/docs/fork_worker.md +35 -0
  12. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  13. data/docs/images/puma-connection-flow.png +0 -0
  14. data/docs/images/puma-general-arch.png +0 -0
  15. data/docs/jungle/README.md +9 -0
  16. data/docs/jungle/rc.d/README.md +74 -0
  17. data/docs/jungle/rc.d/puma +61 -0
  18. data/docs/jungle/rc.d/puma.conf +10 -0
  19. data/docs/kubernetes.md +78 -0
  20. data/docs/nginx.md +80 -0
  21. data/docs/plugins.md +38 -0
  22. data/docs/rails_dev_mode.md +28 -0
  23. data/docs/restart.md +65 -0
  24. data/docs/signals.md +98 -0
  25. data/docs/stats.md +142 -0
  26. data/docs/systemd.md +253 -0
  27. data/docs/testing_benchmarks_local_files.md +150 -0
  28. data/docs/testing_test_rackup_ci_files.md +36 -0
  29. data/ext/puma_http11/PumaHttp11Service.java +17 -0
  30. data/ext/puma_http11/ext_help.h +15 -0
  31. data/ext/puma_http11/extconf.rb +80 -0
  32. data/ext/puma_http11/http11_parser.c +1057 -0
  33. data/ext/puma_http11/http11_parser.h +65 -0
  34. data/ext/puma_http11/http11_parser.java.rl +145 -0
  35. data/ext/puma_http11/http11_parser.rl +149 -0
  36. data/ext/puma_http11/http11_parser_common.rl +54 -0
  37. data/ext/puma_http11/mini_ssl.c +842 -0
  38. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
  39. data/ext/puma_http11/org/jruby/puma/Http11.java +228 -0
  40. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +455 -0
  41. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +509 -0
  42. data/ext/puma_http11/puma_http11.c +495 -0
  43. data/lib/puma/app/status.rb +96 -0
  44. data/lib/puma/binder.rb +502 -0
  45. data/lib/puma/cli.rb +247 -0
  46. data/lib/puma/client.rb +682 -0
  47. data/lib/puma/cluster/worker.rb +180 -0
  48. data/lib/puma/cluster/worker_handle.rb +96 -0
  49. data/lib/puma/cluster.rb +616 -0
  50. data/lib/puma/commonlogger.rb +115 -0
  51. data/lib/puma/configuration.rb +390 -0
  52. data/lib/puma/const.rb +307 -0
  53. data/lib/puma/control_cli.rb +316 -0
  54. data/lib/puma/detect.rb +45 -0
  55. data/lib/puma/dsl.rb +1425 -0
  56. data/lib/puma/error_logger.rb +113 -0
  57. data/lib/puma/events.rb +57 -0
  58. data/lib/puma/io_buffer.rb +46 -0
  59. data/lib/puma/jruby_restart.rb +11 -0
  60. data/lib/puma/json_serialization.rb +96 -0
  61. data/lib/puma/launcher/bundle_pruner.rb +104 -0
  62. data/lib/puma/launcher.rb +488 -0
  63. data/lib/puma/log_writer.rb +147 -0
  64. data/lib/puma/minissl/context_builder.rb +96 -0
  65. data/lib/puma/minissl.rb +459 -0
  66. data/lib/puma/null_io.rb +84 -0
  67. data/lib/puma/plugin/systemd.rb +90 -0
  68. data/lib/puma/plugin/tmp_restart.rb +36 -0
  69. data/lib/puma/plugin.rb +111 -0
  70. data/lib/puma/puma_http11.jar +0 -0
  71. data/lib/puma/rack/builder.rb +297 -0
  72. data/lib/puma/rack/urlmap.rb +93 -0
  73. data/lib/puma/rack_default.rb +24 -0
  74. data/lib/puma/reactor.rb +125 -0
  75. data/lib/puma/request.rb +688 -0
  76. data/lib/puma/runner.rb +213 -0
  77. data/lib/puma/sd_notify.rb +149 -0
  78. data/lib/puma/server.rb +680 -0
  79. data/lib/puma/single.rb +69 -0
  80. data/lib/puma/state_file.rb +68 -0
  81. data/lib/puma/thread_pool.rb +434 -0
  82. data/lib/puma/util.rb +141 -0
  83. data/lib/puma.rb +78 -0
  84. data/lib/rack/handler/puma.rb +144 -0
  85. data/tools/Dockerfile +16 -0
  86. data/tools/trickletest.rb +44 -0
  87. metadata +153 -0
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Puma
4
+ class UnsupportedBackend < StandardError; end
5
+
6
+ # Monitors a collection of IO objects, calling a block whenever
7
+ # any monitored object either receives data or times out, or when the Reactor shuts down.
8
+ #
9
+ # The waiting/wake up is performed with nio4r, which will use the appropriate backend (libev,
10
+ # Java NIO or just plain IO#select). The call to `NIO::Selector#select` will
11
+ # 'wakeup' any IO object that receives data.
12
+ #
13
+ # This class additionally tracks a timeout for every added object,
14
+ # and wakes up any object when its timeout elapses.
15
+ #
16
+ # The implementation uses a Queue to synchronize adding new objects from the internal select loop.
17
+ class Reactor
18
+ # Create a new Reactor to monitor IO objects added by #add.
19
+ # The provided block will be invoked when an IO has data available to read,
20
+ # its timeout elapses, or when the Reactor shuts down.
21
+ def initialize(backend, &block)
22
+ require 'nio'
23
+ valid_backends = [:auto, *::NIO::Selector.backends]
24
+ unless valid_backends.include?(backend)
25
+ raise ArgumentError.new("unsupported IO selector backend: #{backend} (available backends: #{valid_backends.join(', ')})")
26
+ end
27
+
28
+ @selector = ::NIO::Selector.new(NIO::Selector.backends.delete(backend))
29
+ @input = Queue.new
30
+ @timeouts = []
31
+ @block = block
32
+ end
33
+
34
+ # Run the internal select loop, using a background thread by default.
35
+ def run(background=true)
36
+ if background
37
+ @thread = Thread.new do
38
+ Puma.set_thread_name "reactor"
39
+ select_loop
40
+ end
41
+ else
42
+ select_loop
43
+ end
44
+ end
45
+
46
+ # Add a new client to monitor.
47
+ # The object must respond to #timeout and #timeout_at.
48
+ # Returns false if the reactor is already shut down.
49
+ def add(client)
50
+ @input << client
51
+ @selector.wakeup
52
+ true
53
+ rescue ClosedQueueError, IOError # Ignore if selector is already closed
54
+ false
55
+ end
56
+
57
+ # Shutdown the reactor, blocking until the background thread is finished.
58
+ def shutdown
59
+ @input.close
60
+ begin
61
+ @selector.wakeup
62
+ rescue IOError # Ignore if selector is already closed
63
+ end
64
+ @thread&.join
65
+ end
66
+
67
+ private
68
+
69
+ def select_loop
70
+ close_selector = true
71
+ begin
72
+ until @input.closed? && @input.empty?
73
+ # Wakeup any registered object that receives incoming data.
74
+ # Block until the earliest timeout or Selector#wakeup is called.
75
+ timeout = (earliest = @timeouts.first) && earliest.timeout
76
+ @selector.select(timeout) {|mon| wakeup!(mon.value)}
77
+
78
+ # Wakeup all objects that timed out.
79
+ timed_out = @timeouts.take_while {|t| t.timeout == 0}
80
+ timed_out.each { |c| wakeup! c }
81
+
82
+ unless @input.empty?
83
+ until @input.empty?
84
+ client = @input.pop
85
+ register(client) if client.io_ok?
86
+ end
87
+ @timeouts.sort_by!(&:timeout_at)
88
+ end
89
+ end
90
+ rescue StandardError => e
91
+ STDERR.puts "Error in reactor loop escaped: #{e.message} (#{e.class})"
92
+ STDERR.puts e.backtrace
93
+
94
+ # NoMethodError may be rarely raised when calling @selector.select, which
95
+ # is odd. Regardless, it may continue for thousands of calls if retried.
96
+ # Also, when it raises, @selector.close also raises an error.
97
+ if NoMethodError === e
98
+ close_selector = false
99
+ else
100
+ retry
101
+ end
102
+ end
103
+ # Wakeup all remaining objects on shutdown.
104
+ @timeouts.each(&@block)
105
+ @selector.close if close_selector
106
+ end
107
+
108
+ # Start monitoring the object.
109
+ def register(client)
110
+ @selector.register(client.to_io, :r).value = client
111
+ @timeouts << client
112
+ rescue ArgumentError
113
+ # unreadable clients raise error when processed by NIO
114
+ end
115
+
116
+ # 'Wake up' a monitored object by calling the provided block.
117
+ # Stop monitoring the object if the block returns `true`.
118
+ def wakeup!(client)
119
+ if @block.call client
120
+ @selector.deregister client.to_io
121
+ @timeouts.delete client
122
+ end
123
+ end
124
+ end
125
+ end