Connection Pool vs. Thread Pool Settings
December 28, 2008 Leave a comment
Connection Pool and Thread Pool are used to improve performance of applications. Most of us use these poolings with default settings not caring about their configurations or finding optimal values. But the configuration also an important factor in performance tuning. In some sense the connection pool and the thread pool settings are dependent. We will discuss about the dependency in this post.
The dependency between these two pool setting is in maximum attribute. Let us assume that your database can support maximum of 50 connections then it is straight forward to configure the connection pool maximum attribute as 50. But how this setting going to impact thread pool setting? Configure application server thread pool as maximum of 100. In this scenario application server will allow 100 request to be processed simultaneously however database have only 50 connections. So only 50 thread will get connection another 50 thread will fight to get database connection hence connections will be switched between threads frequently that will slow down overall application performance.
Let us assume we set thread pool maximum setting same as connection pool maximum setting of 50. Application server will allow 50 thread to be processed simultaneously the remaining thread will be in wait state. All the 50 thread will get database connection immediately hence it will be processed quickly.
The above example assumed each thread will use one database connection (may be multiple connections but sequentially); if your application uses two database connections parallelly by each thread then configure thread pool maximum setting as half of the connection pool maximum.
Finally, setting the thread pool size too large can cause performance problems because if there are too many concurrent threads, task switching overhead becomes a serious bottleneck.
Some tips to configure pools.
- Determine the optimal value of maximum thread and maximum connection from performance test.
- Set the value of initial capacity equivalent to maximum capacity.