From ea89d8cb4718dddc03bea216093af4ec211650da Mon Sep 17 00:00:00 2001 From: felix Date: Mon, 16 Sep 2019 18:37:17 +0800 Subject: [PATCH] feat(stream-call): only 1000 pending tasks --- gnes/service/frontend.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gnes/service/frontend.py b/gnes/service/frontend.py index 02b5d812..2775a082 100644 --- a/gnes/service/frontend.py +++ b/gnes/service/frontend.py @@ -142,10 +142,18 @@ def StreamCall(self, request_iterator, context): zmq_client.send_message(self.add_envelope(request, zmq_client), self.args.timeout) num_request += 1 - while True: + while num_request > 10: try: # fetch response in real time to reduce network overload - msg = zmq_client.recv_message(10) + timeout = 50 + if self.args.timeout > 0: + timeout = min(0.5 * self.args.timeout, 100) + + # only 1000 pending tasks are approved + if num_request > 1000: + timeout = -1 + + msg = zmq_client.recv_message(timeout) yield self.remove_envelope(msg) num_request -= 1 except TimeoutError: