database connection pool(basic)

As you know, the database connection is a very scarce resource in the web application. It takes a long time for a request to connect and close database, and it also spends some resources. If there are hundreds of thousands of requests sent to the database concurrently, the performance of database will be bad, or even it crushed except you add some hardware resources to accelerate it. But most of us are more willing to improve the throughput in the software level. So, it’s a good idea that build a “Database Connection Pool” to reuses the database connection resource, which calls “resource pool” in the software design model.

Figure 1 without dcp

Actually, the DCP is like a connection cache. Each request will get a connection which is already connecting to the database from DCP. This method can improve the throughput.

Figure 2 with dcp

However, we also need to do some work to set some limitations(table 1) on DCP to avoid to waste the hardware resources.

Table 1, parameters for configuring DCP

PARAMETERS DESCRIPTION
Initial size The initial number of connections that are created when the pool is started
Max active The maximum number of active connections that can be allocated from the pool at the same time
Max idle The maximum number of connections that remain idle in the pool, without extra ones being destroyed
Max wait The maximum time in milliseconds that the pool will wait when there are no available connections for a connection to be returned
Max pool Maximum number of connections that should be held in the pool
Max size Maximum number of connections that can be created for use
Min idle The maximum number of active connections that can remain idle in the pool
Min pool Minimum number of connections that should be held in the pool

Reference:
[1] A Method of Design and Optimization of Database Connection Pool, Fei Liu
[2] Improving Performance of Web Application approaches using Connection Pooling, Kirti Gupta, Manish Mathuria


database connection pool(basic)
https://r-future.github.io/post/database-connection-pool/
Author
Future
Posted on
July 26, 2019
Licensed under