Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Mon Apr 04, 2011 4:57 pm 
Offline
Senior Newbie

Joined: Wed Jun 16, 2010 4:55 pm
Posts: 10
Hello

Gathering experiences from some other members of Linode forums , I decided to setup mpm-worker with fcgid and suexec. Everything works as I expect it to do and I already see some better performance. Thing that annoys me is that cgi processes keep on running even if atm server is in idle and without any http connections

Here is just snip of ps aux:

Code:
www-data 11943  0.0  0.7   5472  1944 ?        S    16:29   0:00 /usr/sbin/apache2 -k start
www-data 11944  0.0  0.7   6616  1924 ?        S    16:29   0:00 /usr/sbin/apache2 -k start
www-data 11945  0.0  1.6  63180  4164 ?        Sl   16:29   0:00 /usr/sbin/apache2 -k start
www-data 11946  0.0  1.6  63172  4168 ?        Sl   16:29   0:00 /usr/sbin/apache2 -k start
amar     12124  0.0  1.9  17816  4996 ?        Ss   21:11   0:00 /usr/lib/cgi-bin/php
amar     12125  0.0  1.9  17816  5000 ?        Ss   21:11   0:00 /usr/lib/cgi-bin/php
amar     12126  0.0  1.4  18072  3724 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12127  0.0  1.4  18072  3724 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12128  0.0  1.4  18072  3724 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12129  0.0  1.4  18072  3724 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12130  0.0  1.4  18072  3720 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12131  0.0  1.4  18072  3720 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12132  0.0  1.4  18072  3720 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12133  0.0  1.4  18072  3720 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12134  0.0  1.9  17816  4996 ?        Ss   21:11   0:00 /usr/lib/cgi-bin/php
amar     12135  0.0  1.4  18072  3720 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12136  0.0  1.4  18072  3720 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12137  0.0  1.4  18072  3720 ?        S    21:11   0:00 /usr/lib/cgi-bin/php
amar     12138  0.0  1.4  18072  3720 ?        S    21:11   0:00 /usr/lib/cgi-bin/php


See? Why 25 of them? Why they are up for hours even there is no http connections to server? Where could I tweak this ?

Here is my wrapper:

Code:
#!/bin/sh
#
# sample PHP FastCGI wrapper
PHPRC="/etc/php5/cgi/"    # directory which contains php.ini
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHPRC PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
exec  /usr/lib/cgi-bin/php


Here is my mpm-worker:

Code:
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
    ThreadStackSize 2097152
</IfModule>


Regards

A.


Top
   
 Post subject:
PostPosted: Tue Apr 05, 2011 5:33 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
The whole point of FastCGI is to keep PHP processes alive, so that you don't have to spin up a new process every time a request comes in. That's why FastCGI is faster than CGI, as the name implies.

Now, the problem is that you have more than a dozen PHP processes when you really only wanted 5. (That's what "PHP_FCGI_CHILDREN=4" does. One parent process with 4 children. And 5 is really all you need for a mostly idle site.)

This is because fcgid spawns one whole family of PHP processes per Apache child process. You have ThreadsPerChild 25 and MaxClients 150, so you get a maximum of 150 / 25 = 6 Apache children, and accordingly a maximum of 6 * 5 = 30 PHP processes. That's too much.

I think there's a way to avoid this behavior by using a different configuration than what you have there, but sorry I forgot what it was. It's been a while since I played with fcgid.


Last edited by hybinet on Tue Apr 05, 2011 5:35 pm, edited 1 time in total.

Top
   
 Post subject:
PostPosted: Tue Apr 05, 2011 5:34 pm 
Offline
Senior Member
User avatar

Joined: Tue Nov 24, 2009 1:59 pm
Posts: 362
I'm just guessing here, but as far as I remember fcgid assumes "dumb handlers". That is, it considers what you gave it as a handler to be a parser capable of processing one script at a time, and that it (fcgid) is responsible for spawning/killing them as necessary. May well be it's set by default to spawn 8 handlers.
For php, you launch the php "master", which runs php_fcgi_children. But the apache side needs to know to launch only that one master, but to push many requests at it at the same time. mod_fastcgi can do that. mod_fcgid couldn't the last time I checked (year ago?).

_________________
rsk, providing useless advice on the Internet since 2005.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group