Skip to content

Commit

Permalink
Merge pull request #27 from SomberNight/fix_issue_26
Browse files Browse the repository at this point in the history
session._recalc_concurrency: handle time.time() not making progress
  • Loading branch information
Neil committed Oct 29, 2019
2 parents b8a77f8 + 3f40cbb commit 1b81d50
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions aiorpcx/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ def _recalc_concurrency(self):
current = self._outgoing_concurrency.max_concurrent
cap = min(current + max(3, current * 0.1), 250)
floor = max(1, min(current * 0.8, current - 1))
target = int(0.5 + max(floor, min(cap, current * self.target_response_time / avg)))
if avg != 0:
target = max(floor, min(cap, current * self.target_response_time / avg))
else:
target = cap
target = int(0.5 + target)
if target != current:
self.logger.info(f'changing outgoing request concurrency to {target} from {current}')
self._outgoing_concurrency.set_target(target)
Expand Down Expand Up @@ -494,7 +498,7 @@ async def _send_concurrent(self, message, future, request_count):
async with timeout_after(self.sent_request_timeout):
return await future
finally:
time_taken = time.time() - send_time
time_taken = max(0, time.time() - send_time)
if request_count == 1:
self._req_times.append(time_taken)
else:
Expand Down

0 comments on commit 1b81d50

Please sign in to comment.