fcgid keep alive or something else.. ?

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:

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:

#!/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:

 <ifmodule mpm_worker_module="">StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
    ThreadStackSize 2097152</ifmodule> 

Regards

A.

2 Replies

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 "PHPFCGICHILDREN=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.

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 phpfcgichildren. But the apache side needs to know to launch only that one master, but to push many requests at it at the same time. modfastcgi can do that. modfcgid couldn't the last time I checked (year ago?).

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct