Skip to content

Commit

Permalink
Keep stealing from the same block
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Feb 13, 2024
1 parent 1adb29e commit 6c10abe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions edb/server/connpool/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,16 @@ def _tick(self) -> None:
# the starving blocks.

for block in list(self._blocks.values()):
nconns = block.count_conns()
num_waiters = block.count_waiters()
if nconns > num_waiters:
if (conn := block.try_steal()) is not None:
if not self._maybe_free_conn(block, conn):
block.release(conn)
while block.count_conns() > block.count_waiters():
if (conn := block.try_steal()) is None:
# no more from this block
break

elif not self._maybe_free_conn(block, conn):
# put back the last stolen connection if we
# don't need to steal anymore
block.release(conn)
return

else:
# Mode C: distribute the total connections by calibrated demand
Expand Down

0 comments on commit 6c10abe

Please sign in to comment.