Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HikariConfig and maxPoolSize

I use HikariConfig as DataSource of postgres database on spring server. Should I set up maxPoolSize? (default value is -1) How much pool size can i use? Are there any dependencies with hardware?

like image 367
Vadim Shvedov Avatar asked Aug 15 '16 19:08

Vadim Shvedov


People also ask

What is HikariConfig?

HikariConfig is the configuration class used to initialize a data source. It comes with four well-known, must-use parameters: username, password, jdbcUrl, and dataSourceClassName. Out of jdbcUrl and dataSourceClassName, we generally use one at a time.

What is maxPoolSize in Hikari?

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.

What is Hikari Max lifetime?

spring.datasource.hikari.max-lifetime=1800000. Controls the maximum lifetime of a connection in the pool. An in-use connection will never be retired, only when it is closed it will be removed.

What is Hikari minimum idle?

minimumIdle. Controls the minimum number of connection pool idle connections. When the connection pool idle connections are less than minimumIdle and the total number of connections is not more than maximumPoolSize, HikariCP will try its best to supplement new connections.


1 Answers

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

like image 68
AntJavaDev Avatar answered Sep 20 '22 13:09

AntJavaDev