You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tim Gardner <tg...@codeHorse.com> on 2000/06/16 19:31:11 UTC

Apache::DBI strategy/philosophy

I have been using DBI without Apache::DBI and have been simply 
storing db connections in a global variable as a sort of poor man's 
persistent connection when running under Apache::Registry.

Now I want to do things "right" and am trying to understand 
Apache::DBI.  Before looking at the module  I imagined that it would 
work by providing a library of persistent connections.  You would 
check a connnection out of the library, use it, and then put it back 
when you are done, like checking a book out of the library.  If you 
disconnected the connection, you just wouldn't return it, and the 
pool would have to create a new connection for the next user.

But this is not the way Apache::DBI works.  Instead, if I understand 
correctly after glancing at the module this morning, two consecutive 
identical connect calls will return the same connection!  Why isn't 
this a problem?  Is the assumption that two different transactions 
will use different user/pwd combinations?

Thanks,
Tim

Re: Apache::DBI strategy/philosophy

Posted by Edmund Mergl <E....@bawue.de>.
Tim Gardner wrote:
> 
> I have been using DBI without Apache::DBI and have been simply
> storing db connections in a global variable as a sort of poor man's
> persistent connection when running under Apache::Registry.
> 
> Now I want to do things "right" and am trying to understand
> Apache::DBI.  Before looking at the module  I imagined that it would
> work by providing a library of persistent connections.  You would
> check a connnection out of the library, use it, and then put it back
> when you are done, like checking a book out of the library.  If you
> disconnected the connection, you just wouldn't return it, and the
> pool would have to create a new connection for the next user.
> 
> But this is not the way Apache::DBI works.  Instead, if I understand
> correctly after glancing at the module this morning, two consecutive
> identical connect calls will return the same connection!  Why isn't
> this a problem?  Is the assumption that two different transactions
> will use different user/pwd combinations?
> 
> Thanks,
> Tim


Apache (version 1.x) uses a multi-process approach for serving as 
many requests as possible in parallel. Every httpd process has its
own address space. A database connection opened by one specific
httpd can not be shared with another httpd. At most you will get
a segmentation violation. Hence every httpd needs to keep its own
pool of persistent database connections.

As a direct consequence it is not possible to use more than one
HTTP request inside one transaction, because you can not control
which httpd will server a specific request. Very likely two requests
will be served by two different httpds where both do not know 
anything about a common transaction.


Edmund



-- 
Edmund Mergl
mailto:E.Mergl@bawue.de
http://www.edmund-mergl.de
fon: +49 700 EDEMERGL