Home Projects Jobs Clientele Contact


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Db pool [was: My little comments to CPP code]

sergey@total-knowledge.com wrote:
>> Almost there. Now look at the samples for the proper syntax....
> My guess is that the proper syntax is:
> <servlet name="InitServlet" dso="./debug/libui/libuu.so">
> <parameter name="num_connections" value="100"/>
> </servlet>
>> I think you missed the fact that connections do not have to be closed
>> nor are necessarily open when pool returns them. You are, however,
>> right in that the login() stored procedure should be called every time
>> connection is retrieved, and logout/cleanup should be called every time
>> connection is returned to the pool. I think it is best to tie these to
>> pool
>> itself, in order to avoid forgetting to call these by accident.
>> Another thing you are forgetting about is when init() and destroy() are
>> called.
> Ok, here is how I understand DB pool related functionlity at this point(so
> far without some details of how pool will work internally):
> DB pool initialized in InitServlet::init() and pointer to it stored in
> ServletContext.
InitServlet? What is that? (other then that, idea seems to be fine)
> The database handle will be retrieved in UUServlet and passed to data
> model classes as an argument to constructor.
Not necessarily constructor, but in most cases probably true.
> Connection has to be opened and added to the pool if
> "No connections available in m_connections list" AND ( "maxCon parameter
> is null" OR "maxCon limit has not been reached" )
We will always have a cap. BTW, what happens, if there are no
connections available and we reached the cap?
> Connection has to be closed and removed from the pool
> 1. At shutdown. We have to loop through all connections in m_connections
> list and close them, then clear m_connections list.
What happens to connections that were requested by servlets and weren't
returned to the pool when shutdown occurs?
> I don't know how else connections can be closed, maybe when it was
> inactive for some time and Postgres will close it by itself?
Depends on our policy. We may want to close connections that
serviced some number of requests, if Alexey insists on it. Or
connections may live forever, once opened... Etc. This is really
what the connection management policies question was about.
> However I don't see the point in returning closed connections to the
> client. If, for some reason, there are closed connection in m_connections
> list, they have to be removed from the list until first open connection is
> found and returned to client.
That is correct. The question then is, how do you know connection
was closed, while it is in the m_connections list.
> login() stored procedure will be called in uuDBPool::getConnection()
> whenever there is an open connection to return and
> logout() stored procedure will be called in
> uuDBPool::releaseConnection(Connection& con) whenever connection is
> returned to the pool.
> Since we process authentication in the pool, uuDBPool::getConnection()
> will get 4 parameters(login, password, server, sessionid) to call login().
> The question now when uuDBPool::getConnection() and
> uuDBPool::releaseConnection() will be called.
> It has to be done in servlet' service() imho.
Ultimately yes.
>  But since we have UUServlet my guess that we can do it there.
You could provide some helper functions for those purposes.
I am not clear on what kind of help they'd provide though.
UUServlet::getDbConnection(HttpSession&) perhaps? Dunno...
> So uuDBPool::getConnection() will be called in UUServlet constractor and
> uuDBPool::releaseConnection() will be called in UUServlet destructor.
Err?? Here you go again, and I thought everything is clear....

Ilya A. Volynets-Evenbakh
Total Knowledge. CTO

Authoright © Total Knowledge: 2001-2008