Thread: pg_pconnect - Really persistent ?

pg_pconnect - Really persistent ?

From
Hervé Piedvache
Date:
Hi,

I have some troubles with the pg_pconnect function ...

All my PHP scripts are using pg_pconnect but apache seems to not using
the persistent connection ... ?
I mean that when I make a small script usign a pg_pconnect, and a simple
select ... I open 2 browsers and call many time my scrip, I look for the
backends of postgresql and I see many backends opened !

If I try for example to limit the backend to 35, and run an ab (apache
bench) to call the page ... after the 35 connections opened postgresql
say there is no more connection possible ... ok ! but why the
persistents connexions are not re-used ?

Does someone could explain me how I have to do ... ?

In same time I have also try with php.ini to refuse the pgsql
persistents connections but they seem to run !? what this option is for
?
I also try to limit the number of connections also in php.ini to 5 for
example ... and I open 35 postgres backends with any trouble !! :(

Thanks for your answers ...

regards,
--
Hervé

Re: pg_pconnect - Really persistent ?

From
Alexey Borzov
Date:
Greetings, Hervé!

Well, there are some problems, indeed.
1) PHP counts connections on a per-process basis. So, when you have,
say, 10 httpd processes, and a limit of 10 connections is set in
php.ini, you can have total of 100 postgres backends, with a default
limit of 32.
2) PHP does not reuse persistent connections when it can open a new
one. So set a limit of pconnections to 1 or 2 in php.ini, and
everything will work as intended.

At 06.12.2000, 14:43, you wrote:
HP> I have some troubles with the pg_pconnect function ...

HP> All my PHP scripts are using pg_pconnect but apache seems to not using
HP> the persistent connection ... ?
HP> I mean that when I make a small script usign a pg_pconnect, and a simple
HP> select ... I open 2 browsers and call many time my scrip, I look for the
HP> backends of postgresql and I see many backends opened !

HP> If I try for example to limit the backend to 35, and run an ab (apache
HP> bench) to call the page ... after the 35 connections opened postgresql
HP> say there is no more connection possible ... ok ! but why the
HP> persistents connexions are not re-used ?


--
Yours, Alexey V. Borzov, Webmaster of RDW



Re: pg_pconnect - Really persistent ?

From
Hervé Piedvache
Date:
Hi Alexey,

Alexey Borzov a écrit :
>
> Well, there are some problems, indeed.
> 1) PHP counts connections on a per-process basis. So, when you have,
> say, 10 httpd processes, and a limit of 10 connections is set in
> php.ini, you can have total of 100 postgres backends, with a default
> limit of 32.
> 2) PHP does not reuse persistent connections when it can open a new
> one. So set a limit of pconnections to 1 or 2 in php.ini, and
> everything will work as intended.

OK .. I would like more precision of your configuration please, or to
configure my system ...

I do what you said ... but still have trouble with postgresql ... I have
a message like too many files opened in same time ... on the postgresql
server my max limit is 8192 files ... !! So to save my trouble for the
moment the only way I found is to cron a apache graceful each minute !
:(((
Each time the graceful is done it kill all the backends of postgresql
not needed ... then I'm saved !

But I think it's not the good solution so what do I have to limit ?
Apache ? Postgresql ? my limit of pconnection and connection (pconnect
and normal) is now set to 2 in my php.ini file.

For the moment on apache :
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 10
#
StartServers 20
MinSpareServers 64
MaxSpareServers 128
MaxClients 256
MaxRequestsPerChild 0
ThreadsPerChild 256
LimitRequestBody 50240
LimitRequestFields 50
#

I run postgresql with those options :
-B 1024 -S -i -N 256 -o '-F -E -S 1000 -d 1 -s -o
/usr/local/pgsql/data/postgres.log'

I have 2 servers, one for Apache, the other for postgresql the two
servers are identical configuration with 2xPIII 800 SMP, 1Gb of RAM.
My web server have many connections ... and each connection need to
access to the postgresql !

Hope you could give me some help to solve this stupid trouble !! ;)

Regards,

> At 06.12.2000, 14:43, you wrote:
> HP> I have some troubles with the pg_pconnect function ...
>
> HP> All my PHP scripts are using pg_pconnect but apache seems to not using
> HP> the persistent connection ... ?
> HP> I mean that when I make a small script usign a pg_pconnect, and a simple
> HP> select ... I open 2 browsers and call many time my scrip, I look for the
> HP> backends of postgresql and I see many backends opened !
>
> HP> If I try for example to limit the backend to 35, and run an ab (apache
> HP> bench) to call the page ... after the 35 connections opened postgresql
> HP> say there is no more connection possible ... ok ! but why the
> HP> persistents connexions are not re-used ?
>
> --
> Yours, Alexey V. Borzov, Webmaster of RDW

--
Hervé

Re[2]: pg_pconnect - Really persistent ?

From
Alexey Borzov
Date:
Greetings, Hervé!

At 11.12.2000, 10:56, you wrote:
>> Well, there are some problems, indeed.
>> 1) PHP counts connections on a per-process basis. So, when you have,
>> say, 10 httpd processes, and a limit of 10 connections is set in
>> php.ini, you can have total of 100 postgres backends, with a default
>> limit of 32.
>> 2) PHP does not reuse persistent connections when it can open a new
>> one. So set a limit of pconnections to 1 or 2 in php.ini, and
>> everything will work as intended.

HP> OK .. I would like more precision of your configuration please, or to
HP> configure my system ...

HP> I do what you said ... but still have trouble with postgresql ... I have
HP> a message like too many files opened in same time ... on the postgresql
HP> server my max limit is 8192 files ... !! So to save my trouble for the
HP> moment the only way I found is to cron a apache graceful each minute !
HP> :(((
    Increase the limit on open files: now each postgres can have
8192/256=32 open files max, and it needs to have much more...

HP> #
HP> StartServers 20
HP> MinSpareServers 64
HP> MaxSpareServers 128
HP> #
    Isn't MaxSpareServers a bit high? At each given time you can have
128 idle Apaches and each of these 2 idle Postgreses connected (256
total), which is actually your limit. Ouch!


--
Yours, Alexey V. Borzov, Webmaster of RDW



Re: pg_pconnect - Really persistent ?

From
Hervé Piedvache
Date:
Hi Alexey,

At first thanks for your answer ;)

Alexey Borzov a écrit :
>
> HP> I do what you said ... but still have trouble with postgresql ... I have
> HP> a message like too many files opened in same time ... on the postgresql
> HP> server my max limit is 8192 files ... !! So to save my trouble for the
> HP> moment the only way I found is to cron a apache graceful each minute !
> HP> :(((
>     Increase the limit on open files: now each postgres can have
> 8192/256=32 open files max, and it needs to have much more...

OK is 32768 is ok ? 32768/256=128 max files by backend ...
I don't know (and would like to know if possible) what is the
implication of this file-max for my server ?
What is the maximimum size of the file max for a linux ? In fact that
depends of what ? ;)

> HP> #
> HP> StartServers 20
> HP> MinSpareServers 64
> HP> MaxSpareServers 128
> HP> #
>     Isn't MaxSpareServers a bit high? At each given time you can have
> 128 idle Apaches and each of these 2 idle Postgreses connected (256
> total), which is actually your limit. Ouch!

I understand what you mean ... but you can see my Apache log file of
today ...

[Wed Dec 13 12:16:14 2000] [info] server seems busy, (you may need to
increase StartServers, or Min/MaxSpareServers), spawning 8 children,
there are 0 idle, and 39 total children
[Wed Dec 13 12:16:15 2000] [info] server seems busy, (you may need to
increase StartServers, or Min/MaxSpareServers), spawning 16 children,
there are 0 idle, and 47 total children
[Wed Dec 13 12:16:16 2000] [info] server seems busy, (you may need to
increase StartServers, or Min/MaxSpareServers), spawning 32 children,
there are 12 idle, and 63 total children
[Wed Dec 13 12:16:17 2000] [info] server seems busy, (you may need to
increase StartServers, or Min/MaxSpareServers), spawning 32 children,
there are 45 idle, and 95 total children

What can I do ... and why I'm in this case ?

Many thanks per advance for your help !

regards,
--
Hervé