Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HikariCP/Apache DBCP2 and PgBouncer

After switching to PgBouncer in a Spring application that uses HikariCP(or Apache DBCP2) do I need to make additional configuration for HikriCP(or Apache DBCP2) side?

like image 657
Radu Dumbrăveanu Avatar asked Mar 03 '23 20:03

Radu Dumbrăveanu


1 Answers

If you are using PgBouncer, then you definitely don't need HikariCP around.

The reasoning is simple, a Database connection pool was invented to protect the database from the huge memory and performance cost of establishing a Database Connection and tearing it down to the server (A Database Connection is not a TCP connection, it is much more than that). The database connection pool accomplishes that by reusing already establish backend connections taking place. And this is already fulfilled with PgBouncer.

The space between HikariCP and PgBouncer is no longer a Database connection world, but rather a TCP connection, which is much more cheaper to construct specially in the same data center and doesn't require extra memory and CPU to construct.

Infact, using HikariCP infront of PgBouncer is like using an HTTP Connection Pool to re-use HTTP connections in-front your NGINX Webserver. Which I don't think anyone would find useful.

Also, having a Hikari connection pool for an application will limit the maximum connections it can use when it's heavy loaded. So let's say you have Microservice A, Microservice B and Microservice C. And let's assume microservice A requires high throughput to the database while B and C are light loaded throughput. Having HikariCP with a pool size of 10 on each microservice will just create a bottle neck for microservice A completely and will require you go through some performance optimization drills to resize the pool every now and then which is completely unnecessary.

DISCLAIMER: I'm curious of any counter arguments against what I just mentioned.

like image 190
Basil Musa Avatar answered Mar 25 '23 06:03

Basil Musa