Poor PHP performance with fcgid

Hi there!

I am struggling to get decent performance with PHP running through fcgid.
The problem is that at times, when a virtual server is called from a browser, the server actually takes a couple of seconds to respond. About 2-3 seconds. Then the site runs perfectly fine and snappy.

To me it seems like the php process is sleeping or just not existant, so the server needs some time to get it started. But 3 seconds? Isn’t it a bit much?
The server by the way is not under heavy load… enough ram, load usually is around 0.2-0.4.

I switched a site to mod_php and the problem was gone. But since I want to retain the benefits of fcgid, I tried to improve things a bit:

  • i switched to the worker mpm, which also removes the mod_php thing
  • i removed the PHP_FCGI_CHILDREN option from the /home/*/fcgi-bin/php5.fcgi files, which now look like this:

#!/bin/bash
ulimit -u 50
ulimit -v 1048576
PHPRC=$PWD/…/etc/php5
export PHPRC
umask 022
SCRIPT_FILENAME=$PATH_TRANSLATED
export SCRIPT_FILENAME
/usr/bin/php5-cgi

And here is my fcgid apache configuration

AddHandler fcgid-script .fcgi IPCConnectTimeout 60 IPCCommTimeout 90 IdleTimeout 3600 IdleScanInterval 60 ProcessLifeTime 3600 MaxProcessCount 64 MaxRequestsPerProcess 10000 DefaultMaxClassProcessCount 4 DefaultMinClassProcessCount 1

I am running the latest Virtualmin Pro on a Debian 5.0.5 x64 sysytem, apache and php5 are from the standard debian packages.

Is there anything i can do to fix this?

Howdy,

It’s unusual to see the problems you’re describing! What does the RAM usage look like on your system? You can determine that by running “free -m”?

Also, I’m curious if you see those issues when using PHP in CGI mode… that would still retain the security benefits of using FCGID. To switch to CGI mode, you can go into Server Configuration -> Website Options, and set “PHP script execution mode” to “CGI Wrapper”.

-Eric

total used free shared buffers cached Mem: 1998 1856 141 0 39 390 -/+ buffers/cache: 1426 571 Swap: 10247 510 9736

as for cgi mode, i will test tomorrow.
btw maybe i can optimize the fcgi module settings? i have not been able to find recommended settings from a good source…

basically it seems to me that after some time idling (or maybe due to some other criteria) the php process of the virtual server is shut down, so on the next request the process has to be started again. and that takes a couple of seconds.
is there a way to lengthen the timeout period, or even to avoid the process shutting down at all? that would make the server much more responsive at all times…

i found something interesting in the logs btw

[Mon Jul 19 23:21:33 2010] [notice] mod_fcgid: process 18044 going graceful shutdown, sending SIGTERM
[Mon Jul 19 23:21:33 2010] [notice] mod_fcgid: process 18045 going graceful shutdown, sending SIGTERM
[Mon Jul 19 23:21:39 2010] [notice] mod_fcgid: process /home/foo.tld/public_html/index.php(18044) exit(lifetime expired), get stop signal 15
[Mon Jul 19 23:21:39 2010] [notice] mod_fcgid: process /home/foo.tld/public_html/index.php(18045) exit(lifetime expired), get stop signal 15

i just changed my fcgi configuration to these more generous settings


AddHandler fcgid-script .fcgi
IPCConnectTimeout 60
IPCCommTimeout 90
IdleTimeout 21600
IdleScanInterval 900
ProcessLifeTime 21600
MaxProcessCount 128
MaxRequestsPerProcess 10000
DefaultMaxClassProcessCount 4
DefaultMinClassProcessCount 1


i hope it all will work better then…