63

What is the default connection pool size that Spring Boot HikariCP provides when the container loads?

Of course, I am using below properties to setup max CP size, but I was wondering what is the default CP size if we don't give any number in the application.properties file.

spring.datasource.hikari.minimumIdle=5
spring.datasource.hikari.maximumPoolSize=20
spring.datasource.hikari.idleTimeout=30000
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.connectionTimeout=30000

And if I give a max pool size in application.properties as 100 and I use only 20, will that affect my application performance?

Yuri
  • 4,254
  • 1
  • 29
  • 46
Hari
  • 631
  • 1
  • 5
  • 3
  • 2
    See https://www.baeldung.com/spring-boot-hikari for some details – Wim Deblauwe Mar 06 '19 at 15:30
  • It would be also great to know why actuator doesn't show the defaults under actuator/env. Asked here https://stackoverflow.com/questions/63358741/spring-boot-actuator-doesnt-show-hikari-parameters – ka3ak Aug 11 '20 at 13:10

3 Answers3

75

maximumPoolSize

Default: 10

HicariCP Documentation contains default properties: https://github.com/brettwooldridge/HikariCP

Read about Pool Size here: Maximum Connection Pool Size

Dmitry Krivolap
  • 1,354
  • 9
  • 16
  • 8
    Thank you, and what is the maximum number of connection pools that HikariCP handles? is it based on JVM memory ? – Hari Mar 07 '19 at 15:18
1

Concerning the maximum pool size , for example, PostgreSQL recommends the following formula:

pool_size = ((core_count * 2) + effective_spindle_count)
  • core_count is amount of CPU cores
  • effective_spindle_count is the amount of disks in a RAID

But according to those docs:

but we believe it will be largely applicable across databases.

That means this formula generally can be applicable to other databases.

Also, for example, about Oracle you can read this article and watch video

kerbermeister
  • 2,985
  • 3
  • 11
  • 30
0

The formula which has held up pretty well across a lot of benchmarks for years is that for optimal throughput the number of active connections should be somewhere near

connections = ((core_count * 2) + effective_spindle_count).

Core count should not include HT threads, even if hyperthreading is enabled. Effective spindle count is zero if the active data set is fully cached, and approaches the actual number of spindles as the cache hit rate falls. ... There hasn't been any analysis so far regarding how well the formula works with SSDs.

The calculation of pool size in order to avoid deadlock is a fairly simple resource allocation formula:

pool size = Tn x (Cm - 1) + 1

Where,

  • Tn is the maximum number of threads
  • Cm is the maximum number of simultaneous connections held by a single thread.

For example, imagine three threads (Tn=3), each of which requires four connections to perform some task (Cm=4). The pool size required to ensure that deadlock is never possible is:

pool size = 3 x (4 - 1) + 1 = 10

Another example, you have a maximum of eight threads (Tn=8), each of which requires three connections to perform some task (Cm=3). The pool size required to ensure that deadlock is never possible is:

pool size = 8 x (3 - 1) + 1 = 17

This is not necessarily the optimal pool size, but the minimum required to avoid deadlock.

In some environments, using a JTA (Java Transaction Manager) can dramatically reduce the number of connections required by returning the same Connection from getConnection() to a thread that is already holding a Connection in the current transaction.

We never cease to amaze at the in-house web applications we've encountered, with a few dozen front-end users performing periodic activity, and a connection pool of 100 connections. Don't over-provision your database.

Pranav MS
  • 2,235
  • 2
  • 23
  • 50