Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(traffic-controller): network traffic controller in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Sep 19, 2019
1 parent a39405d commit 6e87afa
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gnes/service/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6e87afa

Please sign in to comment.