Current time: 11-16-2024, 10:04 AM Hello There, Guest! (LoginRegister)


Post Reply 
How to control the MAX thread of PHP-CGI's NO.?
Author Message
jetvster Offline
Junior Member
*

Posts: 19
Joined: Jun 2009
Reputation: 0
Post: #1
How to control the MAX thread of PHP-CGI's NO.?
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?
(This post was last modified: 01-25-2010 01:22 PM by jetvster.)
01-25-2010 12:53 PM
Find all posts by this user Quote this message in a reply
kilburn Offline
Development Team
*****
Dev Team

Posts: 2,182
Joined: Feb 2007
Reputation: 34
Post: #2
RE: How to control the MAX thread of PHP-CGI's NO.?
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.
01-25-2010 05:27 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Nuxwin
Unregistered

 
Post: #3
RE: How to control the MAX thread of PHP-CGI's NO.?
@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.
10-19-2010 06:17 PM
Quote this message in a reply
kilburn Offline
Development Team
*****
Dev Team

Posts: 2,182
Joined: Feb 2007
Reputation: 34
Post: #4
RE: How to control the MAX thread of PHP-CGI's NO.?
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.
10-19-2010 06:26 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Nuxwin
Unregistered

 
Post: #5
RE: How to control the MAX thread of PHP-CGI's NO.?
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/ta...iew=markup


http://www.mail-archive.com/php-cvs@list...24066.html
10-19-2010 06:29 PM
Quote this message in a reply
avnhenry Offline
Banned

Posts: 5
Joined: Oct 2010
Post: #6
RE: How to control the MAX thread of PHP-CGI's NO.?
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.
10-27-2010 07:12 PM
Find all posts by this user Quote this message in a reply
nikolas22t Offline
Junior Member
*

Posts: 16
Joined: Nov 2009
Reputation: 0
Post: #7
RE: How to control the MAX thread of PHP-CGI's NO.?
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
03-24-2011 06:17 PM
Find all posts by this user Quote this message in a reply
kilburn Offline
Development Team
*****
Dev Team

Posts: 2,182
Joined: Feb 2007
Reputation: 34
Post: #8
RE: How to control the MAX thread of PHP-CGI's NO.?
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...
03-24-2011 09:39 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)