How to restrict initial pool size in hikaricp?

前端 未结 3 1350
离开以前
离开以前 2021-01-20 01:38

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

Now switch

相关标签:
3条回答
  • 2021-01-20 02:07

    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

    0 讨论(0)
  • 2021-01-20 02:08

    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.

    0 讨论(0)
  • 2021-01-20 02:15

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

    spring.jpa.hibernate.hikari.minimumIdle=5
    spring.datasource.hikari.maximum-pool-size=10
    
    0 讨论(0)
提交回复
热议问题