Skip to content

Commit eeb4e29

Browse files
committed
clean up the run method
1 parent 0a6a86e commit eeb4e29

1 file changed

Lines changed: 27 additions & 20 deletions

File tree

lib/protobuf/rpc/servers/zmq/broker.rb

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,9 @@ def run
3333
# Something went wrong
3434
break if rc == -1
3535

36-
readables_include_backend = @poller.readables.include?(@backend_socket)
37-
message_count_read_from_backend = 0
38-
39-
while readables_include_backend && message_count_read_from_backend < backend_poll_weight do
40-
message_count_read_from_backend = message_count_read_from_backend + 1
41-
process_backend
42-
@poller.poll_nonblock
43-
readables_include_backend = @poller.readables.include?(@backend_socket)
44-
end
45-
36+
check_and_process_backend
4637
process_local_queue # Fair ordering so queued requests get in before new requests
47-
readables_include_frontend = @poller.readables.include?(@frontend_socket)
48-
message_count_read_from_frontend = 0
49-
50-
while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do
51-
message_count_read_from_frontend = message_count_read_from_frontend + 1
52-
process_frontend
53-
break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full
54-
@poller.poll_nonblock
55-
readables_include_frontend = @poller.readables.include?(@frontend_socket)
56-
end
38+
check_and_process_frontend
5739
end
5840
ensure
5941
teardown
@@ -69,6 +51,31 @@ def backend_poll_weight
6951
@backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 1].max
7052
end
7153

54+
def check_and_process_backend
55+
readables_include_backend = @poller.readables.include?(@backend_socket)
56+
message_count_read_from_backend = 0
57+
58+
while readables_include_backend && message_count_read_from_backend < backend_poll_weight do
59+
message_count_read_from_backend += 1
60+
process_backend
61+
@poller.poll_nonblock
62+
readables_include_backend = @poller.readables.include?(@backend_socket)
63+
end
64+
end
65+
66+
def check_and_process_frontend
67+
readables_include_frontend = @poller.readables.include?(@frontend_socket)
68+
message_count_read_from_frontend = 0
69+
70+
while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do
71+
message_count_read_from_frontend += 1
72+
process_frontend
73+
break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full
74+
@poller.poll_nonblock
75+
readables_include_frontend = @poller.readables.include?(@frontend_socket)
76+
end
77+
end
78+
7279
def frontend_poll_weight
7380
@frontend_poll_weight ||= [ENV["PB_ZMQ_SERVER_FRONTEND_POLL_WEIGHT"].to_i, 1].max
7481
end

0 commit comments

Comments
 (0)