Small Hub read:

How to select a database connection pool


  • Author: jianzh5
  • Hacpai.com/article/158…

What is database connection pooling

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 do YOU need connection pooling

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 compact, so you can load more code into the cache.

  2. Implements a lockless collection type to reduce resource contention caused by concurrency.

  3. The use of custom array types greatly improves performance over ArrayList.

  4. For the CPU time slice algorithm optimization, as far as possible in a time slice to complete all operations.

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, and it is widely used around the world. The Hikari connection pool is the default connection pool for SpringBoot2.0. For most businesses, it doesn’t 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.

Recommended reading

Great, this Java site, everything! https://markerhub.com

The UP master of this B station, speaks Java really good!

Too great! The latest edition of Java programming ideas can be viewed online!