开发者

How many php-cgi processes should I run?

开发者 https://www.devze.com 2022-12-14 10:13 出处:网络
I am asking about a web server running a light front (nginx in my case), with PHP processes accessed through fastcgi.

I am asking about a web server running a light front (nginx in my case), with PHP processes accessed through fastcgi.

I am trying to figure out a way to methodically calculate how many PHP cgi processes should be running in the machine.

One way to think of it is figure out the average memory footprint of a process, and run as many as possible within the limits of available RAM. However, this does not bring CPU usage into the question.

Since CPU is the real bottleneck in my application (DB and memcache are used, but are not the bottlenecks), I am thinking that the base number for php processes should be the number of CPUs available.

For example - in an 8 core machine, the base number would be 8. Assuming some processes do wait for database or network, I do not see any reason to run more than 20 PHP processes alltogether.

Does that way o开发者_如何学Pythonf thinking make sense? How do you calculate how many processes to run?


Option 1: Use your apache logs to determine duration at peak times.

Add duration to your log format. (something like)

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" duration:%T/%D 

Then do some log file parsing to analyze the number of concurrently processing requests.

Option 2 (if application has dedicated apache server): Write a cron job to log the number of apache processes:

# Quick hack to log apache processes 
* * * * * date -R >> /tmp/apache_count &&  ps -A | grep httpd | grep -v grep | wc -l > /tmp/apache_count
0

精彩评论

暂无评论...
验证码 换一张
取 消