Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if the pool has a free connection #381

Open
reifba opened this issue Oct 24, 2018 · 2 comments
Open

check if the pool has a free connection #381

reifba opened this issue Oct 24, 2018 · 2 comments

Comments

@reifba
Copy link

reifba commented Oct 24, 2018

Hi, I am trying to optimise the size of the connection pool ( I know its a much broader topic).
I've been playing around with setting a really low timeout, and looping while counting the timeouts (this is also meaningful only in the long running mean) .

My app has no use for persistent connections/transactions and a pool is used to allow for a higher throughput and every "fetch" is called on the pool instance.

any low hanging fruits here or should I try to rebuilding the library with some tracing on the acquire context?

@elprans
Copy link
Member

elprans commented Nov 28, 2018

There's no public method, but you can check pool._queue.qsize() for the number of free connections in it.

@alvassin
Copy link

alvassin commented Dec 25, 2019

@elprans thank you.

What is the correct way to calculate busy connections? Is this the correct way?

used_connections = sum(
    holder._in_use is not None
    for holder in pool._holders
)

I am trying to see metrics how are being used asyncpg connections, and this metric sometimes show very strange values (much more then Pool max_size value for example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants