Skip to content

Commit

Permalink
Explicitly return active connection count
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac committed Jul 24, 2024
1 parent 814b212 commit 8551dda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion edb/server/connpool/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ def failed_connects(self) -> int:
def failed_disconnects(self) -> int:
return self._failed_disconnects

def get_pending_conns(self) -> int:
@property
def active_conns(self) -> int:
return self.current_capacity - self._get_pending_conns()

def _get_pending_conns(self) -> int:
return sum(
block.count_pending_conns() for block in self._blocks.values()
)
Expand Down
8 changes: 6 additions & 2 deletions edb/server/connpool/pool2.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ async def _boot(self, loop: asyncio.AbstractEventLoop) -> None:
elif msg[0] == 4:
loop.create_task(self._perform_prune(msg[1]))

# Allow readers to skip the self-pipe for performing reads which may reduce
# latency a small degree. We'll still need to eventually pick up a self-pipe
# read but we increment a counter to skip at that point.
def _try_read(self) -> None:
while msg := self._pool._try_read():
self._skip_reads += 1
Expand Down Expand Up @@ -234,8 +237,9 @@ async def prune_all_connections(self) -> None:
coros.append(self._disconnect(conn))
await asyncio.gather(*coros, return_exceptions=True)

def get_pending_conns(self) -> int:
return 0
@property
def active_conns(self) -> int:
return len(self._conns_held)

def iterate_connections(self) -> typing.Iterator[C]:
for conn in self._conns.values():
Expand Down
4 changes: 1 addition & 3 deletions edb/server/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ def on_switch_over(self):
)

def get_active_pgcon_num(self) -> int:
return (
self._pg_pool.current_capacity - self._pg_pool.get_pending_conns()
)
return self._pg_pool.active_conns

@property
def client_id(self) -> int:
Expand Down

0 comments on commit 8551dda

Please sign in to comment.