[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Re: Db pool [was: My little comments to CPP code]
- What is our pool responsible for.
It responsible for managing DB connections.
When a servlet needs a database connection, it requests an available one
from the pool. If none is available, a new one is created and added to the
pool.
1. Get an open connection from the pool.
We need a connection to provide user access to DB.
2. Return a connection to the pool.
We need to count connections in the pool
3. Release all resources and close all connections at shutdown.
We need to loop through all connections and close them on shutdown to
clear the pool.
4. Setting up connection time-outs and communication failures.
We need to set up timeouts for queueing and recognize and clean up
"failure" connections.
5. Limit the number of connections in the pool to a predefined value.
Set the max limit to make sure the pool is not overloaded.
- What pooling strategies we want to support (and why)
1. Close connections that have not been used for a specified time.
2. Queueing connections. If there is max connections for the pool
specified, then objects requesting a connection can be put on hold until
another object frees its connection.
- How will pooling and HTTP request object lifetimes will interoperate
Pool initialized at init() time(not sure about this one), then the same
connection can be used for subsequent requests. Since servlets can keep
information between requests, a pool lives longer then HTTP request.
- What will API look like
1. The uuDBPool() constructor that takes these parameters:
string login,
string password,
int server(this one is needed for login() proc),
string sessionid(needed for login() proc, not really used now),
int maxCon(max connections for this pool).
It represents the pool, I renamed it to uuDBPool()
2. Connection getConnection( long timeout ) { return con; } to get a
connection from the pool or to create a new connection. 'timeout' is a
value for how long the client is waiting for a connection.
3. void releaseConnection(Connection con) used for returning a connection
to the pool.
4. void shutdown() closes all connections in the pool.
- Provide few use cases relevant for our application
1. Browser sends request to the servlet.
2. No connections available in the pool.
3. Is maxCon been reached?
a. Case "NO"
1) Create new connection using getConnection()' login() procedure.
2) Increament connections counter in the pool.
3) Return connection to the client.
b. Case "YES"
1) Wait 'timeout' milliseconds.
2) Return to 3.
Another case:
1. Browser sends request to the servlet.
2. Connections available in the pool.
3. Return a connection using getConnection()
One more:
1. User leaves the site.
2. Connection returned to the pool using releaseConnection() function
3. Number of used connections is decremented.
I'm not sure when shutdown() should be called.