Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does HikariCP recommend fixed size pool for better performance

According to HikariCP's documentation they mentioned to create fixed size pool for better performance.

minimumIdle:

This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool.If the idle connections dip below this value, HikariCP will make a best effort to add additional connections quickly and efficiently. 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

My application usually requires 100 connections and only at a few circumstances reaches 200 connections.

If I create a 200 connection fixed size pool, most of the time 100 connections will be idle.

So which of the following is the best:

  1. Create connection pool with fixed size. i.e. 200

OR

  1. Create connection pool by setting minimumIdle to 100 and maximumPoolSize to 200.

Why the second point is not recommended by HikariCP? I think the second one would be the best for my case.

like image 995
shivadarshan Avatar asked Mar 11 '15 13:03

shivadarshan


People also ask

What is Hikari max pool size?

spring.datasource.hikari.maximum-pool-size=50. Specifies number of database connections between database and application. This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. spring.datasource.hikari.connection-timeout=60000.

Why is HikariCP faster?

Since fewer bytes are generated than the JDK Proxy, negating a lot of unnecessary byte-code, thus making it faster in execution ) Optimizations of Proxy and Interceptor: Hikari library has reduce a lot of code, e.g HikariCP's Statement proxy has only 100 lines of code.

How does HikariCP connection pool work?

Summary. "HikariCP is solid high-performance JDBC connection pool. A connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools may significantly reduce the overall resource usage." - You can find out more here.

What is the maximum number of connection pools that HikariCP handles?

Create connection pool by setting minimumIdle to 100 and maximumPoolSize to 200.


1 Answers

I suggest you read this page and watch the attached video. The Oracle Performance Group demonstrates how an application with a pool of 96 connection easily handles 10,000 front-end users and 20,000 transactions per-second.

PostgreSQL recommends a formula of:

connections = ((core_count * 2) + effective_spindle_count)

Where core_count is CPU cores, and effective_spindle_count is the number of disks in a RAID. For many servers, this formula would result in a connection pool of 10-20 maximum connections.

The odds are that with even 100 connections, your database is heavily over saturated. Do you have 50 CPU cores? If you're drives are spinning platters not SSDs the head can only be in one place at a time, and unless the entire dataset is in memory there is no way to service so many requests at once (100-200).

UPDATE: Directly answering your question about fixed-pool sizing. You will likely get the best performance from your application with a pool that as a maximum connection count turned right at the "knee" or "peak" performance that your DB can handle. This is likely a small number. If you have "spike demand", as many applications do, trying to spin up new connections to grow the pool at the instant of the spike is counter-productive (creates more load on the server). A small, constant pool will give you predictable performance.

like image 59
brettw Avatar answered Oct 15 '22 05:10

brettw