Skip to content
Permalink
Browse files

fix(frontend): use poll for better efficiency

  • Loading branch information...
hanxiao committed Sep 24, 2019
1 parent fede29c commit 82951d9571331f963f6428a245568243d9b41fd9
Showing with 5 additions and 17 deletions.
  1. +5 −17 gnes/service/frontend.py
@@ -102,29 +102,17 @@ def Search(self, request, context):

def StreamCall(self, request_iterator, context):
with self.zmq_context as zmq_client:
# network traffic control
num_request = 0
max_outstanding = 500

for request in request_iterator:
timeout = 25
if self.args.timeout > 0:
timeout = min(0.5 * self.args.timeout, 50)

while num_request > 10:
try:
msg = zmq_client.recv_message(timeout)
yield self.remove_envelope(msg)
num_request -= 1
except TimeoutError:
if num_request > max_outstanding:
self.logger.warning("the network traffic exceed max outstanding (%d > %d)" % (
num_request, max_outstanding))
continue
break
zmq_client.send_message(self.add_envelope(request, zmq_client), -1)
num_request += 1

if zmq_client.receiver.poll(1):
msg = zmq_client.recv_message(self.args.timeout)
num_request -= 1
yield self.remove_envelope(msg)

for _ in range(num_request):
msg = zmq_client.recv_message(self.args.timeout)
yield self.remove_envelope(msg)

0 comments on commit 82951d9

Please sign in to comment.
You can’t perform that action at this time.