raptor 0.12.0 → 0.13.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +10 -10
- data/docs/raptor-vs-puma.md +29 -29
- data/ext/raptor_bpf/reuseport_select.bpf.c +8 -4
- data/lib/raptor/binder.rb +37 -87
- data/lib/raptor/cli.rb +9 -25
- data/lib/raptor/cluster.rb +17 -53
- data/lib/raptor/http.rb +18 -0
- data/lib/raptor/http1.rb +244 -233
- data/lib/raptor/http2.rb +42 -63
- data/lib/raptor/reactor.rb +21 -52
- data/lib/raptor/reuseport_bpf.rb +14 -5
- data/lib/raptor/server.rb +10 -36
- data/lib/raptor/stats.rb +3 -8
- data/lib/raptor/systemd.rb +1 -1
- data/lib/raptor/version.rb +1 -1
- data/sig/generated/raptor/binder.rbs +34 -80
- data/sig/generated/raptor/cli.rbs +9 -25
- data/sig/generated/raptor/cluster.rbs +10 -51
- data/sig/generated/raptor/http.rbs +10 -0
- data/sig/generated/raptor/http1.rbs +129 -113
- data/sig/generated/raptor/http2.rbs +31 -48
- data/sig/generated/raptor/reactor.rbs +21 -52
- data/sig/generated/raptor/reuseport_bpf.rbs +11 -2
- data/sig/generated/raptor/server.rbs +9 -35
- data/sig/generated/raptor/stats.rbs +3 -8
- metadata +1 -1
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
# Generated from lib/raptor/reactor.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module Raptor
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# It coordinates between ractor pools for CPU-intensive HTTP parsing and
|
|
9
|
-
# thread pools for blocking operations, and provides backlog metrics that
|
|
10
|
-
# the server uses for backpressure control to prevent overload.
|
|
11
|
-
#
|
|
12
|
-
# @example
|
|
13
|
-
# reactor = Reactor.new(
|
|
14
|
-
# ractor_pool,
|
|
15
|
-
# thread_pool,
|
|
16
|
-
# connection_options: { first_data_timeout: 30, chunk_data_timeout: 10 },
|
|
17
|
-
# http1_options: { persistent_data_timeout: 65 }
|
|
18
|
-
# )
|
|
19
|
-
# reactor.run
|
|
20
|
-
# reactor.add(id: client.object_id, socket: client)
|
|
21
|
-
# # ... later
|
|
22
|
-
# reactor.shutdown
|
|
4
|
+
# Multiplexes client connections and closes them when they overrun
|
|
5
|
+
# their per-phase timeouts (first data, subsequent chunks, and
|
|
6
|
+
# keep-alive idle). Feeds ready bytes to the parser pipeline and hands
|
|
7
|
+
# completed requests back to the caller-provided handlers.
|
|
23
8
|
class Reactor
|
|
24
9
|
# A client connection node ordered by absolute expiry time so the
|
|
25
10
|
# soonest-to-expire is always at the tree's minimum.
|
|
@@ -27,7 +12,7 @@ module Raptor
|
|
|
27
12
|
# @rbs attr_accessor timeout_at: Float
|
|
28
13
|
attr_accessor timeout_at: untyped
|
|
29
14
|
|
|
30
|
-
#
|
|
15
|
+
# Returns the client connection state.
|
|
31
16
|
#
|
|
32
17
|
# @return [Hash] the client connection state
|
|
33
18
|
#
|
|
@@ -97,11 +82,8 @@ module Raptor
|
|
|
97
82
|
# @rbs (untyped ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped]) -> void
|
|
98
83
|
def initialize: (untyped ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped]) -> void
|
|
99
84
|
|
|
100
|
-
# Starts the reactor's main event loop in a new thread.
|
|
101
|
-
#
|
|
102
|
-
# The event loop handles I/O events, processes timeouts, manages
|
|
103
|
-
# the registration queue, and controls server connection acceptance.
|
|
104
|
-
# It continues until the queue is closed and emptied.
|
|
85
|
+
# Starts the reactor's main event loop in a new thread. Runs until
|
|
86
|
+
# the registration queue is closed and drained.
|
|
105
87
|
#
|
|
106
88
|
# @return [Thread] the thread running the reactor event loop
|
|
107
89
|
#
|
|
@@ -118,10 +100,8 @@ module Raptor
|
|
|
118
100
|
# @rbs (Hash[Symbol, untyped] state) -> void
|
|
119
101
|
def add: (Hash[Symbol, untyped] state) -> void
|
|
120
102
|
|
|
121
|
-
# Updates the state of an existing client connection
|
|
122
|
-
#
|
|
123
|
-
# Called when an incomplete HTTP request needs to be
|
|
124
|
-
# re-registered with the reactor for further processing.
|
|
103
|
+
# Updates the state of an existing client connection and re-registers
|
|
104
|
+
# it for further I/O.
|
|
125
105
|
#
|
|
126
106
|
# @param state [Hash] updated client connection state
|
|
127
107
|
# @option state [Integer] :id client identifier
|
|
@@ -140,11 +120,8 @@ module Raptor
|
|
|
140
120
|
# @rbs (Integer id) -> TCPSocket?
|
|
141
121
|
def remove: (Integer id) -> TCPSocket?
|
|
142
122
|
|
|
143
|
-
# Re-registers a kept-alive connection for the next request cycle
|
|
144
|
-
#
|
|
145
|
-
# Called after successfully writing a response when keep-alive is active.
|
|
146
|
-
# Resets the connection state and re-queues the socket in the selector
|
|
147
|
-
# using the persistent data timeout.
|
|
123
|
+
# Re-registers a kept-alive connection for the next request cycle
|
|
124
|
+
# under the persistent-data timeout.
|
|
148
125
|
#
|
|
149
126
|
# @param socket [TCPSocket] the kept-alive client socket
|
|
150
127
|
# @param id [Integer] the unique client identifier
|
|
@@ -158,9 +135,6 @@ module Raptor
|
|
|
158
135
|
|
|
159
136
|
# Returns the socket for a given client identifier without removing it.
|
|
160
137
|
#
|
|
161
|
-
# Used by HTTP/2 connections where the socket remains registered across
|
|
162
|
-
# multiple stream requests.
|
|
163
|
-
#
|
|
164
138
|
# @param id [Integer] unique client identifier
|
|
165
139
|
# @return [TCPSocket, nil] the socket, if found
|
|
166
140
|
#
|
|
@@ -168,8 +142,7 @@ module Raptor
|
|
|
168
142
|
def socket_for: (Integer id) -> TCPSocket?
|
|
169
143
|
|
|
170
144
|
# Returns the writer object associated with a given connection, if one
|
|
171
|
-
# was supplied when the connection was added.
|
|
172
|
-
# that need to coordinate concurrent socket writes.
|
|
145
|
+
# was supplied when the connection was added.
|
|
173
146
|
#
|
|
174
147
|
# @param id [Integer] unique client identifier
|
|
175
148
|
# @return [Object, nil] the writer, if found
|
|
@@ -177,9 +150,8 @@ module Raptor
|
|
|
177
150
|
# @rbs (Integer id) -> untyped?
|
|
178
151
|
def writer_for: (Integer id) -> untyped?
|
|
179
152
|
|
|
180
|
-
# Returns the flow controller associated with a given connection, if
|
|
181
|
-
# was supplied when the connection was added.
|
|
182
|
-
# dispatchers to honour the peer's flow-control windows.
|
|
153
|
+
# Returns the flow controller associated with a given connection, if
|
|
154
|
+
# one was supplied when the connection was added.
|
|
183
155
|
#
|
|
184
156
|
# @param id [Integer] unique client identifier
|
|
185
157
|
# @return [Object, nil] the flow controller, if found
|
|
@@ -187,10 +159,8 @@ module Raptor
|
|
|
187
159
|
# @rbs (Integer id) -> untyped?
|
|
188
160
|
def flow_control_for: (Integer id) -> untyped?
|
|
189
161
|
|
|
190
|
-
# Updates connection state for an HTTP/2 connection
|
|
191
|
-
#
|
|
192
|
-
# Re-registers the socket with the selector for further reads and stores
|
|
193
|
-
# the updated HPACK table and stream states.
|
|
162
|
+
# Updates connection state for an HTTP/2 connection and re-registers
|
|
163
|
+
# the socket for further reads.
|
|
194
164
|
#
|
|
195
165
|
# @param state [Hash] updated connection state from the ractor pool
|
|
196
166
|
# @return [void]
|
|
@@ -198,9 +168,8 @@ module Raptor
|
|
|
198
168
|
# @rbs (Hash[Symbol, untyped] state) -> void
|
|
199
169
|
def update_http2_state: (Hash[Symbol, untyped] state) -> void
|
|
200
170
|
|
|
201
|
-
# Closes the socket for the given connection and drops all reactor
|
|
202
|
-
# associated with it.
|
|
203
|
-
# a GOAWAY frame.
|
|
171
|
+
# Closes the socket for the given connection and drops all reactor
|
|
172
|
+
# state associated with it.
|
|
204
173
|
#
|
|
205
174
|
# @param id [Integer] unique client identifier
|
|
206
175
|
# @return [void]
|
|
@@ -242,8 +211,8 @@ module Raptor
|
|
|
242
211
|
# @rbs (TCPSocket socket) -> void
|
|
243
212
|
def wakeup!: (TCPSocket socket) -> void
|
|
244
213
|
|
|
245
|
-
# Reads data from a socket and either queues it for parsing
|
|
246
|
-
#
|
|
214
|
+
# Reads data from a socket and either queues it for parsing or
|
|
215
|
+
# returns it to the selector.
|
|
247
216
|
#
|
|
248
217
|
# @param socket [TCPSocket] the socket to read from and queue
|
|
249
218
|
# @param state [Hash] current connection state
|
|
@@ -260,7 +229,7 @@ module Raptor
|
|
|
260
229
|
# @rbs (TCPSocket socket) -> void
|
|
261
230
|
def cleanup: (TCPSocket socket) -> void
|
|
262
231
|
|
|
263
|
-
#
|
|
232
|
+
# Returns true when the request has been fully parsed.
|
|
264
233
|
#
|
|
265
234
|
# @param state [Hash] connection state
|
|
266
235
|
# @return [Boolean] true if the request is complete
|
|
@@ -14,8 +14,8 @@ module Raptor
|
|
|
14
14
|
|
|
15
15
|
BPF_OBJECT_PATH: untyped
|
|
16
16
|
|
|
17
|
-
#
|
|
18
|
-
#
|
|
17
|
+
# Returns true when the preconditions for BPF-directed reuseport are
|
|
18
|
+
# met on this platform.
|
|
19
19
|
#
|
|
20
20
|
# @return [Boolean]
|
|
21
21
|
#
|
|
@@ -45,6 +45,15 @@ module Raptor
|
|
|
45
45
|
# @rbs (Array[String] bind_uris, Integer worker_index, Integer socket_backlog) -> Array[TCPServer]
|
|
46
46
|
def self.create_worker_listeners: (Array[String] bind_uris, Integer worker_index, Integer socket_backlog) -> Array[TCPServer]
|
|
47
47
|
|
|
48
|
+
# Prepares this worker's load-reporting slot so subsequent
|
|
49
|
+
# {update_load} calls can publish its backlog.
|
|
50
|
+
#
|
|
51
|
+
# @param worker_index [Integer] slot index for this worker
|
|
52
|
+
# @return [void]
|
|
53
|
+
#
|
|
54
|
+
# @rbs (Integer worker_index) -> void
|
|
55
|
+
def self.enable_load_reporting: (Integer worker_index) -> void
|
|
56
|
+
|
|
48
57
|
# Publishes this worker's current backlog to the BPF map.
|
|
49
58
|
#
|
|
50
59
|
# @param backlog [Integer] the worker's current reactor backlog
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
# Generated from lib/raptor/server.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module Raptor
|
|
4
|
-
# Accepts client connections
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
# Supports TCP, Unix, and SSL listeners. SSL handshakes are offloaded
|
|
10
|
-
# to the thread pool so a slow client can't pin the server thread.
|
|
11
|
-
# For HTTP/1.1 the first request is parsed inline and dispatched
|
|
12
|
-
# straight to the thread pool; HTTP/2 (negotiated via ALPN) is
|
|
13
|
-
# registered with the reactor for frame processing.
|
|
14
|
-
#
|
|
15
|
-
# @example
|
|
16
|
-
# binder = Binder.new(["tcp://0.0.0.0:3000"])
|
|
17
|
-
# reactor = Reactor.new(ractor_pool, thread_pool, connection_options: {}, http1_options: {})
|
|
18
|
-
# http1 = Http1.new(app, 3000)
|
|
19
|
-
# http2 = Http2.new(app, 3000)
|
|
20
|
-
# server = Server.new(binder, reactor, thread_pool, http1, http2, connection_options: { first_data_timeout: 30 }, listeners: binder.listeners)
|
|
21
|
-
# server.run
|
|
22
|
-
# # ... later
|
|
23
|
-
# server.shutdown
|
|
4
|
+
# Accepts client connections on TCP, Unix, and SSL listeners and
|
|
5
|
+
# dispatches them into the request pipeline. Backs off from accepting
|
|
6
|
+
# when the reactor backlog is high so an overloaded process leaves
|
|
7
|
+
# connections for peers to absorb.
|
|
24
8
|
class Server
|
|
25
9
|
HTTP_SCHEME: ::String
|
|
26
10
|
|
|
@@ -72,11 +56,6 @@ module Raptor
|
|
|
72
56
|
|
|
73
57
|
# Starts the server's main accept loop in a new thread.
|
|
74
58
|
#
|
|
75
|
-
# The accept loop polls listening sockets for ready connections and accepts
|
|
76
|
-
# them when the reactor backlog is under the backpressure threshold. On
|
|
77
|
-
# Linux with BPF-directed dispatch active, a companion thread publishes
|
|
78
|
-
# this worker's backlog to the BPF map.
|
|
79
|
-
#
|
|
80
59
|
# @return [Thread] the thread running the accept loop
|
|
81
60
|
#
|
|
82
61
|
# @rbs () -> Thread
|
|
@@ -117,13 +96,8 @@ module Raptor
|
|
|
117
96
|
# @rbs () -> void
|
|
118
97
|
def drain_accept_queue: () -> void
|
|
119
98
|
|
|
120
|
-
# Accepts a connection from the given listener and dispatches it
|
|
121
|
-
#
|
|
122
|
-
# For SSL listeners the TLS handshake is offloaded to the thread pool so
|
|
123
|
-
# a slow client cannot block the server thread. For SSL connections with
|
|
124
|
-
# h2 negotiated via ALPN, the server sends initial SETTINGS and adds the
|
|
125
|
-
# connection to the reactor as an HTTP/2 connection. All other connections
|
|
126
|
-
# follow the HTTP/1.1 path.
|
|
99
|
+
# Accepts a connection from the given listener and dispatches it into
|
|
100
|
+
# the HTTP/1.1 or SSL/HTTP-2 pipeline.
|
|
127
101
|
#
|
|
128
102
|
# @param listener [TCPServer, UNIXServer, Binder::SslListener] the ready listener
|
|
129
103
|
# @return [Boolean] true if a connection was accepted, false if the listener had nothing to dispatch
|
|
@@ -131,9 +105,9 @@ module Raptor
|
|
|
131
105
|
# @rbs (TCPServer | UNIXServer | Binder::SslListener listener) -> bool
|
|
132
106
|
def accept_connection: (TCPServer | UNIXServer | Binder::SslListener listener) -> bool
|
|
133
107
|
|
|
134
|
-
# Performs the TLS handshake for an accepted SSL connection
|
|
135
|
-
# it through the HTTP/2 or
|
|
136
|
-
#
|
|
108
|
+
# Performs the TLS handshake for an accepted SSL connection, bounded
|
|
109
|
+
# by `:first_data_timeout`, and dispatches it through the HTTP/2 or
|
|
110
|
+
# HTTP/1.1 path.
|
|
137
111
|
#
|
|
138
112
|
# @param listener [Binder::SslListener] the SSL listener that accepted the connection
|
|
139
113
|
# @param tcp_client [TCPSocket] the accepted TCP socket
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# Generated from lib/raptor/stats.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module Raptor
|
|
4
|
-
# Shared
|
|
5
|
-
#
|
|
6
|
-
# Stats uses an anonymous mmap (MAP_ANON | MAP_SHARED) created before
|
|
7
|
-
# forking so that worker processes can write their stats and the master
|
|
8
|
-
# process can read them without any pipes or signals. Each worker is
|
|
9
|
-
# assigned a fixed-size slot in the shared region.
|
|
4
|
+
# Shared-memory store for per-worker process statistics. Each worker
|
|
5
|
+
# holds a fixed-size slot in an anonymous mmap region.
|
|
10
6
|
#
|
|
11
7
|
# Binary layout per slot (native byte order):
|
|
12
8
|
# pid uint32 4 bytes
|
|
@@ -29,8 +25,7 @@ module Raptor
|
|
|
29
25
|
|
|
30
26
|
@mmap: untyped
|
|
31
27
|
|
|
32
|
-
# Allocates the shared mmap region
|
|
33
|
-
# workers so the mapping is inherited by every child process.
|
|
28
|
+
# Allocates the shared mmap region for `num_workers` slots.
|
|
34
29
|
#
|
|
35
30
|
# @param num_workers [Integer] number of worker slots to allocate
|
|
36
31
|
# @return [void]
|