pg.ddx.io pgsql-jdbc@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Recommendations for PGBouncer interacting with HikariCP 4+ messages / 3 participants [nested] [flat]
* Recommendations for PGBouncer interacting with HikariCP @ 2019-08-22 01:03 Joseph Hammerman <jhammerman@squarespace.com> 0 siblings, 1 reply; 4+ messages in thread From: Joseph Hammerman @ 2019-08-22 01:03 UTC (permalink / raw) To: pgsql-jdbc@lists.postgresql.org Hi pgsql-jdbc email distribution list, We have recently added PGBouncer into our stack. We have done this in part, to protect the database. Our Java userbase is accustomed to using HikariCP / Hibernate for connection pooling. They would prefer to continue to use the connection pooler, in order to not have GC churn on connection spin up and tear down (in addition to additional latency introduced by having to perform the three-way handshake more often). Is there any published material / does anyone have any knowledge of how these tools should interact or not interact? HikariCP wants to keep many long running idle_in_transaction connections open, which saturates the backend connection pool. Thanks in advance for any assistance anyone can provide, Joe ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Recommendations for PGBouncer interacting with HikariCP @ 2019-08-23 20:39 Dave Cramer <pg@fastcrypt.com> parent: Joseph Hammerman <jhammerman@squarespace.com> 0 siblings, 1 reply; 4+ messages in thread From: Dave Cramer @ 2019-08-23 20:39 UTC (permalink / raw) To: Joseph Hammerman <jhammerman@squarespace.com>; +Cc: pgsql-jdbc@lists.postgresql.org On Wed, 21 Aug 2019 at 21:03, Joseph Hammerman <jhammerman@squarespace.com> wrote: > Hi pgsql-jdbc email distribution list, > > We have recently added PGBouncer into our stack. We have done this in > part, to protect the database. Our Java userbase is accustomed to using > HikariCP / Hibernate for connection pooling. They would prefer to continue > to use the connection pooler, in order to not have GC churn on connection > spin up and tear down (in addition to additional latency introduced by > having to perform the three-way handshake more often). > > Is there any published material / does anyone have any knowledge of how > these tools should interact or not interact? > JDBC should work fine with pgbouncer. > HikariCP wants to keep many long running idle_in_transaction connections > open, which saturates the backend connection pool. > That's strange why is it keeping them in transaction ? One would think once you closed (returned the connection) it should commit it. > > Thanks in advance for any assistance anyone can provide, > Joe > Dave Cramer davec@postgresintl.com www.postgresintl.com ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Recommendations for PGBouncer interacting with HikariCP @ 2019-08-23 21:53 Steven Schlansker <stevenschlansker@gmail.com> parent: Dave Cramer <pg@fastcrypt.com> 0 siblings, 1 reply; 4+ messages in thread From: Steven Schlansker @ 2019-08-23 21:53 UTC (permalink / raw) To: Dave Cramer <pg@fastcrypt.com>; +Cc: Joseph Hammerman <jhammerman@squarespace.com>; pgsql-jdbc@lists.postgresql.org > On Aug 23, 2019, at 1:39 PM, Dave Cramer <pg@fastcrypt.com> wrote: > > On Wed, 21 Aug 2019 at 21:03, Joseph Hammerman <jhammerman@squarespace.com> wrote: > Hi pgsql-jdbc email distribution list, > > We have recently added PGBouncer into our stack. We have done this in part, to protect the database. Our Java userbase is accustomed to using HikariCP / Hibernate for connection pooling. They would prefer to continue to use the connection pooler, in order to not have GC churn on connection spin up and tear down (in addition to additional latency introduced by having to perform the three-way handshake more often). > >> Is there any published material / does anyone have any knowledge of how these tools should interact or not interact? > > JDBC should work fine with pgbouncer. Most things do, although there are some caveats. For example if you have anything attached to your server session *outside* of a txn (say, server-side prepared statements or session vars) and you configure your pgbouncer for transaction pooling, you can end up creating some extremely difficult to understand behaviors. https://pgbouncer.github.io/faq.html#how-to-use-prepared-statements-with-transaction-pooling So you do have to be a little bit careful. > >> HikariCP wants to keep many long running idle_in_transaction connections open, which saturates the backend connection pool. > > That's strange why is it keeping them in transaction ? One would think once you closed (returned the connection) it should commit it. My personal experience working with JDBC and HikariCP is that 99.9% of the time, "idle in transaction" means that some programmer somewhere actually did not close their resource. I did end up finding numerous bugs, both in my $WORK's code as well as in Java libraries we use, although to the best of my memory the roots of problems we found were never in either PgJDBC nor HikariCP. To diagnose these nasty issues, we took a pretty extreme method: on every checkout from the HikariCP pool, we generate a UUID and print a tagged stack trace to a file. We then set `application_name` to "app_name-$UUID". When our DBAs found an "idle in txn" connection that we did not know where it came from, we would immediately have the app and could then look up the stack trace of the last allocation site using the application_name in pg_stat_activity. From there it was usually straightforward, if painful, to diagnose the problem: "Oh I opened a Hibernate session and handed it off to a Reactive actor that threw an exception but it never got handled and so the Connection was never closed and the whole thing got leaked. Whoops. But look at how *fast* Reactive is!!!" Hope that gives you some ideas. ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Recommendations for PGBouncer interacting with HikariCP @ 2019-08-27 10:39 Dave Cramer <pg@fastcrypt.com> parent: Steven Schlansker <stevenschlansker@gmail.com> 0 siblings, 0 replies; 4+ messages in thread From: Dave Cramer @ 2019-08-27 10:39 UTC (permalink / raw) To: Steven Schlansker <stevenschlansker@gmail.com>; +Cc: Joseph Hammerman <jhammerman@squarespace.com>; pgsql-jdbc@lists.postgresql.org On Fri, 23 Aug 2019 at 17:54, Steven Schlansker <stevenschlansker@gmail.com> wrote: > > > On Aug 23, 2019, at 1:39 PM, Dave Cramer <pg@fastcrypt.com> wrote: > > > > On Wed, 21 Aug 2019 at 21:03, Joseph Hammerman < > jhammerman@squarespace.com> wrote: > > Hi pgsql-jdbc email distribution list, > > > > We have recently added PGBouncer into our stack. We have done this in > part, to protect the database. Our Java userbase is accustomed to using > HikariCP / Hibernate for connection pooling. They would prefer to continue > to use the connection pooler, in order to not have GC churn on connection > spin up and tear down (in addition to additional latency introduced by > having to perform the three-way handshake more often). > > > >> Is there any published material / does anyone have any knowledge of how > these tools should interact or not interact? > > > > JDBC should work fine with pgbouncer. > > Most things do, although there are some caveats. For example if you have > anything attached to your server session *outside* of a txn > (say, server-side prepared statements or session vars) > and you configure your pgbouncer for transaction pooling, you can end up > creating some extremely difficult to understand behaviors. > > > https://pgbouncer.github.io/faq.html#how-to-use-prepared-statements-with-transaction-pooling > > So you do have to be a little bit careful. > > > > >> HikariCP wants to keep many long running idle_in_transaction > connections open, which saturates the backend connection pool. > > > > That's strange why is it keeping them in transaction ? One would think > once you closed (returned the connection) it should commit it. > > My personal experience working with JDBC and HikariCP is that 99.9% of the > time, "idle in transaction" means that some programmer somewhere > actually did not close their resource. I did end up finding numerous > bugs, both in my $WORK's code as well as in Java libraries we use, although > to the > best of my memory the roots of problems we found were never in either > PgJDBC nor HikariCP. > > To diagnose these nasty issues, we took a pretty extreme method: on every > checkout from the HikariCP pool, we generate a UUID and > print a tagged stack trace to a file. We then set `application_name` to > "app_name-$UUID". > > Excellent idea! > When our DBAs found an "idle in txn" connection that we did not know where > it came from, we would immediately have the app and could > then look up the stack trace of the last allocation site using the > application_name in pg_stat_activity. > > From there it was usually straightforward, if painful, to diagnose the > problem: "Oh I opened a Hibernate session and handed it off to a Reactive > actor that threw an exception but it never got handled and so the > Connection was never closed and the whole thing got leaked. Whoops. But > look at how *fast* Reactive is!!!" > Interesting > > Hope that gives you some ideas. > Thanks for the insight Dave Cramer davec@postgresintl.com www.postgresintl.com ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-08-27 10:39 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-08-22 01:03 Recommendations for PGBouncer interacting with HikariCP Joseph Hammerman <jhammerman@squarespace.com> 2019-08-23 20:39 ` Dave Cramer <pg@fastcrypt.com> 2019-08-23 21:53 ` Steven Schlansker <stevenschlansker@gmail.com> 2019-08-27 10:39 ` Dave Cramer <pg@fastcrypt.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox