From: scott.marlowe <scott.marlowe@ihs.com>
To: David Busby <busby@pnts.com>
Cc: pgsql-php@postgresql.org
Subject: Re: Number of connections
Date: Mon, 19 May 2003 09:37:03 -0600 (MDT)
Message-ID: <Pine.LNX.4.33.0305190928420.18757-100000@css120.ihs.com> (raw)
In-Reply-To: <03bf01c31ca5$ac0e5d70$1100000a@busbydev>
On Sat, 17 May 2003, David Busby wrote:
> List,
> I cannot tell from the documentation if pg_pconnect() or pg_connect()
> are really different in how the connection pool is managed. Does anyone
> know if that is the case? Seems that using pg_pconnect would dictate "use a
> pooled connection" and pg_connect is "use a pooled connection, or make a new
> one". On "live" apps which is better to use, seems pg_pconnect. Thoughts?
This is a far more complex subject than it may at first appear.
The first and most important point is that PHP doesn't "pool" connections
when using persistant connections. what happens is that each apache child
preocess holds a connection open after a pconnect has been used.
this means that using the default apache configuration option of 150 max
children, and the postgresql default of 32, that after a little bit of
load is applied, your whole web site comes crashing with errors about no
more backend connections available.
I.e. using pconnect without understand the implications, and configuring
your web site accordingly, is dangerous. pconnects in PHP are like tiny
ints in mysql, I consider them to almost be a misfeature, in that they are
so often used by folks who don't know what they're getting themselves
into.
pconnects don't save much time. My testing showed them to be 1,000 times
faster than regular connects. Unfortunately, since regular connects run
in about 1 mS, having persistant connects run at 1 uS doesn't really help.
I.e. the average PHP page takes 10 to 100 mS to run, so chopping off <1 mS
from the connect speed is pretty much noise for most folks.
Another issue is that if you use pconnect to two different databases in
the same cluster in a PHP script, you now have TWO persistant connections
open at the same. Open to three databases, three persistant connections.
IF you want to use pconnects, then you need to do some system planning and
configuration.
If you are running multiple front end apache servers, they need to be
configured so that you have fewer connects open than the max that
postgresql can handle at any given time. So, set max children lower in
apache (20 to 50 or so) and multiply the max number of different connects
in each script, times the number of apache servers, add a 10 or 20 for
overhead, and set the postgresql max connects to that.
Otherwise, your site will have issues with connecting. And that would
make it WAY slower than just using plain old connect.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: scott.marlowe@ihs.com, busby@pnts.com
Subject: Re: Number of connections
In-Reply-To: <Pine.LNX.4.33.0305190928420.18757-100000@css120.ihs.com>
References: <03bf01c31ca5$ac0e5d70$1100000a@busbydev> <Pine.LNX.4.33.0305190928420.18757-100000@css120.ihs.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox