Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many php-cgi processes should I run?

Tags:

php

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 of thinking make sense? How do you calculate how many processes to run?

like image 567
yhager Avatar asked Nov 15 '22 13:11

yhager


1 Answers

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
like image 94
Lance Rushing Avatar answered Dec 01 '22 00:12

Lance Rushing