HikariConfig and maxPoolSize
Asked Answered
T

3

7

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?

Taster answered 15/8, 2016 at 19:57 Comment(0)
H
9

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

Hanschen answered 2/12, 2016 at 12:34 Comment(1)
About MinimumIdle: "[..] However, for maximum performance and responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as maximumPoolSize" github.com/brettwooldridge/HikariCP#configuration-knobs-babyChaisson
L
3

I arrived here at this question because I, too, wanted to understand what a -1 default for maxPoolSize and minIdle means. Both of these properties default to -1 inside of the internals of HikariConfig. The Hikari code reconciles these values into the defaults that are advertised publicly in the documentation.

public HikariConfig()
{
    dataSourceProperties = new Properties();
    healthCheckProperties = new Properties();

    minIdle = -1;
    maxPoolSize = -1;
    maxLifetime = MAX_LIFETIME;
    ...

These values are then set as such:

    if (maxPoolSize < 1) {
      maxPoolSize = DEFAULT_POOL_SIZE;
    }

    if (minIdle < 0 || minIdle > maxPoolSize) {
      minIdle = maxPoolSize;
    }

Not intended to be a direct answer to OP's question, just adding clarity for anyone else who may land here looking for what -1 means.

Laryngeal answered 25/2, 2022 at 17:25 Comment(0)
B
1

FYI - struggled with getting the HikariConfig to take notice of values supplied like

HikariConfig hc = new HikariConfig();    
hc.addDataSourceProperty("maxPoolSize","5");

Which appears in some (older I think) code samples. So make sure you use

HikariConfig hc = new HikariConfig();
hc.setMaximumPoolSize(5);
...
Barra answered 30/4, 2023 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.