The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

FcgidMaxProcesses not respected

Discussion in 'Workarounds and Optimization' started by AngelNo3, Jan 31, 2013.

  1. AngelNo3

    AngelNo3 Member

    Joined:
    Dec 17, 2012
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    In Apache Configuration > Include Editor > Pre VirtualHost Include > All Versions, I've set my FastCGI settings as follows:

    Code:
    <IfModule fcgid_module>
    	# Allows override of value set in wrapper script
    	FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 500
    	# FcgidMaxRequestsPerProcess should be <= PHP_FCGI_MAX_REQUESTS
    	FcgidMaxRequestsPerProcess 500
    	
    	FcgidMaxProcesses 15
    	FcgidMinProcessesPerClass 0
    	FcgidMaxProcessesPerClass 8
    
    	FcgidIdleTimeout 30
    	FcgidIdleScanInterval 15
    	FcgidProcessLifeTime 60
    	FcgidIOTimeout 300
    	FcgidZombieScanInterval 3
    
    	FcgidMaxRequestLen 268435456
    </IfModule>
    However, despite this, when I use top I see that up to 40 or more php processes are running at any given time, each using 30-55 MB, and eating up my RAM. I would expect the settings above would limit these to no more than 15 (i.e., the value of FcgidMaxProcesses), which would be a tolerable amount. But it's not happening ... the setting seems to have no effect. Any ideas what I might be doing wrong?
     
  2. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    I find that sometimes restarting apache causes fcgid to leave orphaned php processes running, so check for that first.

    The following command will close any orphaned php processes.

    Code:
    /bin/ps -Ao'command,pid,ppid'|/bin/grep ' 1$'|/bin/grep /php|/bin/awk '{ print $2; }'|/usr/bin/xargs --no-run-if-empty kill -9
    You may want to add it to your root cron at /var/spool/cron/root

    Code:
    */5 * * * * /bin/ps -Ao'command,pid,ppid'|/bin/grep ' 1$'|/bin/grep /php|/bin/awk '{ print $2; }'|/usr/bin/xargs --no-run-if-empty kill -9
    Scanning for idle so often and having such a short process lifetime kind of defeats some of the benefits of having fcgid unless you're really really tight on memory. How much memory do you have and how many accounts on your server?
     
  3. AngelNo3

    AngelNo3 Member

    Joined:
    Dec 17, 2012
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I tried the first command, and it spits out a bunch of lines that say `kill: can't find process "-c"`.

    I have 2 GB of memory, 3GB burstable. There is only one cPanel account running on the VPS.

    The settings were an attempt to kill off what appeared to be idle PHP processes, because they were choking out my RAM, even though most of them were using 0.0% CPU. I am new to managing a VPS, so I may not have done the best thing. Any suggestions welcome and appreciated.
     
    #3 AngelNo3, Feb 4, 2013
    Last edited: Feb 4, 2013
  4. AngelNo3

    AngelNo3 Member

    Joined:
    Dec 17, 2012
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Here is sample top output:
    Code:
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                              
     1795 mysql     15   0 3229m 629m 7128 S  0.0 20.5 193:48.01 mysqld                                                               
     1434 nobody    18   0  440m 129m  736 S  0.0  4.2  33:39.39 memcached                                                            
    19504 XXXXXXX   16   0  243m  52m 8252 S  0.0  1.7   0:10.84 php                                                                  
     4024 named     25   0 1876m  51m 2604 S  0.0  1.7   0:06.23 named                                                                
     9625 XXXXXXX   15   0  243m  50m 7908 S  0.0  1.6   0:01.84 php                                                                  
     9564 XXXXXXX   15   0  241m  49m 7880 S  0.0  1.6   0:01.47 php                                                                  
     9566 XXXXXXX   15   0  239m  48m 8060 S  0.0  1.6   0:02.92 php                                                                  
    27756 XXXXXXX   15   0  238m  46m 8740 S  0.0  1.5   0:23.66 php                                                                  
     9623 XXXXXXX   15   0  237m  45m 8008 S  0.0  1.5   0:00.95 php                                                                  
    21621 XXXXXXX   16   0  237m  45m 8932 S  0.0  1.5   1:10.73 php                                                                  
     8036 XXXXXXX   16   0  237m  44m 8928 S  0.0  1.5   0:12.18 php                                                                  
     7718 XXXXXXX   16   0  238m  44m 8704 S  0.0  1.5   0:02.47 php                                                                  
     8132 XXXXXXX   16   0  237m  44m 8960 S  0.0  1.5   0:47.85 php                                                                  
    29713 XXXXXXX   16   0  237m  44m 8788 S  0.0  1.4   0:51.62 php                                                                  
     3333 XXXXXXX   15   0  236m  44m 9004 S  0.0  1.4   2:23.52 php                                                                  
     8131 XXXXXXX   16   0  236m  44m 8972 S  0.0  1.4   0:56.22 php                                                                  
     6044 XXXXXXX   16   0  236m  44m 8908 S  0.0  1.4   0:43.76 php                                                                  
    19513 XXXXXXX   15   0  236m  44m 8900 S  0.0  1.4   0:43.80 php                                                                  
     7722 XXXXXXX   16   0  238m  44m 8444 S  0.0  1.4   0:00.48 php                                                                  
     3697 XXXXXXX   16   0  236m  44m 8756 S  0.0  1.4   1:14.46 php                                                                  
    22122 XXXXXXX   16   0  236m  44m 8736 S  0.0  1.4   0:28.45 php                                                                  
     8136 XXXXXXX   15   0  236m  43m 8888 S  0.0  1.4   0:56.82 php                                                                  
    32672 XXXXXXX   15   0  236m  43m 8888 S  0.0  1.4   0:25.54 php                                                                  
     3716 XXXXXXX   16   0  236m  43m 8884 S  0.0  1.4   0:43.38 php                                                                  
    27690 XXXXXXX   15   0  234m  43m 8880 S  0.0  1.4   0:17.87 php                                                                  
    19527 XXXXXXX   15   0  236m  43m 8916 S  0.0  1.4   0:40.32 php                                                                  
    32057 XXXXXXX   18   0  236m  43m 8740 S  0.0  1.4   1:15.55 php                                                                  
     5870 XXXXXXX   16   0  236m  43m 8884 S  0.0  1.4   0:59.74 php                                                                  
    22126 XXXXXXX   15   0  236m  43m 8540 S  0.0  1.4   0:01.08 php                                                                  
     7386 XXXXXXX   15   0  236m  43m 8540 S  0.0  1.4   0:01.02 php                                                                  
    28129 XXXXXXX   16   0  236m  43m 8444 S  0.0  1.4   0:00.59 php                                                                  
    22125 XXXXXXX   16   0  235m  43m 8712 S  0.0  1.4   0:04.99 php                                                                  
     7721 XXXXXXX   15   0  235m  42m 8548 S  0.0  1.4   0:00.54 php                                                                  
     5228 XXXXXXX   16   0  235m  42m 8560 S  0.0  1.4   0:00.61 php                                                                  
     6038 XXXXXXX   15   0  235m  42m 8548 S  0.0  1.4   0:00.60 php                                                                  
     3717 XXXXXXX   15   0  234m  42m 8916 S  0.0  1.4   1:02.94 php                                                                  
     5233 XXXXXXX   16   0  235m  42m 8540 S  0.0  1.4   0:00.60 php                                                                  
    27762 XXXXXXX   16   0  235m  42m 8536 S  0.0  1.4   0:00.60 php                                                                  
    28421 XXXXXXX   16   0  235m  42m 8536 S  0.0  1.4   0:00.44 php                                                                  
    28423 XXXXXXX   15   0  235m  42m 8532 S  0.0  1.4   0:00.43 php                                                                  
     5221 XXXXXXX   16   0  235m  42m 8532 S  0.0  1.4   0:00.59 php                                                                  
     6039 XXXXXXX   15   0  235m  42m 8532 S  0.0  1.4   0:00.50 php                                                                  
    28122 XXXXXXX   16   0  235m  42m 8532 S  0.0  1.4   0:00.53 php                                                                  
    27785 XXXXXXX   15   0  235m  42m 8532 S  0.0  1.4   0:00.61 php                                                                  
     6037 XXXXXXX   15   0  235m  42m 8536 S  0.0  1.4   0:00.55 php                                                                  
     8056 XXXXXXX   15   0  234m  42m 8720 S  0.0  1.4   0:11.40 php                                                                  
    27739 XXXXXXX   15   0  232m  42m 8720 S  0.0  1.4   0:16.71 php                                                                  
    31879 XXXXXXX   15   0  234m  42m 8928 S  0.0  1.4   1:02.06 php                                                                  
     6035 XXXXXXX   15   0  235m  41m 8548 S  0.0  1.4   0:00.58 php                                                                  
    28124 XXXXXXX   16   0  235m  41m 8548 S  0.0  1.4   0:00.59 php 
    
     
  5. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    Not sure why you got an error. Make sure you copied the entire command.

    To figure out if any of those are orphans another way, you could install htop which is a fancier version of top (htop - an interactive process-viewer for Linux).

    Type:

    yum install htop

    Then after installing, just type htop. At the bottom of the interface you should see "F5 Tree". Press F5 and it will then show what processes are children of other processes. Your PHP processes should be children of httpd. If they are not, then they're likely orphaned and the previous command should clear them, or at least it does with my CENTOS install. Maybe you're running a different OS?

    Otherwise I'm not sure why valid php process are not being killed when they reach the limits set by your settings above.
     
  6. AngelNo3

    AngelNo3 Member

    Joined:
    Dec 17, 2012
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I tried installing htop, and got this:

    Code:
    # yum install htop
    Loaded plugins: fastestmirror
    Determining fastest mirrors
     * base: mirrors.seas.harvard.edu
     * extras: mirror.umd.edu
     * updates: mirror.umd.edu
    base                                                                                             | 3.7 kB     00:00     
    base/primary_db                                                                                  | 4.5 MB     00:00     
    extras                                                                                           | 3.5 kB     00:00     
    extras/primary_db                                                                                |  23 kB     00:00     
    imhbase                                                                                          |  951 B     00:00     
    imhbase/primary                                                                                  | 8.1 kB     00:00     
    imhbase                                                                                                           42/42
    updates                                                                                          | 3.5 kB     00:00     
    updates/primary_db                                                                               | 5.1 MB     00:00     
    Setting up Install Process
    No package htop available.
    Error: Nothing to do
     
  7. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    You may need to add a rpm repository first so yum can find top.

    The following site has some wget and 32-bit / 64-bit rpm commands to run first.

    Installing htop
     

Share This Page