What is a database connection pool?

Connection pooling is a common technique. Why do you need it? We need to start with TCP. If our server and database are not deployed in the same machine, so, the server every time to query the database to establish a connection, generally TCP link, establish a connection requires three handshakes, assuming that the background service and database one-way access time needs 10ms, so just to establish a connection took 30ms, In addition, TCP has a slow start mechanism. In fact, a query may take more than one TCP return and return, which greatly reduces the query efficiency.

Why connection pooling is needed:

In order to solve this problem, we need to maintain long links so that we do not have to establish a connection every time, after all, establishing a connection takes time and requires some other system resources. Another benefit of connection pooling is that it makes it easier to manage, on the one hand, to avoid database resources being occupied by certain apis, and on the other hand, to avoid resource leaks.

What is a HikariCP

HikariCP is an open source database connection pool component created by An American programmer living in Japan. The code is very lightweight and very fast. According to official data, in i7, 32 threads open 32 connections, random database read and write operations, HikariCP is hundreds of times faster than C3P0 database connection pool. HikariCP is also officially recommended in SpringBoot2.0.

Why is HikariCP so fast

1. Bytecode is more streamlined, so you can load more code into the cache.

2. Implemented a lock free collection type to reduce resource contention caused by concurrency.

3. Use custom array types, which greatly improves performance over ArrayList.

4. Optimize the CPU time slice algorithm, and try to complete all operations in one time slice.

Compared with Druid

On Github, some users posted a comparison between Alibaba Druid and Hikari, suggesting that Hikari beats Alibaba’s Druid connection pool in terms of performance. Alibaba’s engineers also responded by saying that Druid’s performance was slightly lower because of the locking mechanism, and Druid’s focus on providing more functionality.

How to choose:

Hikari is the default connection pool for SpringBoot2.0. The Hikari version of SpringBoot2.0 is the default connection pool for SpringBoot2.0. The Hikari version of SpringBoot2.0 is the default connection pool for SpringBoot2.0. It is also widely used around the world, and for most businesses it is no matter which one you use because the performance bottleneck is usually not in the connection pool. You are free to choose according to your own preferences.