Limit PHP Processes per Domain

9 posts / 0 new
Last post
#1 Thu, 04/03/2008 - 03:41
ADobkin

Limit PHP Processes per Domain

Is it possible to limit the total number of PHP processes per domain in Virtualmin? If so, how is this done?

One of our hosted sites is getting slammed with activity, and it is spawning several hundred php-cgi processes (using FastCGI / php5.fcgi) at a time. This activity is sucking up all available memory and CPU, which is preventing access to all other sites and services on the server. What can we do in this situation?

FYI, I am aware of the option to set the "PHP FCGId sub-processes" (default of 4), but I want to limit the total number that can be spawned for a single domain. For example, under Server Owner Limits, there is an option for "Maximum Mongrel server processes for Rails", but I do not see any options for PHP FCGId.

Thanks, Alan

Wed, 04/16/2008 - 08:45
ADobkin

FYI, I have opened up an RFE for this issue in the bug tracker:

FS#3850 - RFE: Server Resource Limits
http://www.virtualmin.com/index.php?option=com_flyspray&Itemid=82&am...

I didn't receive any responses to my initial post here, but I feel this issue is too important (and too easy to fix) to ignore.

Thanks,
Alan

Tue, 04/22/2008 - 01:01
joyent

Alan, if you're using mod_fcgid, you should be able to do that. The process limits in mod_fcgid are rock solid in my experience. The mod_fcgid directives for this is DefaultMaxClassProcessCount, and actually applies on a per virtual host basis (Apache wise).

The thing to avoid though is to use PHP's own dynamic spawning (which I fear is Virtualmin's default). If you see any mention of 'PHP_FCGI_CHILDREN' in your PHP wrapper scripts (php5.fcgi), remove those lines. If you do have them there, you're actually using two layers of dynamic spawning - mod_fcgid and PHP. PHP's native spawning sucks big time (basically - it fires up the maximum processes allowed (as per PHP_FCGI_CHILDREN) no matter what kind of traffic comes in, so you're wasting a lot of memory.

There is a config option in VMPro to define a custom PHP wrapper (Jamie implemented that on my request) so you can get rid of those for new virtual servers too. I've seen sites getting hammered by spammers, but mod_fcgid stayed solid and didn't yield an inch.

Tue, 04/22/2008 - 01:35 (Reply to #3)
Joe
Joe's picture

<div class='quote'>The thing to avoid though is to use PHP's own dynamic spawning (which I fear is Virtualmin's default).</div>

Not in the next release. It got added at customer request a while back, and it took a while for it to become apparent that it's not the right choice here.

--

Check out the forum guidelines!

Fri, 09/25/2009 - 08:48 (Reply to #4)
Hal9000

i've been suffering from fork bombs lately, so i stumbled across this thread that, i hope, will help me to solve the problem. ok so my /etc/apache2/mods-enabled/fcgid.conf now looks like this

<IfModule mod_fcgid.c>
  AddHandler    fcgid-script .fcgi
  IPCConnectTimeout 120
  IPCCommTimeout 120
  DefaultMaxClassProcessCount 5
</IfModule>

so basically i added DefaultMaxClassProcessCount 5 to the file. now, in all /home/*/fcgi-bin/php5.fcgi i have

#!/bin/bash
ulimit -t 3600
PHPRC=$PWD/../etc/php5
export PHPRC
umask 022
export PHP_FCGI_CHILDREN
SCRIPT_FILENAME=$PATH_TRANSLATED
export SCRIPT_FILENAME
exec /usr/bin/php5-cgi

so PHP_FCGI_CHILDREN as you can see is there. is this correct or should that be removed? also, why is that php5.fcgi file also in /home/*/public_html/ ?

cheers

Fri, 09/25/2009 - 08:53 (Reply to #5)
andreychek

Another option as well would be to go into Administration Options -> Edit Resource Limits, and to set "Max Number of Processes" for any Virtual Servers you'd like to have limits for.

-Eric

Fri, 09/25/2009 - 09:18 (Reply to #6)
Hal9000

yes, i actually wanted to start a thread about that... cause i want to set the limits there, but i find nowhere in the docs or whatever what some sane values would be. i plan to set different limits depending on the server plan, so what would be an example for small websites and one for more trafficated websites? what does count as process there anyway, besides the web server? i really wat to know what i'm doing before setting any limits to anyone...

Fri, 09/25/2009 - 09:30 (Reply to #7)
andreychek

It refers to processes owned by a given user that may run at any point in time.

It's difficult to give any specific numbers, but my suggestion would be to take a peek at your current process list, see how many processes are owned by certain users at any given time, and work on some numbers based on that.

All it does is set /etc/security/limits.conf.

Those limits aren't particularly graceful, I tend to view them, at best, as a way to keep users from accidentally using all the resources on the system.

-Eric

Fri, 09/25/2009 - 17:37 (Reply to #8)
Hal9000

thanks dude, will try that on sunday, depending on how many beers i will get on saturday.

Topic locked