membersound
membersound

Reputation: 86637

How to restrict initial pool size in hikaricp?

I used to have a tomcat connection pool configuration restricting the initial pool size: spring.datasource.tomcat.initial-size=2

Now switching to hikaricp: what is the equivalent to restrict the initially started connections?

Sidenote: spring.datasource.hikari.minimumIdle does not prevent initializing 10 connections at startup.

Upvotes: 6

Views: 27290

Answers (3)

NiVeR
NiVeR

Reputation: 9786

You can use these properties provided in spring boot:

spring.datasource.hikari.minimumIdle=5
spring.datasource.hikari.maximumPoolSize=8

and then:

spring.datasource.hikari.idleTimeout=120000

to limit the life of idle connections, but hikari doesn't give you such property for initial number of connections.

Upvotes: 10

membersound
membersound

Reputation: 86637

I just found out it had to do with my configuration of multiple datasources.

In general, the property spring.datasource.hikari.minimum-idle=2 automatically restricts the startup pool size correctly!

But if having multiple data sources, there was a configuration property missing, as follows:

    @Bean
    @ConfigurationProperties("spring.datasource.secondary.hikari")
    public DataSource secondatyDataSource() {
        return ...
    }

Before I just had "spring.datasource.secondary", and there by my property "spring.datasource.secondary.hikari.*" was not taken into account.

This is probably wrong documented in https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html

Upvotes: 2

priteshbaviskar
priteshbaviskar

Reputation: 2327

With spring boot, set these properties in your application.properties.

spring.jpa.hibernate.hikari.minimumIdle=5
spring.datasource.hikari.maximum-pool-size=10

Upvotes: 6

Related Questions