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.

Limit number of php processes

Discussion in 'Security' started by giany, Mar 17, 2010.

  1. giany

    giany Registered

    Joined:
    Mar 16, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I maintain a hosting server that has like 250 domains on it. I'm facing a problem with some domains (wordpress, joomla ....) that have buggy code (memory leaks). When someone accesses those sites a lot of php processes spawn (1000-2000 processes) and consume all the RAM and SWAP and eventually the server will crash.

    Is there a way to limit the number of spawned processes? Or a way to avoid this kind of problem?
     
  2. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Yes you can, though 250 domains is probably pushing the limits of what you would want to host on one server particularly if those are active or heavily visited.

    You failed to tell any of us anything about your current PHP configuration so my very first question to you is what flavor of PHP are you running --

    dso, cgi, suphp, fastcgi, phpsuexec, etc?

    The type of PHP you are running will make a major difference on what you need to do settings wise and can in itself be a solution as well.

    My second question to you is whether you are running an MPM module?

    I would at the very least barebones be running MPM Prefork especially given the number of domains you are hosting though with either SuPHP or FCGI, you will have the additional option of running MPM Worker which would directly address your question about process spawning quite a bit though of those two, I would lean more towards FCGI than SuPHP in your case because FCGI utilizes a non-blocking process design that would be a bit more efficient for you in terms of process queuing and spawning and these days has the security of SuPHP but also performance exceeding that of Apache module (dso) if configured properly.

    My third question to you would be to ask you about your server's resources and more specifically how much memory do you have installed on the server first and foremost and second to that what kind of processor are you running on your server? Are you using a 32 bit or 64 bit operating system? This also can make a substantial difference.

    If you have a multiple core processor, you might be very surprised at just how many people don't realize that they have to enable the additional cores in both the operating system and server applications to make full use of their processor. Most just run their processors with one single core functioning and the stats reading out blind from the rest.

    Other than these items, you will want to take a very hard look at your Apache performance settings and what values you are using for the number of connections, spare threads (or servers), timeouts, etc
    The idea here is that you want to optimize your performance but keep those numbers in line with your actual true hardware resources.

    Anyway though, there is probably a whole lot you can do to put a leash on processes spawned and resource consumption but some more information would be needed to properly assess your best direction to go with all of that.
     
  3. giany

    giany Registered

    Joined:
    Mar 16, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I believe only aprox 50 sites are active and heavily visited. Load is like under 1 most of the time.


    PHP 5.2.9 (cli) (built: Nov 25 2009 16:51:12)
    Copyright (c) 1997-2009 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with eAccelerator v0.9.6-rc1, Copyright (c) 2004-2007 eAccelerator, by eAccelerator
    with the ionCube PHP Loader v3.3.10, Copyright (c) 2002-2009, by ionCube Ltd., and
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
    with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH

    I'm not using mpm module only prefork.


    I'm using Centos 5.4 64 bit with 6GB Ram and dual core Intel(R) Xeon(R) CPU 5130 @ 2.00GHz.

    I tried to do some performance tests for apache using the ab tool and results were ok. The only problem I have with this poorly coded plugins that cause the server to crash. Any help would be appreciated.
     
  4. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    You didn't actually tell my what kind of PHP you have from any of that but given that you have the outdated obsolete default 5.2.9 and eAccelerator enabled, I would take a guess that you are likely DSO which means you could cut down the loads a lot changing to something else as mod_php (dso) allocates resources on each request and uses a blocking pattern where you effectively move through requests in order instead of concurrently and that amounts to more memory overhead and processing for Apache as well.

    That is a contradictory statement --- prefork *IS* an MPM module

    Don't see any real issues there ...

    Not sure what plugins you have but may possible be able to help there
    and I have some very slick programs that can go in and rewrite bad
    code for many programs including unknown programs in a heartbeat.

    I think upgrading and changing your PHP may help the most though.

    Anyway, I have sent you my contact info by private message ...
     
  5. gswahhab

    gswahhab Registered

    Joined:
    Mar 18, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    one site in particular keeps crashing the server.
    i am having the exact same issue. i am running phpsuexec
    vps, have 1gb ram 3 cores about 30 sites only a few are active. the one that is

    most active is the one that keeps crashing the site. my host suggested i switch to fastcgi as well but i am not sure what effect it would have and if it would screw everything up b/c of file permissions. i dont believe i have mpm but wouldnt know how to check either
     
  6. gswahhab

    gswahhab Registered

    Joined:
    Mar 18, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    forgot to mention its 64bit. additionally is there a way i can narrow down the code to see where the bad code is coming from?
     
  7. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Are you certain that you are running phpsuexec?

    This is very often commonly confused with SuPHP but if you are indeed actually running phpsuexec then I would advice that you change over to either SuPHP or FCGI as phpsuexec is quite ancient and very insecure.

    Code:
    # /usr/local/cpanel/bin/rebuild_phpconf --current | grep "PHP5"
    
    Well there is why you are crashing! 30 sites on a 1 GB VPS? Eeww!

    (Disregarding the cynicism though well warranted, I might be able to help you determine what scripts, sites, and processes are most impacting your resources and bringing your server down)

    Yes, FastCGI would be infinitely better! Permissions can remain the same between phpsuexec (cgi w/ suexec), SuPHP (suphp), and FastCGI (fcgi). You only run into permission changing problems if you are changing between Apache module (dso) and anything else.

    Regarding "mpm", if you have one enabled, it is likely "prefork" ---
    Code:
    # httpd -l | grep "prefork\|worker"
    
    If you see "worker.c" or "prefork.c" returned from the above command then you do have an mpm module enabled though that does not necessarily mean that it is properly configured or optimized though.
     
  8. goodmove

    goodmove Well-Known Member

    Joined:
    May 12, 2003
    Messages:
    624
    Likes Received:
    0
    Trophy Points:
    16
    Could you give some brief pointers as to how to check whether the OS, Apache, PHP & MySQL are utilising all the processor cores available, both physical and virtual cores as in Hyper-Threading?
     
Loading...

Share This Page