HikariConfig and maxPoolSize HikariConfig and maxPoolSize postgresql postgresql

HikariConfig and maxPoolSize


The maxPoolSize is an indicator as a limit for your application. You should calculate that based on the traffic/ app's overhead / hardware. F.E you could set the limit to 10000 connections , which doesnt mean that it will operate as expected. Actually this will get affected by your hardware , because if your machine contains one core , the 100000 active connections will just stretch both the java application and the postgres as the OS will struggle to handle all those I/O calls. Even worse , if the database and the java app are in different machines in the same network , you also have the network overhead.

What actually optimizes the performance is the minimumIdle property along with the idleTimeout , so if you have calculated a proper value for those , then it should never reach the maxConnection value as well as cause overhead due to lock waiting or resource starvation. The only bad here , is that if your application is wrong designed(f.e. holding the connection longer than needed, not properly committing the transactions, not using batch jobs for long operations) , then it will affect the User's Experience, but this is another question.

i)

Should I set up maxPoolSize? (default value is -1)


You should set it as a global limit so that both your app and database will be maintainable and healthy. The default value is not -1 but 10. More details here

ii)

How much pool size can i use?


That depends on your application and your infrastructure. The only way you could get those numbers is by integrated tests for the most stretching Use Cases.Some info here regarding the postgres tuning

iii)

Are there any dependencies with hardware?


Yes there are , for both the JVM and the Postgres server and also not only from hardware perspective , but also what OS you might choose