Lokesh
Lokesh

Reputation: 3112

Unable to set HikariCP max-pool-size

I'm using Spring Boot 2.0.3 release. I want to increase the maximum pool size of HikariCP which is 10 by default.

I tried changing it in applicaiton.properties with

spring.datasource.hikari.maximum-pool-size=200

but it is not working because in the logs it still show that max pool size is 10.

The reason I want to change is because I am somehow reaching that limit in staging and I have no idea what's causing it.

Upvotes: 6

Views: 24140

Answers (2)

Yury K.
Yury K.

Reputation: 671

I faced similar issue recently (Spring Boot v2.1.3). Posting it here in case people bump into the same scenario.

Long story short: if you're initializing DataSource using @ConfigurationProperties, those properties don't seem to require hikari prefix for maximum-pool-size, unless I'm missing something. So spring.datasource.maximum-pool-size should work if you use @ConfigurationProperties(prefix = "spring.datasource").

Details: In my case I'm initializing DataSource myself using org.springframework.boot.jdbc.DataSourceBuilder, so that I could later use it in org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean:

@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource primaryDataSource()
{
    return DataSourceBuilder.create().build();
}

In this case property spring.datasource.hikari.maximum-pool-size taken from Common App Properties section in Spring Boot doc did not help. Neither did suggested above maximumPoolSize.

So I went and debugged Spring Boot code which lead me to org.springframework.boot.context.properties.bind.JavaBeanBinder and it's method bind. Value for property name for HikariDataSource setter setMaximumPoolSize was "maximum-pool-size", so just for sake of testing I renamed my property to be spring.datasource.maximum-pool-size and it finally worked.

Hope it helps. Please let me know in the comments if I missed something or took wrong path. Thanks!

Upvotes: 28

Karol Dowbecki
Karol Dowbecki

Reputation: 44932

As per HikariCP Github README it's maximumPoolSize so try using:

spring.datasource.hikari.maximumPoolSize = 200

But this will work only if you allow Spring Boot to create the DataSource. If you create the DataSource yourself Spring Boot properties have no effect.

Do note that 200 is a very high value that may negatively impact your database as each physical connection requires server resources. In most cases a lower value will yield better performance, see HikariCP wiki: About Pool Sizing.

Upvotes: 9

Related Questions