What is the best way to setup your pool with respect to:-
- When do you create connections?
- When do you close connections, and would you close all of them?
- Do you test connections are still good. When and how?
- How do you figure out a good number for the maximum number of connections?
- What sort of monitoring do you have in place to ensure users of the pool are well behaved? Can you stop one bad piece of code from taking out everything?
- Have you written your own pool, or used a third-party library?
I believe this is an agnostic question, but comments about ‘features’ of particular databases/languages are welcome. For example, it might be slower or more expensive to connect on some databases than others.
To clarify, I do not intend to write a pool from scratch, this question is more about how to configure an existing library that does pooling.
I wrote a connection pool for the database in Java when it was just a design pattern and not a common library. Now I use the one built into Tomcat.
I used a thread to monitor several aspects of the pool and several parameters to control its behavior…
This served me very well for a couple of years. The highest I ever saw the pool was 151 connections during a wild peek. Usually the pool was at about a dozen during heavy usage and idled down to the minimum three in the early morning hours.
I used Oracle’s JDBC thin drivers and connected to an Oracle database.