0
votes

We are using Pyramid framework for our application and are using connection pooling. Currently connection pool size is 40. Wondering how to find how many connections are used in the application? Below snippet is used to create connection pool in application

engine = create_engine(Connection_URL, pool_size=20, max_overflow=0)

Currently we are using PostgreSQL and I am querying 'pg_stat_database' table to getting number of connections from application.

1
Generally you'd set the connection pool to equal the amount of simultaneous requests you want to handle. So if you have a WSGI server that spawns 10 threads, you'd want your connection pool to be of size 10.X-Istence

1 Answers

0
votes

You might want to use numbackends, according to official documentation:

numbackends: Number of backends currently connected to this database. This is the only column in this view that returns a value reflecting current state; all other columns return the accumulated values since the last reset.

In your case:

all_result = engine.execute("select * from pg_stat_database").fetchone()
print(all_result['numbackends'])         #returns current database connections