ispCP - Board - Support
How to control the MAX thread of PHP-CGI's NO.? - Printable Version

+- ispCP - Board - Support (http://www.isp-control.net/forum)
+-- Forum: ispCP Omega Support Area (/forum-30.html)
+--- Forum: System Setup & Installation (/forum-32.html)
+--- Thread: How to control the MAX thread of PHP-CGI's NO.? (/thread-9360.html)



How to control the MAX thread of PHP-CGI's NO.? - jetvster - 01-25-2010 12:53 PM

apache2.config
Quote:<IfModule mpm_worker_module>
StartServers 1
MaxClients 150
MinSpareThreads 20
MaxSpareThreads 70
ThreadsPerChild 25
MaxRequestsPerChild 500
ServerLimit 2
#ThreadLimit 50
</IfModule>
php5-fcgi-starter
Quote:#!/bin/sh

umask 022

PHPRC="/var/www/fcgi/XXXXX.com/php5/"

export PHPRC
PHP_FCGI_CHILDREN=2
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=500
export PHP_FCGI_MAX_REQUESTS

exec /usr/bin/php5-cgi

Quote:host:/etc/apache2/mods-enabled# ps aux |grep php |wc -l
184 mean out of control?waste about 1.5G memory,make my server too slow because of no more memory to use


Quote:host:/etc/apache2/mods-enabled# ps aux |grep apache2
root 12311 0.0 0.2 142600 8304 ? Ss 00:18 0:05 /usr/sbin/apache2 -k start
www-data 18398 0.0 0.1 142260 5980 ? S 10:25 0:00 /usr/sbin/apache2 -k start
www-data 18399 0.0 0.1 142600 6212 ? S 10:25 0:00 /usr/sbin/apache2 -k start
www-data 19978 0.5 0.3 438636 14528 ? Sl 10:49 0:01 /usr/sbin/apache2 -k start
www-data 20006 0.5 0.3 438840 14388 ? Sl 10:49 0:01 /usr/sbin/apache2 -k start
www-data 20153 0.5 0.3 437348 12648 ? Sl 10:52 0:00 /usr/sbin/apache2 -k start
www-data 20181 0.4 0.2 436504 11704 ? Sl 10:52 0:00 /usr/sbin/apache2 -k start
root 20215 0.0 0.0 5164 796 pts/2 S+ 10:53 0:00 grep apache2
host:/etc/apache2/mods-enabled# ps aux |grep apache2 |wc -l
8

i want to control the max thread of PHP-CGI and apache,i change the param ThreadsPerChild and ServerLimit of apache2.config,but it's seem nouse,any idea?


RE: How to control the MAX thread of PHP-CGI's NO.? - kilburn - 01-25-2010 05:27 PM

We're missing some info:

- OS/Distro/Version?
- fcgid/fastcgi/mod_php?
- prefork/worker/event?

For worker + fcgid, you have to take into account that there are 2 types of processes used: apache *and* php. Both are going to consume memory, and you have to configure both of them.

Basically, the number of apache processes is configured by the "MaxClients" and "ThreadsPerChild" directives (see worker docs, summary section). In your case, you've setup these directives 150 and 25 respectively. Thus, apache spawns up to 150/25 = 6 apache worker processes (+ the master, which runs as root). Play with these numbers to get more or less apache workers as you wish.

Now, regarding php (fcgid), things are a bit more cumbersome. First, you should comment out the following lines in *all* the /var/www/fcgi/<domain.tld>/php5-fcgi-starter files (you'll have to write a script to do it if you have many domains):
Quote:#PHP_FCGI_CHILDREN=2
#export PHP_FCGI_CHILDREN
#PHP_FCGI_MAX_REQUESTS=500
#export PHP_FCGI_MAX_REQUESTS

Next, comment out the same lines in "/etc/ispcp/fcgi/parts/*", so that new domains are configured exactly the same as the ones that you've manually configured.

Finally, you can tune up fcgid's parameters by modifying the /etc/apache2/mods-enabled/fcgid_ispcp.conf. The most relevant directives (regarding performance/memory consumption) are:
Code:
- IdleTimeout: Specifies how many time a process may stay idle before being killed by the process manager. Thus, decreasing it will kill workers faster and you should observe a lower resource usage. Setting it to low is bad though, because it will cause too much re-spawning.
- MaxProcessCount: Specifies the maximum total number of php process that will be spawned, considering *all* the available virtual hosts.
- DefaultMaxClassProcessCount: Specifies the maximum number of php processes spawned *for each virtualhost*.
- DefaultMinClassProcessCount: Specifies the minimum number of php processes spawned *for each virtualhost*. Set it to "0" if you have many domains that are almost never accessed.

Hope this helped.


RE: How to control the MAX thread of PHP-CGI's NO.? - Nuxwin - 10-19-2010 06:17 PM

@marc,

You wrong here!

To really disable PHP process manager, you should export PHP_FCGI_CHILDREN like this

Code:
PHP_FCGI_CHILDREN = 0
export PHP_FCGI_CHILDREN

Otherwise, will not work.


RE: How to control the MAX thread of PHP-CGI's NO.? - kilburn - 10-19-2010 06:26 PM

Nuxi, I'm using this config on multiple servers, so I can assure you that it does work. Basically, 0 is the default value for PHP_FCGI_CHILDREN if it's not set, at least in debian stable.


RE: How to control the MAX thread of PHP-CGI's NO.? - Nuxwin - 10-19-2010 06:29 PM

No, you wrong
Edit:

Sorry, after check, it seem that was changed (default 8 to default 0)... Since PHP 5.2.0 (I think)

For now, under Lenny (php 5.2.6) it's defaulted to 0.

http://svn.php.net/viewvc/php/php-src/tags/php_5_2_6/sapi/cgi/README.FastCGI?view=markup


http://www.mail-archive.com/php-cvs@lists.php.net/msg24066.html


RE: How to control the MAX thread of PHP-CGI's NO.? - avnhenry - 10-27-2010 07:12 PM

Lighttpd is known to have memory leakage problems.I had a scenario similar to yours. No matter what I did in the kernel parameters and/or to lightly config file,the crash kept happening randomly.This directive allows you to disable certain functions for security reasons.It takes on a comma-delimited list of function names. disable_functions is not affected by Safe Mode.


RE: How to control the MAX thread of PHP-CGI's NO.? - nikolas22t - 03-24-2011 06:17 PM

I have a serious problem with server memory on a VM , every few minutes or hours server gives a message "out of memory, killed process php5-cgi" the options below are comment out on each domain , but still have the problem , any other suggestion ?

PHP_FCGI_CHILDREN=2
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=500
export PHP_FCGI_MAX_REQUESTS


RE: How to control the MAX thread of PHP-CGI's NO.? - kilburn - 03-24-2011 09:39 PM

We need more specific information on your server's resources and how are they being utilized. How much memory does it have? How many apache worker processes is it running? How many php-cgi processes? How much memory is assigned to mysql? etc...