I call this fine tuning but it’s not for any production server, just
to serve my need on the laptop. I don’t really interested in
performance tuning right now but as I keep working, my laptop start to
crawl. Quick check with ps auxww show’s a long list of php process
running, so this is the culprit that keep eating my memory. There must
be someway to configure the number of process fastcgi would created.
First I checked my php wrapper and this is how it’s look like:-
#!/bin/sh PHPRC="/etc" export PHPRC PHP_FCGI_CHILDREN=100 export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=4000 export PHP_FCGI_MAX_REQUESTS exec /srv/www/fcgi-bin/php
That’s it. I set the maximum requests to 4000. Changing the value to 10 gave a big difference. I checked back apache mod_fastcgi manual to see what’s all those variables meant for. Here are some excerpt from the manual that I want to take notes for future references:-
PHPFCGICHILDREN (default value: 8)
This controls how many child processes the PHP process spawns. When the fastcgi starts, it creates a number of child processes which handle one page request at a time. So by default, you will be able to handle 8 concurrent PHP page requests. Further requests will be queued. Increasing this number will allow for better concurrency, especially if you have pages that take a significant time to create, or supply a lot of data (e.g. downloading huge files via PHP). On the other hand, having more processes running will use more RAM, and letting too many PHP pages be generated concurrently will mean that each request will be slow.
PHPFCGIMAX_REQUESTS (default value: 500)
This controls how many requests each child process will handle before exitting. When one process exits, another will be created. This tuning is necessary because several PHP functions are known to have memory leaks. If the PHP processes were left around forever, they would be become very inefficient. - from README.FastCGI in PHP Sources
-maxClassProcesses n (10) The maximum number of dynamic FastCGI application instances allowed to run for any one FastCGI application. It must be <= to -maxProcesses (this is not programmatically enforced). -maxProcesses n (50) The maximum total number of dynamic FastCGI application instances allowed to run at any one time. It must be >= to -maxClassProcesses (this is not programmatically enforced).
-singleThreshold n (0) An integer between 0 and 100 used to determine whether the last instance of a FastCGI application can be terminated. If the process manager computed load factor for the application is lower than the specified threshold, the last instance is terminated. In order to make your executables run in the “idle” mode for the long time, you would specify a value closer to 1, however if memory or CPU time is of primary concern, a value closer to 100 would be more applicable. A value of 0 will prevent the last instance of an application from being terminated; this is the default value, changing it is not recommended (especially if -appConnTimeout is set). For historic reasons the mis-spelling singleThreshhold is also accepted. - from apache mod_fastcgi manual
and this is the apache config for mod_fastcgi:-
FastCgiIpcDir /tmp AddHandler fastcgi-script .fcgi #FastCgiSuexec /usr/sbin/suexec2 FastCgiWrapper /usr/sbin/suexec2 FastCgiConfig -singleThreshold 60 -killInterval 300 -autoUpdate -idle-timeout 240 -pass-header HTTP_AUTHORIZATION
