bayserver-core 2.2.2 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/baykit/bayserver/agent/command_receiver.rb +1 -1
- data/lib/baykit/bayserver/agent/grand_agent.rb +89 -76
- data/lib/baykit/bayserver/agent/grand_agent_monitor.rb +1 -0
- data/lib/baykit/bayserver/agent/lifecycle_listener.rb +16 -0
- data/lib/baykit/bayserver/agent/non_blocking_handler.rb +37 -8
- data/lib/baykit/bayserver/agent/signal/signal_sender.rb +1 -0
- data/lib/baykit/bayserver/agent/spin_handler.rb +16 -0
- data/lib/baykit/bayserver/agent/timer_handler.rb +15 -0
- data/lib/baykit/bayserver/docker/base/inbound_ship.rb +20 -51
- data/lib/baykit/bayserver/docker/base/inbound_ship_store.rb +2 -1
- data/lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb +3 -2
- data/lib/baykit/bayserver/docker/built_in/write_file_taxi.rb +8 -2
- data/lib/baykit/bayserver/docker/warp/warp_data.rb +8 -0
- data/lib/baykit/bayserver/docker/warp/warp_data_listener.rb +9 -9
- data/lib/baykit/bayserver/docker/warp/warp_docker.rb +2 -1
- data/lib/baykit/bayserver/docker/warp/warp_ship.rb +32 -3
- data/lib/baykit/bayserver/mem_usage.rb +2 -1
- data/lib/baykit/bayserver/protocol/packet_store.rb +2 -1
- data/lib/baykit/bayserver/protocol/protocol_handler_store.rb +2 -1
- data/lib/baykit/bayserver/taxi/taxi.rb +1 -0
- data/lib/baykit/bayserver/taxi/taxi_runner.rb +94 -5
- data/lib/baykit/bayserver/tours/read_file_taxi.rb +46 -23
- data/lib/baykit/bayserver/tours/send_file_yacht.rb +5 -1
- data/lib/baykit/bayserver/tours/tour.rb +5 -6
- data/lib/baykit/bayserver/tours/tour_req.rb +28 -28
- data/lib/baykit/bayserver/tours/tour_res.rb +93 -31
- data/lib/baykit/bayserver/tours/tour_store.rb +2 -1
- data/lib/baykit/bayserver/util/executor_service.rb +27 -10
- data/lib/baykit/bayserver/version.rb +1 -1
- metadata +4 -2
@@ -82,6 +82,7 @@ module Baykit
|
|
82
82
|
@bytes_posted = 0
|
83
83
|
@bytes_consumed = 0
|
84
84
|
@bytes_limit = 0
|
85
|
+
@tour_returned = false
|
85
86
|
end
|
86
87
|
|
87
88
|
######################################################
|
@@ -121,8 +122,16 @@ module Baykit
|
|
121
122
|
end
|
122
123
|
end
|
123
124
|
|
124
|
-
|
125
|
-
|
125
|
+
begin
|
126
|
+
@tour.ship.send_headers(@tour.ship_id, @tour)
|
127
|
+
rescue IOError => e
|
128
|
+
BayLog.debug_e(e, "%s abort: %s", @tour, e)
|
129
|
+
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
|
130
|
+
raise e
|
131
|
+
ensure
|
132
|
+
@header_sent = true
|
133
|
+
end
|
134
|
+
|
126
135
|
end
|
127
136
|
|
128
137
|
def send_redirect(chk_tour_id, status, location)
|
@@ -132,9 +141,15 @@ module Baykit
|
|
132
141
|
BayLog.error("Try to redirect after response header is sent (Ignore)")
|
133
142
|
else
|
134
143
|
set_consume_listener(&ContentConsumeListener::DEV_NULL)
|
135
|
-
|
136
|
-
|
137
|
-
|
144
|
+
begin
|
145
|
+
@tour.ship.send_redirect(@tour.ship_id, @tour, status, location)
|
146
|
+
rescue IOError => e
|
147
|
+
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
|
148
|
+
raise e
|
149
|
+
ensure
|
150
|
+
@header_sent = true
|
151
|
+
end_content(chk_tour_id)
|
152
|
+
end
|
138
153
|
end
|
139
154
|
|
140
155
|
end
|
@@ -170,27 +185,31 @@ module Baykit
|
|
170
185
|
raise Sink.new("Response consume listener is null")
|
171
186
|
end
|
172
187
|
|
188
|
+
@bytes_posted += len
|
173
189
|
BayLog.debug("%s posted res content len=%d posted=%d limit=%d consumed=%d",
|
174
190
|
@tour, len, @bytes_posted, @bytes_limit, @bytes_consumed)
|
175
191
|
if @bytes_limit > 0 && @bytes_limit < self.bytes_posted
|
176
192
|
raise ProtocolException.new("Post data exceed content-length: " + @bytes_posted + "/" + @bytes_limit)
|
177
193
|
end
|
178
194
|
|
179
|
-
if @
|
180
|
-
|
195
|
+
if @tour.zombie? || @tour.aborted?
|
196
|
+
# Don't send peer any data
|
197
|
+
BayLog::debug("%s Aborted or zombie tour. do nothing: %s state=%s", self, @tour, @tour.state)
|
198
|
+
done_lis.call()
|
181
199
|
else
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
200
|
+
if @can_compress
|
201
|
+
get_compressor().compress(buf, ofs, len, &done_lis)
|
202
|
+
else
|
203
|
+
begin
|
204
|
+
@tour.ship.send_res_content(@tour.ship_id, @tour, buf, ofs, len, &done_lis)
|
205
|
+
rescue IOError => e
|
206
|
+
done_lis.call()
|
207
|
+
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
|
208
|
+
raise e
|
209
|
+
end
|
187
210
|
end
|
188
211
|
end
|
189
212
|
|
190
|
-
@bytes_posted += len
|
191
|
-
|
192
|
-
BayLog.debug("%s post res content: len=%d posted=%d limit=%d consumed=%d",
|
193
|
-
@tour, len, @bytes_posted, @bytes_limit, @bytes_consumed)
|
194
213
|
|
195
214
|
old_available = @available
|
196
215
|
if !buffer_available()
|
@@ -208,6 +227,10 @@ module Baykit
|
|
208
227
|
@tour.check_tour_id(chk_tour_id)
|
209
228
|
|
210
229
|
BayLog.debug("%s end ResContent", self)
|
230
|
+
if @tour.ended?
|
231
|
+
BayLog.debug("%s Tour is already ended (Ignore).", self)
|
232
|
+
return
|
233
|
+
end
|
211
234
|
|
212
235
|
if !@tour.zombie? && @tour.city != nil
|
213
236
|
@tour.city.log(@tour)
|
@@ -220,15 +243,34 @@ module Baykit
|
|
220
243
|
|
221
244
|
|
222
245
|
# Done listener
|
246
|
+
tour_returned = false
|
223
247
|
done_lis = Proc.new() do
|
248
|
+
@tour.check_tour_id(chk_tour_id)
|
224
249
|
@tour.ship.return_tour(@tour)
|
250
|
+
tour_returned = true
|
225
251
|
end
|
226
252
|
|
227
253
|
begin
|
228
|
-
@tour.
|
229
|
-
|
230
|
-
|
231
|
-
|
254
|
+
if @tour.zombie? || @tour.aborted?
|
255
|
+
# Don't send peer any data. Do nothing
|
256
|
+
BayLog.debug("%s Aborted or zombie tour. do nothing: %s state=%s", self, @tour, @tour.state)
|
257
|
+
done_lis.call()
|
258
|
+
else
|
259
|
+
begin
|
260
|
+
@tour.ship.send_end_tour(@tour.ship_id, @tour, &done_lis)
|
261
|
+
rescue IOError => e
|
262
|
+
BayLog.debug("%s Error on sending end tour", self)
|
263
|
+
done_lis.call()
|
264
|
+
raise e
|
265
|
+
end
|
266
|
+
end
|
267
|
+
ensure
|
268
|
+
# If tour is returned, we cannot change its state because
|
269
|
+
# it will become uninitialized.
|
270
|
+
BayLog.debug("%s tur#%d is returned: %s", self, chk_tour_id, tour_returned)
|
271
|
+
if !tour_returned
|
272
|
+
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ENDED)
|
273
|
+
end
|
232
274
|
end
|
233
275
|
end
|
234
276
|
|
@@ -281,15 +323,26 @@ module Baykit
|
|
281
323
|
end
|
282
324
|
|
283
325
|
if @header_sent
|
284
|
-
BayLog.
|
285
|
-
BayLog.
|
326
|
+
BayLog.debug("Try to send error after response header is sent (Ignore)")
|
327
|
+
BayLog.debug("%s: status=%d, message=%s", self, status, msg)
|
286
328
|
if err != nil
|
287
329
|
BayLog.error_e(err);
|
288
330
|
end
|
289
331
|
else
|
290
332
|
set_consume_listener(&ContentConsumeListener::DEV_NULL)
|
291
|
-
|
292
|
-
@
|
333
|
+
|
334
|
+
if @tour.zombie? || @tour.aborted?
|
335
|
+
# Don't send peer any data. Do nothing
|
336
|
+
BayLog.debug("%s Aborted or zombie tour. do nothing: %s state=%s", self, @tour, @tour.state)
|
337
|
+
else
|
338
|
+
begin
|
339
|
+
@tour.ship.send_error(@tour.ship_id, @tour, status, msg, err)
|
340
|
+
rescue IOError => e
|
341
|
+
BayLog.debug("%s Error on sending error", self)
|
342
|
+
@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED)
|
343
|
+
end
|
344
|
+
@header_sent = true
|
345
|
+
end
|
293
346
|
end
|
294
347
|
|
295
348
|
end_content(chk_tour_id)
|
@@ -306,7 +359,7 @@ module Baykit
|
|
306
359
|
|
307
360
|
if File.directory?(file)
|
308
361
|
raise HttpException.new HttpStatus::FORBIDDEN, file
|
309
|
-
elsif !File.
|
362
|
+
elsif !File.exist?(file)
|
310
363
|
raise HttpException.new HttpStatus::NOT_FOUND, file
|
311
364
|
end
|
312
365
|
|
@@ -357,11 +410,11 @@ module Baykit
|
|
357
410
|
tp.open_valve()
|
358
411
|
|
359
412
|
when Harbor::FILE_SEND_METHOD_TAXI
|
360
|
-
txi = ReadFileTaxi.new(bufsize)
|
413
|
+
txi = ReadFileTaxi.new(@tour.ship.agent.agent_id, bufsize)
|
361
414
|
@yacht.init(@tour, file, txi)
|
362
415
|
txi.init(File.open(file, "rb"), @yacht)
|
363
|
-
if !TaxiRunner.post(txi)
|
364
|
-
raise HttpException.new(HttpStatus
|
416
|
+
if !TaxiRunner.post(@tour.ship.agent.agent_id, txi)
|
417
|
+
raise HttpException.new(HttpStatus::SERVICE_UNAVAILABLE, "Taxi is busy!");
|
365
418
|
end
|
366
419
|
|
367
420
|
else
|
@@ -382,9 +435,18 @@ module Baykit
|
|
382
435
|
|
383
436
|
def get_compressor()
|
384
437
|
if @compressor == nil
|
385
|
-
|
386
|
-
|
387
|
-
|
438
|
+
sip_id = @tour.ship.ship_id
|
439
|
+
tur_id = @tour.tour_id
|
440
|
+
gz_callback = lambda do |new_buf, new_ofs, new_len, &lis|
|
441
|
+
begin
|
442
|
+
@tour.ship.send_res_content(sip_id, @tour, new_buf, new_ofs, new_len, &lis)
|
443
|
+
rescue IOError => e
|
444
|
+
@tour.change_state(tur_id, Tour::TourState::ABORTED)
|
445
|
+
raise e
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
@compressor = GzipCompressor.new(gz_callback)
|
388
450
|
end
|
389
451
|
|
390
452
|
return @compressor
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'baykit/bayserver/agent/grand_agent'
|
2
|
+
require 'baykit/bayserver/agent/lifecycle_listener'
|
2
3
|
require 'baykit/bayserver/tours/tour'
|
3
4
|
require 'baykit/bayserver/util/string_util'
|
4
5
|
|
@@ -15,7 +16,7 @@ module Baykit
|
|
15
16
|
|
16
17
|
|
17
18
|
class AgentListener
|
18
|
-
include Baykit::BayServer::Agent::
|
19
|
+
include Baykit::BayServer::Agent::LifecycleListener # implements
|
19
20
|
|
20
21
|
def add(agt)
|
21
22
|
TourStore.stores[agt.agent_id] = TourStore.new();
|
@@ -20,17 +20,25 @@ module Baykit
|
|
20
20
|
@name = name
|
21
21
|
end
|
22
22
|
|
23
|
+
def to_s
|
24
|
+
@name
|
25
|
+
end
|
26
|
+
|
23
27
|
def run
|
24
28
|
while true
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
block = @que.deq
|
30
|
+
if block == nil
|
31
|
+
break
|
32
|
+
end
|
33
|
+
BayLog.debug("Start task on: %s", @name)
|
34
|
+
block.call
|
35
|
+
BayLog.debug("End task on: %s", @name)
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
|
-
def
|
33
|
-
@
|
39
|
+
def shutdown
|
40
|
+
@que.pop until @que.empty?
|
41
|
+
@que.enq(nil)
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
@@ -40,12 +48,14 @@ module Baykit
|
|
40
48
|
attr :count
|
41
49
|
attr :max_queue_len
|
42
50
|
attr :name
|
51
|
+
attr :executors
|
43
52
|
|
44
53
|
def initialize(name, count)
|
45
54
|
@que = Thread::Queue.new
|
46
55
|
@count = count
|
47
56
|
@max_queue_len = MAX_LEN_PER_EXECUTOR * count
|
48
57
|
@name = name
|
58
|
+
@executors = []
|
49
59
|
|
50
60
|
count.times do |i|
|
51
61
|
started = false
|
@@ -56,6 +66,7 @@ module Baykit
|
|
56
66
|
Thread.current.name = th_name
|
57
67
|
e = Executor.new @que, id, th_name
|
58
68
|
e.run
|
69
|
+
@executors << e
|
59
70
|
end
|
60
71
|
while !started
|
61
72
|
sleep(0.01)
|
@@ -63,17 +74,23 @@ module Baykit
|
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
66
|
-
def to_s
|
77
|
+
def to_s
|
67
78
|
return "ExecutorService[#{@name}]"
|
68
79
|
end
|
69
80
|
|
70
81
|
# post task
|
71
|
-
def submit(
|
72
|
-
BayLog.debug("%s Submit:
|
82
|
+
def submit(&block)
|
83
|
+
BayLog.debug("%s Submit: (qlen=%d/%d)", self, @que.length, @max_queue_len)
|
73
84
|
if @que.length > @max_queue_len
|
74
85
|
raise IOError("Task queue is full (>_<)")
|
75
86
|
end
|
76
|
-
@que.enq(
|
87
|
+
@que.enq(block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def shutdown
|
91
|
+
@executors.each do |exe|
|
92
|
+
exe.shutdown
|
93
|
+
end
|
77
94
|
end
|
78
95
|
end
|
79
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bayserver-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michisuke-P
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: BayServer is one of the high-speed web servers. It operates as a single-threaded,
|
14
14
|
asynchronous server, which makes it exceptionally fast. It also supports multi-core
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/baykit/bayserver/agent/command_receiver.rb
|
26
26
|
- lib/baykit/bayserver/agent/grand_agent.rb
|
27
27
|
- lib/baykit/bayserver/agent/grand_agent_monitor.rb
|
28
|
+
- lib/baykit/bayserver/agent/lifecycle_listener.rb
|
28
29
|
- lib/baykit/bayserver/agent/next_socket_action.rb
|
29
30
|
- lib/baykit/bayserver/agent/non_blocking_handler.rb
|
30
31
|
- lib/baykit/bayserver/agent/package.rb
|
@@ -32,6 +33,7 @@ files:
|
|
32
33
|
- lib/baykit/bayserver/agent/signal/signal_proxy.rb
|
33
34
|
- lib/baykit/bayserver/agent/signal/signal_sender.rb
|
34
35
|
- lib/baykit/bayserver/agent/spin_handler.rb
|
36
|
+
- lib/baykit/bayserver/agent/timer_handler.rb
|
35
37
|
- lib/baykit/bayserver/agent/transporter/data_listener.rb
|
36
38
|
- lib/baykit/bayserver/agent/transporter/package.rb
|
37
39
|
- lib/baykit/bayserver/agent/transporter/plain_transporter.rb
|