You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Albert Vila <av...@imente.com> on 2005/12/13 18:10:03 UTC
Persistent DB Connection problem
Hi all,
I'm having problems setting up the apache + mod_perl + Apache::DBI in
order to get persistent db connections.
I've added the following line in my httpd.conf:
PerlRequire /home/xxx/startup.pl
The startup.pl file contains:
#!/usr/local/bin/perl -w
$ENV{MOD_PERL} or die "GATEWAY_INTERFACE not Perl!";
use Apache::Registry;
use Apache::DBI;
use strict;
# choose debug output: 0 = off, 1 = quiet, 2 = chatty
$Apache::DBI::DEBUG = 2;
I've check using the Apache::Status if the
PERL_CHILD_INIT=1 PERL_STACKED_HANDLERS=1 are enabled.
PerlChildInitHandler* Enabled
* PerlStackedHandlers* Enabled*
However, the persistent connections still does not work. The system
creates a new db connection for earch child.
That's my error.log file (it contains 2 requests):
[Tue Dec 13 11:05:42 2005] [notice] Apache/1.3.33 (Debian GNU/Linux)
mod_perl/1.29 configured -- resuming normal operations
[Tue Dec 13 11:05:42 2005] [notice] Accept mutex: sysvsem (Default: sysvsem)
9178 Apache::DBI push PerlCleanupHandler
9178 Apache::DBI need ping: yes
9178 Apache::DBI new connect to
'imenteFiltres;host=bdd1.colt.imente.comimentefah6Foyo$AutoCommit=1PrintError=1RaiseError=0Username=imentedbi_connect_method=Apache::DBI::connect'
9178 Apache::DBI PerlCleanupHandler
9180 Apache::DBI push PerlCleanupHandler
9180 Apache::DBI need ping: yes
9180 Apache::DBI new connect to
'imenteFiltres;host=bdd1.colt.imente.comimentefah6Foyo$AutoCommit=1PrintError=1RaiseError=0Username=imentedbi_connect_method=Apache::DBI::connect'
9180 Apache::DBI PerlCleanupHandler
Any comments?
Thanks,
Albert
Re: Persistent DB Connection problem
Posted by "Kevin A. McGrail" <km...@pccc.com>.
> I'm shocked that nobody mentioned Apache::DBI->connect_on_init()
That's because he really doesn't want persistent connections. He's trying
to get 1 db connection for XYZ number of child processes.
;-)
Regards,
KAM
Re: Persistent DB Connection problem
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
On Tue, 13 Dec 2005, Kevin A. McGrail wrote:
>> I'm having problems setting up the apache + mod_perl + Apache::DBI in order
>> to get persistent db connections.
>>
>> I've added the following line in my httpd.conf:
>> PerlRequire /home/xxx/startup.pl
>
> The persistent connection is one per child process so I don't know if your
> test is correct. Try instead to write a quick perl script that connects to
> the database, disconnects and connects/disconnects again.
>
> That should definitely result in a persistent connection being used again.
>
> Make sense?
I'm shocked that nobody mentioned Apache::DBI->connect_on_init()
See the Apache-DBI documentation.
Re: Persistent DB Connection problem
Posted by Jonathan Vanasco <mo...@2xlp.com>.
This is a ThreeParter
On Dec 14, 2005, at 10:43 AM, Thomas Schindl wrote:
> I brought about a few days ago a discussion about mod_dbd
> (available with
> Apache-2.2 ) which exactly acts like I think connection-pooling
> should work
> in Apache.
on a side note, does mp2 work with apache-2.2 yet? i've been well
out-of-step with everything apache over the past few months (lots of
php/lighttpd/fcgi stuff :( ) i'm still running 2.0x , assuming
there's no need to upgrade in the near future.
On Dec 14, 2005, at 10:43 AM, Thomas Schindl wrote:
> I've now taken a closer look into the whole thing and at the moment
> it seems to possible to use mod_dbd to provide the physical
> connection on
> C-level to DBD::mysql. I've already contacted the maintainer of
> DBD::mysql
> and I hope until next year i get something going.
Good luck!
On Dec 14, 2005, at 10:50 AM, Perrin Harkins wrote:
> Good. In the meantime, SQL Relay is available:
> http://sqlrelay.sourceforge.net/
Thanks! I've never seen that before!
//Jonathan
Re: Persistent DB Connection problem
Posted by Frank Wiles <fr...@wiles.org>.
On Sun, 18 Dec 2005 15:10:43 -0500
Malcolm J Harwood <mj...@dalereuth.liminalflux.net> wrote:
> On Wednesday 14 December 2005 10:50 am, Perrin Harkins wrote:
>
> > On Wed, 2005-12-14 at 16:43 +0100, Thomas Schindl wrote:
> > > I've now taken a closer look into the whole thing and at the
> > > moment it seems to possible to use mod_dbd to provide the
> > > physical connection on C-level to DBD::mysql. I've already
> > > contacted the maintainer of DBD::mysql and I hope until next year
> > > i get something going.
>
> > Good. In the meantime, SQL Relay is available:
> > http://sqlrelay.sourceforge.net/
>
> Has anyone used this? The docs seem to imply you could only have one
> mod_perl instance connected at a time, which would be a severely
> limiting factor under any sort of load.
I've used it before on a project. It worked pretty well for what
I needed it to do which was share persitant Oracle connections
in a forking Perl daemon where Apache::DBI was obviously not an
option.
I also had many server children connected at any given point.
Are you getting tripped up in the difference between the
sqlr-listener and connection? There will be only one sqlr-listener
per Apache child, but this is a light weight connection. The listener
then contacts the sqlr-connection daemon to acquire a database handle
and do the "heavy" lifting whenever your code needs access to a
handle.
---------------------------------
Frank Wiles <fr...@wiles.org>
http://www.wiles.org
---------------------------------
Re: Persistent DB Connection problem
Posted by Malcolm J Harwood <mj...@liminalflux.net>.
On Wednesday 14 December 2005 10:50 am, Perrin Harkins wrote:
> On Wed, 2005-12-14 at 16:43 +0100, Thomas Schindl wrote:
> > I've now taken a closer look into the whole thing and at the moment
> > it seems to possible to use mod_dbd to provide the physical connection on
> > C-level to DBD::mysql. I've already contacted the maintainer of
> > DBD::mysql and I hope until next year i get something going.
> Good. In the meantime, SQL Relay is available:
> http://sqlrelay.sourceforge.net/
Has anyone used this? The docs seem to imply you could only have one mod_perl
instance connected at a time, which would be a severely limiting factor under
any sort of load.
--
"And these .. these phrases you keep speaking in. They don't make any sense."
"Ah, you seek meaning?"
"Yes."
"Then listen to the music, not the song."
-- Kosh and Talia Winters in Babylon 5:"Deathwalker"
Re: Persistent DB Connection problem
Posted by Perrin Harkins <pe...@elem.com>.
On Wed, 2005-12-14 at 16:43 +0100, Thomas Schindl wrote:
> I've now taken a closer look into the whole thing and at the moment
> it seems to possible to use mod_dbd to provide the physical connection on
> C-level to DBD::mysql. I've already contacted the maintainer of DBD::mysql
> and I hope until next year i get something going.
Good. In the meantime, SQL Relay is available:
http://sqlrelay.sourceforge.net/
- Perrin
Re: Persistent DB Connection problem
Posted by Thomas Schindl <to...@gmx.at>.
Hi,
you are right Jonathan at the moment there's no real DB-Pool implementation
available like one knows it e.g. from Java.
a. Connection-Pool(Connection1, Connection2)
b. Apache-Child-1 "Request-Starts":
-> Connection1 = Pool->fetchConnection();
-> Connection1->executeQuery("SELECT * FROM bla")
-> Pool->returnConnection(Connection1);
c. Apache-Child-2 "Request-Starts":
-> Connection1 = Pool->fetchConnection();
-> Connection1->executeQuery("SELECT * FROM bla");
-> ... Start working
d. Apache-Child-1 "Request ends":
-> Connection2 = Pool->fetchConnection();
-> Connection2->executeQuery("SELECT * FROM bla");
-> Pool->returnConnection(Connection2);
e. Apache-Child-2 "Request ends":
-> Pool->returnConnection(Connection2);
I brought about a few days ago a discussion about mod_dbd (available with
Apache-2.2 ) which exactly acts like I think connection-pooling should work
in Apache.
I've now taken a closer look into the whole thing and at the moment
it seems to possible to use mod_dbd to provide the physical connection on
C-level to DBD::mysql. I've already contacted the maintainer of DBD::mysql
and I hope until next year i get something going.
Tom
> --- Ursprüngliche Nachricht ---
> Von: Jonathan Vanasco <mo...@2xlp.com>
> An: Albert Vila <av...@imente.com>
> Kopie: modperl@perl.apache.org
> Betreff: Re: Persistent DB Connection problem
> Datum: Tue, 13 Dec 2005 13:26:18 -0500
>
>
> On Dec 13, 2005, at 12:59 PM, Albert Vila wrote:
>
> > I thought the persistent connection was only one for all childs.
> >
> > What happens then if I have 1000 childs each one with 1 db
> > connection? This means 1000 database connections. How do you setup
> > apache + mod_perl in this environment?
> >
> > Albert
>
> you want to set it up exactly like that - with 1000 db connections.
>
> if you have 1 db connection that everyone shares, then your
> connection ties up and each child has to wait for all the others to
> finish. not good.
>
> if you have 1000 children, i'd be amazed at your setup. maybe i'm
> just too green at this, but i've never had enough resources to go
> above 300 , even using a stripped down setup and preloading just
> about everything into shared space.
>
> anways:
> mysql and postgres, by default, support ~250 concurrent connections
> out of the config file just fine. you can tweak stuff in the
> settings to get more. there's a maxclient setting (or something like
> that).
>
> if you wanted to do something with 1000 children and 100 db handles,
> you could probably do some sort of pooling scheme with a singleton or
> something where a child 'checks out' a db connection for a request,
> then checks it back in after its done. i thought about that once.
> it gave me a headache. i brought it up here and with friends and
> everyone said "why?" - because you should be fine just adding more
> sql clients.
>
> if you're looking at 1000 children though, you would almost
> definitely want to look into a clustered db setup - probably
> something with reads from 2+ machines that are replicated from a
> master that handles writes.
>
> thats my .02¢
>
>
>
--
GMX DSL-Flatrate 1 Jahr kostenlos* + WLAN-Router ab 0,- Euro*
Bis 31.12.2005 einsteigen! Infos unter: http://www.gmx.net/de/go/dsl
Re: Persistent DB Connection problem
Posted by Jonathan Vanasco <mo...@2xlp.com>.
On Dec 13, 2005, at 12:59 PM, Albert Vila wrote:
> I thought the persistent connection was only one for all childs.
>
> What happens then if I have 1000 childs each one with 1 db
> connection? This means 1000 database connections. How do you setup
> apache + mod_perl in this environment?
>
> Albert
you want to set it up exactly like that - with 1000 db connections.
if you have 1 db connection that everyone shares, then your
connection ties up and each child has to wait for all the others to
finish. not good.
if you have 1000 children, i'd be amazed at your setup. maybe i'm
just too green at this, but i've never had enough resources to go
above 300 , even using a stripped down setup and preloading just
about everything into shared space.
anways:
mysql and postgres, by default, support ~250 concurrent connections
out of the config file just fine. you can tweak stuff in the
settings to get more. there's a maxclient setting (or something like
that).
if you wanted to do something with 1000 children and 100 db handles,
you could probably do some sort of pooling scheme with a singleton or
something where a child 'checks out' a db connection for a request,
then checks it back in after its done. i thought about that once.
it gave me a headache. i brought it up here and with friends and
everyone said "why?" - because you should be fine just adding more
sql clients.
if you're looking at 1000 children though, you would almost
definitely want to look into a clustered db setup - probably
something with reads from 2+ machines that are replicated from a
master that handles writes.
thats my .02¢
Re: Persistent DB Connection problem
Posted by Larry Leszczynski <la...@emailplus.org>.
Hi Albert -
On Tue, 13 Dec 2005, Albert Vila wrote:
> I thought the persistent connection was only one for all childs.
>
> What happens then if I have 1000 childs each one with 1 db connection? This
> means 1000 database connections. How do you setup apache + mod_perl in this
> environment?
Typical mod_perl setups include a light-weight front end Apache which
serves all static content and which reverse-proxies requests for dynamic
content to a heavier-weight back end Apache running mod_perl, see:
http://perl.apache.org/docs/1.0/guide/strategy.html#Adding_a_Proxy_Server_in_http_Accelerator_Mode
In this setup you typically have *far* fewer mod_perl children running at
a given time than if you used only a single mod_perl front end.
Of course under heavy load it is still possible to run up to your database
connection limit, even with the two-Apache setup, in which case you'd need
to look into the other options that people have suggested.
Larry
Re: Persistent DB Connection problem
Posted by Albert Vila <av...@imente.com>.
I thought the persistent connection was only one for all childs.
What happens then if I have 1000 childs each one with 1 db connection?
This means 1000 database connections. How do you setup apache + mod_perl
in this environment?
Albert
Kevin A. McGrail wrote:
>> I'm having problems setting up the apache + mod_perl + Apache::DBI in
>> order to get persistent db connections.
>>
>> I've added the following line in my httpd.conf:
>> PerlRequire /home/xxx/startup.pl
>
> The persistent connection is one per child process so I don't know if
> your test is correct. Try instead to write a quick perl script that
> connects to the database, disconnects and connects/disconnects again.
>
> That should definitely result in a persistent connection being used
> again.
>
> Make sense?
>
> Regards,
> KAM
>
Re: Persistent DB Connection problem
Posted by "Kevin A. McGrail" <km...@pccc.com>.
> I'm having problems setting up the apache + mod_perl + Apache::DBI in
> order to get persistent db connections.
>
> I've added the following line in my httpd.conf:
> PerlRequire /home/xxx/startup.pl
The persistent connection is one per child process so I don't know if your
test is correct. Try instead to write a quick perl script that connects to
the database, disconnects and connects/disconnects again.
That should definitely result in a persistent connection being used again.
Make sense?
Regards,
KAM
Re: Persistent DB Connection problem
Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2005-12-13 at 18:10 +0100, Albert Vila wrote:
> However, the persistent connections still does not work. The system
> creates a new db connection for earch child.
That's what it's supposed to do, as documented in the Apache::DBI man
page. If it creates more than one connection with the same parameters
in each child, then something is wrong.
- Perrin