HikariCP - Database Connection Pool
Introduction
The creation of new connections in the database requires some processing, especially when there is an authentication.
Therefore, to achieve higher performance is advisable to reuse the connections and not constantly open a new connection.
To solve this issue a connection pool is used, which makes it so that when a connection is dropped it will not actually be closed and be destroyed, so the connection will be put on hold to be reused when a new connection is needed.
This will offer great performance and also allows more parameter settings, including the best which is to limit the maximum number of connections to avoid overloading the database.
HikariCP
Hikari means Light in Japanese, is the most efficient and Java Database Connectivity (JDBC) is a Java API for accessing relational databases and is a very fast lightweight Java connection pool.
The official HikariCP repository can be found here on GitHub, check out the performance graphs and configuration information.
Netuno uses HikariCP to manage connections to PostgreSQL, MariaDB, Microsoft SQL Server and Oracle.
Configuration Settings
The configuration of HikariCP on Netuno is done next to the configuration of the database in the applications.
That is, within the application in the config folder in the environment configuration, such as:
- _development.json
- _production.json
In the "db" section, it contains the database settings.
Also for the default connection as for any other connection can be configure the HikariCP parameters in the same way.
So inside the default, where you have the host, port, name (database), username and password, just add more HikariCP parameters as:
...
"db": {
"default": {
"engine": "pg",
"host": "localhost",
"port": 5432,
"name": "my_database",
"username": "my_user",
"password": "secret",
"maximumPoolSize": 25,
"minimumIdle": 1,
"idleTimeout": 10000,
"maxLifetime": 60000
}
}
...
For example, each of these extra HikariCP settings above are for:
- The
maximumPoolSizesets the maximum size of connections in HikariCP, in this example the connection limit will be 25. - The
minimumIdlesets the minimum number of pending connections in the queue to be used. - The
idleTimeoutis the time the connection can be queued. - The
maxLifetimeis the maximum lifetime connection.
The HikariCP settings must be consistent with the database engine configuration. For example, the maximum number of connections and the time limits must never exceed what is defined in the database engine.
Any other HikariCP parameter can be configured in the same way, just add the desired configuration parameters.
Parameters
See below the list of parameters that can be configured with HikariCP using Netuno. This configuration are either set as default by Netuno or are not applicable.