1

I have set up FastCGI to run my PHP site, and I found that when I generate a big file using the site, only one php-cgi process is working and its CPU usage is 100%. But the total CPU usage is only 25%.

Here is the "top -u user" output.

top - 13:50:35 up  3:58,  3 users,  load average: 0.07, 0.20, 0.32
Tasks: 116 total,   1 running, 115 sleeping,   0 stopped,   0 zombie
Cpu(s):  25.0%us,  0.1%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:  35126760k total,  1090160k used, 34036600k free,    60644k buffers
Swap:        0k total,        0k used,        0k free,   289816k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                              
 7570 user  20   0  232m  13m  10m S  100.0  0.3   0:00.03 php-cgi                                                               
 7571 user  20   0  234m  16m  10m S  0.0  0.0   0:00.22 php-cgi                                                               
 7572 user  20   0  304m  86m  10m S  0.0  0.3   1:37.49 php-cgi                                                               
 7573 user  20   0  234m  15m 9228 S  0.0  0.0   0:00.16 php-cgi                                                               
 7574 user  20   0  232m  13m 9528 S  0.0  0.0   0:00.40 php-cgi                                                               
 7594 user  20   0  232m  13m  10m S  0.0  0.0   0:00.02 php-cgi                                                               
 7595 user  20   0  234m  14m 9492 S  0.0  0.0   0:00.09 php-cgi                                                               
 7596 user  20   0  232m  13m 9184 S  0.0  0.0   0:00.06 php-cgi                                                               
 7597 user  20   0  234m  15m 9500 S  0.0  0.0   0:00.03 php-cgi                                                               
 7598 user  20   0  232m  10m 7116 S  0.0  0.0   0:00.02 php-cgi                                                               
 7599 user  20   0  232m  13m  10m S  0.0  0.0   0:00.02 php-cgi                                                               
 7601 user  20   0  326m  33m  11m S  0.0  0.1   1:58.60 php-cgi                                                               
 7602 user  20   0  234m  14m 8988 S  0.0  0.0   0:00.14 php-cgi                                                               
 7603 user  20   0  234m  12m 6800 S  0.0  0.0   0:00.15 php-cgi                                                               
 7604 user  20   0  308m  13m 9848 S  0.0  0.0   0:00.13 php-cgi

The server is AWS m2.x2large instance and it got 4 vCPU (4 cores maybe). And now the FastCGI seems to only use one core.

I have no idea about how to set up FastCGI to let it use all 4 vCPU.

My current settings is FastCGI + suEXEC + PHP 5.5.11 + apache2.

Here is teh FastCGI configurations in apache:

FcgidIPCDir /usr/local/apache2/logs/mod_fcgid
FcgidProcessTableFile /usr/local/apache2/logs/mod_fcgid/fcgid_shm
FcgidIOTimeout 7200
FcgidMaxRequestLen 2097152
FcgidMaxProcesses 100
FcgidMaxProcessesPerClass 100
FcgidMaxRequestsPerProcess 5000
FcgidMaxRequestInMem 20971520
FcgidZombieScanInterval 5
FcgidIdleScanInterval 120
FcgidProcessLifeTime 3600

Here is the /cgi-bin/php.fcgi settings:

#!/bin/bash
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
### Set PATH ###
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=5000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI

Please help me on this.

Thank you very much in advance!

Charles
  • 675
  • 3
  • 12
  • 21

1 Answers1

0

The process is using 100% of one core, which is 25% of your total processing power (4 cores). There isn't a way for a single thread to use more than 1 core, but it looks like FastCGI can be configured to use multiple threads. Refer to this question for more details.

Note that 1 request can only result in 1 thread, so if this is handling a single request, there doesn't seem to be a way to have that request handled in multiple threads.

Community
  • 1
  • 1
Quentin Skousen
  • 1,035
  • 1
  • 18
  • 30