[FASTCGI] sub-processes

Michael Grant mgrant at grant.org
Wed Apr 22 05:05:42 EDT 2009


I'm using mod-fastcgi in apache2.

In httpd.conf, I have this:

MinSpareServers     1
MaxSpareServers     20
StartServers        1

and in a php.fcgi script like this:

#!/bin/sh
PHP_FCGI_CHILDREN=10
export PHP_FCGI_CHILDREN
exec /usr/local/bin/php-cgi

What I see is 20 httpd instances, each with a process, and that
process has up to 10 children, pstree outputs something like this:

-+= 00000 root [swapper]
 \-+= 00001 root /sbin/init --
   \-+= 05763 root /usr/local/sbin/httpd -k start
     |--- 05764 www /usr/local/sbin/httpd -k start
     |-+- 05765 www /usr/local/sbin/httpd -k start
     | |-+= 05767 user /usr/local/bin/php-cgi
     | | |--- 05768 user /usr/local/bin/php-cgi
     | | |--- 05769 user /usr/local/bin/php-cgi
     | | |--- 05770 user /usr/local/bin/php-cgi
     | | |--- 05771 user /usr/local/bin/php-cgi
     | | |--- 05772 user /usr/local/bin/php-cgi
     | | |--- 05773 user /usr/local/bin/php-cgi
     | | |--- 05774 user /usr/local/bin/php-cgi
     | | |--- 05775 user /usr/local/bin/php-cgi
     | | |--- 05776 user /usr/local/bin/php-cgi
     | | \--- 05777 user /usr/local/bin/php-cgi
     | |-+= 05941 user /usr/local/bin/php-cgi
     | | |--- 05942 user /usr/local/bin/php-cgi
     | | |--- 05943 user /usr/local/bin/php-cgi
     | | |--- 05944 user /usr/local/bin/php-cgi
     | | |--- 05945 user /usr/local/bin/php-cgi
     | | |--- 05946 user /usr/local/bin/php-cgi
     | | |--- 05947 user /usr/local/bin/php-cgi
     | | |--- 05948 user /usr/local/bin/php-cgi
     | | |--- 05949 user /usr/local/bin/php-cgi
     | | |--- 05950 user /usr/local/bin/php-cgi
     | | \--- 05951 user /usr/local/bin/php-cgi
     | |-+= 05956 user /usr/local/bin/php-cgi
     | | |--- 05957 user /usr/local/bin/php-cgi
     | | |--- 05958 user /usr/local/bin/php-cgi
     | | |--- 05959 user /usr/local/bin/php-cgi
     | | |--- 05960 user /usr/local/bin/php-cgi
     | | |--- 05961 user /usr/local/bin/php-cgi
     | | |--- 05962 user /usr/local/bin/php-cgi
     | | |--- 05963 user /usr/local/bin/php-cgi
     | | |--- 05964 user /usr/local/bin/php-cgi
     | | |--- 05965 user /usr/local/bin/php-cgi
     | | \--- 05966 user /usr/local/bin/php-cgi
     | |-+= 05972 user /usr/local/bin/php-cgi
     | | |--- 05973 user /usr/local/bin/php-cgi
     | | |--- 05974 user /usr/local/bin/php-cgi
     | | |--- 05975 user /usr/local/bin/php-cgi
     | | |--- 05976 user /usr/local/bin/php-cgi
     | | |--- 05977 user /usr/local/bin/php-cgi
     | | |--- 05978 user /usr/local/bin/php-cgi
     | | |--- 05979 user /usr/local/bin/php-cgi
     | | |--- 05980 user /usr/local/bin/php-cgi
     | | |--- 05981 user /usr/local/bin/php-cgi
     | | \--- 05982 user /usr/local/bin/php-cgi
     | |-+= 05984 user /usr/local/bin/php-cgi
     | | |--- 05985 user /usr/local/bin/php-cgi
     | | |--- 05986 user /usr/local/bin/php-cgi
     | | |--- 05987 user /usr/local/bin/php-cgi
     | | |--- 05988 user /usr/local/bin/php-cgi
     | | |--- 05989 user /usr/local/bin/php-cgi
     | | |--- 05990 user /usr/local/bin/php-cgi
     | | |--- 05991 user /usr/local/bin/php-cgi
     | | |--- 05992 user /usr/local/bin/php-cgi
     | | |--- 05993 user /usr/local/bin/php-cgi
     | | \--- 05994 user /usr/local/bin/php-cgi
     | |-+= 05996 user /usr/local/bin/php-cgi
     | | |--- 05997 user /usr/local/bin/php-cgi
     | | |--- 05998 user /usr/local/bin/php-cgi
     | | |--- 05999 user /usr/local/bin/php-cgi
     | | |--- 06000 user /usr/local/bin/php-cgi
     | | |--- 06001 user /usr/local/bin/php-cgi
     | | |--- 06002 user /usr/local/bin/php-cgi
     | | |--- 06003 user /usr/local/bin/php-cgi
     | | |--- 06004 user /usr/local/bin/php-cgi
     | | |--- 06005 user /usr/local/bin/php-cgi
     | | \--- 06006 user /usr/local/bin/php-cgi
     | |-+= 06009 user /usr/local/bin/php-cgi
     | | |--- 06010 user /usr/local/bin/php-cgi
     | | |--- 06011 user /usr/local/bin/php-cgi
     | | |--- 06012 user /usr/local/bin/php-cgi
     | | |--- 06013 user /usr/local/bin/php-cgi
     | | |--- 06014 user /usr/local/bin/php-cgi
     | | |--- 06015 user /usr/local/bin/php-cgi
     | | |--- 06016 user /usr/local/bin/php-cgi
     | | |--- 06017 user /usr/local/bin/php-cgi
     | | |--- 06018 user /usr/local/bin/php-cgi
     | | \--- 06019 user /usr/local/bin/php-cgi
     | |-+= 06025 user /usr/local/bin/php-cgi
     | | |--- 06026 user /usr/local/bin/php-cgi
     | | |--- 06027 user /usr/local/bin/php-cgi
     | | |--- 06028 user /usr/local/bin/php-cgi
     | | |--- 06029 user /usr/local/bin/php-cgi
     | | |--- 06030 user /usr/local/bin/php-cgi
     | | |--- 06031 user /usr/local/bin/php-cgi
     | | |--- 06032 user /usr/local/bin/php-cgi
     | | |--- 06033 user /usr/local/bin/php-cgi
     | | |--- 06034 user /usr/local/bin/php-cgi
     | | \--- 06035 user /usr/local/bin/php-cgi
     | |-+= 06208 user /usr/local/bin/php-cgi
     | | |--- 06210 user /usr/local/bin/php-cgi
     | | |--- 06211 user /usr/local/bin/php-cgi
     | | |--- 06212 user /usr/local/bin/php-cgi
     | | |--- 06213 user /usr/local/bin/php-cgi
     | | |--- 06214 user /usr/local/bin/php-cgi
     | | |--- 06215 user /usr/local/bin/php-cgi
     | | |--- 06216 user /usr/local/bin/php-cgi
     | | |--- 06217 user /usr/local/bin/php-cgi
     | | |--- 06218 user /usr/local/bin/php-cgi
     | | \--- 06219 user /usr/local/bin/php-cgi
     | \-+= 07960 user /usr/local/bin/php-cgi
     |   |--- 07961 user /usr/local/bin/php-cgi
     |   |--- 07962 user /usr/local/bin/php-cgi
     |   |--- 07963 user /usr/local/bin/php-cgi
     |   |--- 07964 user /usr/local/bin/php-cgi
     |   |--- 07965 user /usr/local/bin/php-cgi
     |   |--- 07966 user /usr/local/bin/php-cgi
     |   |--- 07967 user /usr/local/bin/php-cgi
     |   |--- 07968 user /usr/local/bin/php-cgi
     |   |--- 07969 user /usr/local/bin/php-cgi
     |   \--- 07970 user /usr/local/bin/php-cgi
     |--- 05766 www /usr/local/sbin/httpd -k start
     |--- 05778 www /usr/local/sbin/httpd -k start
     |--- 05779 www /usr/local/sbin/httpd -k start
     |--- 05780 www /usr/local/sbin/httpd -k start
     |--- 05883 www /usr/local/sbin/httpd -k start
     |--- 05952 www /usr/local/sbin/httpd -k start
     |--- 05953 www /usr/local/sbin/httpd -k start
     |--- 05954 www /usr/local/sbin/httpd -k start
     |--- 05967 www /usr/local/sbin/httpd -k start
     |--- 05968 www /usr/local/sbin/httpd -k start
     |--- 05969 www /usr/local/sbin/httpd -k start
     |--- 05970 www /usr/local/sbin/httpd -k start
     |--- 06037 www /usr/local/sbin/httpd -k start
     |--- 06531 www /usr/local/sbin/httpd -k start
     |--- 06532 www /usr/local/sbin/httpd -k start
     |--- 06533 www /usr/local/sbin/httpd -k start
     |--- 06548 www /usr/local/sbin/httpd -k start
     |--- 06555 www /usr/local/sbin/httpd -k start
     |--- 06557 www /usr/local/sbin/httpd -k start
     \--- 06558 www /usr/local/sbin/httpd -k start

This seems excessive and it's unclear to me whether all these apache
processes are being used or needed.

I have experimented, if I set PHP_FCGI_CHILDREN=0, I only get 20
sub-processes for user 'user' and no sub-sub-processes for user,
however, performance isn't great.

Some more experimenting by writing some test scripts indicates that if
I have PHP_FCGI_CHILDREN=0 that requests are not handled
simultaneously.  The requests seem to be spread around to the multiple
waiting dynamic servers but serially.  I can post my scripts I used to
test this if needed.  In essence, if I do 2 POST operations
simultaneously, it takes twice as long as when I have
PHP_FCGI_CHILDREN>0.

PHP_FCGI_CHILDREN certainly needs to be greater than 0, but is there
some way I can keep it from multiplying like this?

Michael Grant


More information about the FastCGI-developers mailing list