Skip to content
Permalink
Browse files

feat(traffic-controller): network traffic controller in frontend

  • Loading branch information...
numb3r3 committed Sep 19, 2019
1 parent a39405d commit 6e87afa4afa2d9d85842a6cac38b1bf6a69392e6
Showing with 10 additions and 7 deletions.
  1. +10 −7 gnes/service/frontend.py
@@ -138,22 +138,25 @@ def Search(self, request, context):
def StreamCall(self, request_iterator, context):
with self.zmq_context as zmq_client:
num_request = 0
# network traffic control
max_outstanding = 1000
for request in request_iterator:
zmq_client.send_message(self.add_envelope(request, zmq_client), -1)
num_request += 1
timeout = 25
if self.args.timeout > 0:
timeout = min(0.5 * self.args.timeout, 50)

while num_request > 10:
try:
# fetch response in real time to reduce network overload
timeout = 50
if self.args.timeout > 0:
timeout = min(0.5 * self.args.timeout, 100)

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

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

0 comments on commit 6e87afa

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