Professional Connection Pool Sizing
Join the DZone community and get the full member experience.Join For Free
i previously wrote about the benefits of connection pooling and why monitoring it is of crucial importance . this post will demonstrate how flexy pool can assist you in finding the right size for your connection pools.
know your connection pool
the first step is to know your connection pool settings. my current application uses xa transactions, therefore we use bitronix transaction manager , which comes with its own connection pooling solution.
accord to the bitronix connection pool documentation we need to use the following settings:
- minpoolsize: the initial connection pool size
- maxpoolsize: the maximum size the connection pool can grow to
- maxidletime: the maximum time a connection can remain idle before being destroyed
- acquisitiontimeout: the maximum time a connection request can wait before throwing a timeout. the default value of 30s is way too much for our qos
configuring flexy pool
an enterprise system must use an central monitoring tool, such as ganglia or graphite and instructing flexy pool to use a different reporting mechanism is fairly easy. our example will export reports to csv files and this is how you can customize the default metrics settings .
we only have to give a large enough maxoverflow and retryattempts and leave flexy pool find the equilibrium pool size.
|minpoolsize||0||the pool starts with an initial size of 0|
|maxpoolsize||1||the pool starts with a maximum size of 1|
|acquisitiontimeout||1||a connection request will wait for 1s before giving up with a timeout exception|
|maxoverflow||9||the pool can grow up to 10 connections ( initial maxpoolsize + maxoverflow )|
|retryattempts||30||if the final maxpoolsize of 10 is reached and there is no connection available, a request will retry 30 times before giving up.|
our application is a batch processor and we are going to let it process a large amount of data so we can gather the following metrics:
after analysing the metrics, we can draw the following conclusions:
- the max pool size should be 8
- for this max pool size there is no retry attempt.
- the connection acquiring time has stabilized after the pool has grown to its max size.
- there is a peak connection lease time of 50s causing the pool size to grow from 7 to 8. lowering the time the connections are being held allows us to decrease the pool size as well.
if the database maximum connection count is 100 we can have at most 12 concurrent applications running.
pushing the comfort zone
let’s assume that instead of 12 we would need to run 19 such services. this means the pool size must be at most 5 . lowering the pool size will increase the connection request contention and the probability of connection acquire retry attempts.
we will change the maxoverflow to 4 this time while keeping the other settings unchanged:
|maxoverflow||4||the pool can grow up to 10 connections ( initial maxpoolsize + maxoverflow )|
these are the new metrics:
analysing the metrics, we can conclude that:
- for the max pool size of 5 there are at most 3 retry attempts.
- the overall connection acquiring time confirms the retry attempts.
- the peak connection lease time was replicated, even if it’s around 35s this time.
flexy pool eases connection pool sizing while offering a failover mechanisms for those unforeseen situations when the initial assumptions don’t hold up any more.
alerts may be triggered whenever the number of retries exceeds a certain threshold, allowing us to step in as soon as possible.
Published at DZone with permission of Vlad Mihalcea. See the original article here.
Opinions expressed by DZone contributors are their own.