Gustavo R. Montesino
2016-06-06 11:32:15 UTC
Hello,
WeÂŽre having some trouble with a postgresql / pgbouncer setup due to the
huge amount of idle in transaction sessions kept by the application: If we
set a smallish (proper) pool the server connections are filled by idle
transactions and the app pretty much dies, if we set a bigger pool
sometimes we get too many active sessions on database and response time
goes too high.
While I think thatÂŽs an application-side problema and should be fixed
there, I also believe that it would be possible for pgbouncer to allow some
alternative handling of idle transactions that would allow to better tune
and use db server resources... To that end, IÂŽve been thinking on something
along these lines:
- Add a new pool mode (just to keep current ones behaviour unchanged);
- Add a new client list for idle in transaction sessions;
- Add a new server list/pool/queue to handle re-activated idle in
transaction sessions;
- Add a new config to allow setting the max ammount of idle in transaction
sessions to run in parallel;
- When a session goes idle in transaction, take the client/server out of
the regular list/queue/pool and allow some other new/waiting client to get
a new server connection;
- Whan a idle in transaction session wakes up enqueue/run it according to
the new setting / server pool
The idea would be that pool size could be tunned to the server capacity,
without worries about the idle transactions, and those would also get their
exclusive "pool" so that they get to run when needed; at first I thought
they could just get on the regular queue but I guess that could generate
deadlocking if the idle transactions hold locks needed by all active ones.
As I donÂŽt really know pgbouncer (or postgresql) internals, I might be
missing something; does that sound reasonable / doable?
Thanks and regards,
Gustavo R. Montesino
WeÂŽre having some trouble with a postgresql / pgbouncer setup due to the
huge amount of idle in transaction sessions kept by the application: If we
set a smallish (proper) pool the server connections are filled by idle
transactions and the app pretty much dies, if we set a bigger pool
sometimes we get too many active sessions on database and response time
goes too high.
While I think thatÂŽs an application-side problema and should be fixed
there, I also believe that it would be possible for pgbouncer to allow some
alternative handling of idle transactions that would allow to better tune
and use db server resources... To that end, IÂŽve been thinking on something
along these lines:
- Add a new pool mode (just to keep current ones behaviour unchanged);
- Add a new client list for idle in transaction sessions;
- Add a new server list/pool/queue to handle re-activated idle in
transaction sessions;
- Add a new config to allow setting the max ammount of idle in transaction
sessions to run in parallel;
- When a session goes idle in transaction, take the client/server out of
the regular list/queue/pool and allow some other new/waiting client to get
a new server connection;
- Whan a idle in transaction session wakes up enqueue/run it according to
the new setting / server pool
The idea would be that pool size could be tunned to the server capacity,
without worries about the idle transactions, and those would also get their
exclusive "pool" so that they get to run when needed; at first I thought
they could just get on the regular queue but I guess that could generate
deadlocking if the idle transactions hold locks needed by all active ones.
As I donÂŽt really know pgbouncer (or postgresql) internals, I might be
missing something; does that sound reasonable / doable?
Thanks and regards,
Gustavo R. Montesino