Apache Performance

Posted on 2011-05-09
Last Modified: 2012-05-11
I have a web server that has a php mysql application accessed by 100+ users on the admin side and a public portal that gets pretty good traffic. I am getting server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers), spawning 8 children, there are 3 idle, and 15 total children in the log file and complaints from the admin side of pages timing out. I have 4 GB Ram, Quad-Core Xeon. I need to know what the optimal settings in httpd.conf file should be. It is set to the defaults now. Thanks in advance Russ
Question by:techsrx
    LVL 4

    Expert Comment

    It is not clear what are you using now.

    In any case you need to run php from under fastcgi or fcgid so the php process pool is decoupled from client connection pool, otherwise you will run out of RAM very soon with small number of clients. When you started your app under fcgid you need also to be sure you are using event or thread worker version of http daemon which you might want to install via your OS package system (not sure what are you using).

    fcgid manages process pool dynamically. Fastcgi - statically. If you run fastcgi configure it for 100 processes - that should be plenty. Configure apache server for 1000 clients and 10 apache children each running 100 threads or so.
    LVL 9

    Expert Comment

    I would venture to guess that the problem isn't with Apache, but actually with either the database or (most likely) PHP itself.  I had an issue where I implemented the magic "__autoload()" method to dynamically include the appropriate class files, which caused a lot of disk I/O, resulting in load times of 2-10 seconds [see ].

    Anyway, the point is that you should try to determine where the bottleneck is.  I used valgrind + KCacheGrind to determine the problem.  Find the bottleneck first, unless you're positive that it is apache.

    Author Comment

    The system is RHE Linux, apache 2, mysql 5, php 5. This is from apache server-status

    Current Time: Tuesday, 10-May-2011 17:44:51 MDT
    Restart Time: Tuesday, 10-May-2011 12:23:55 MDT
    Parent Server Generation: 0
    Server uptime: 5 hours 20 minutes 55 seconds
    Total accesses: 372786 - Total Traffic: 787.3 MB
    CPU Usage: u403.4 s30.34 cu.55 cs0 - 2.26% CPU load
    19.4 requests/sec - 41.9 kB/second - 2214 B/request
    18 requests currently being processed, 15 idle worker
    LVL 4

    Accepted Solution

    It is not clear if you running mod_php, fcgid, fastcgi or bare php.
    If you run barephp then your system will be mostly wasting time starting php application which will drastically affect request latency.

    You need to fix it with fcgid or fastcgi.

    This is example of how to run fcgid:

    1. install package tha has apache2 fcgid module and enable it (depends on your OS packaging system).
    2. install php5-cgi  (php5 compiled with fastcgi support) via OS packaging system.
    3. Your site apache config should look approximately like this:

    DefaultInitEnv PHP_FCGI_MAX_REQUESTS 500
    MaxRequestsPerProcess 500
    MaxProcessCount 80
    BusyTimeout 300
            <Directory /opt/yourapplication/directory>
                    Options ExecCGI FollowSymlinks
                    AddHandler fcgid-script .php
                    FCGIWrapper /usr/bin/php5-cgi .php
                    Order allow,deny
                    allow from all

    This will launch all php scripts via fcgid process pool.
    max process count is 80 (which should be plenty in most of cases)
    longest connection is set to 300 seconds
    after 500 requests the child will recycle itself to clear possible memory leaks.

    When you configure this your latency and memory/cpu should improve significantly and you should see several (from 1-2 to the max number of 80 ) php5-cgi processes running waiting for your requests after you execute at least single request to your php application.

    Author Comment

    ok I installed php with fastcgi support, I am still having complaints that the application is running slow and get this in the log file

     server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers), spawning 16 children, there are 7 idle, and 50 total children
    server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers), spawning 8 children, there are 0 idle, and 42 total children
    server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers), spawning 8 children, there are 0 idle, and 42 total children

    Also getting <php-cgi defunct> from time to time


    <IfModule prefork.c>
    StartServers       16
    MinSpareServers    10
    MaxSpareServers   30
    ServerLimit      256
    MaxClients       256
    MaxRequestsPerChild  4000

    Current Time: Saturday, 14-May-2011 11:04:06 MDT
    Restart Time: Thursday, 12-May-2011 20:18:34 MDT
    Parent Server Generation: 0
    Server uptime: 1 day 14 hours 45 minutes 32 seconds
    Total accesses: 887636 - Total Traffic: 419.2 MB
    CPU Usage: u17.95 s7.31 cu730.7 cs0 - .542% CPU load
    6.36 requests/sec - 3150 B/second - 495 B/request
    15 requests currently being processed, 21 idle workers

    I am not sure what to do next.
    LVL 4

    Expert Comment

    defunc process is normal as long as it wont stay for a long time.

    Using prefork server does not make sense (very poor performance and memory footprint). You need to use thread worker with fastcgi.
    Configure about 100 threads per process and launch 10 children. You will have 1000 max clients versus only 30 you have now.

    The beauty of fastcgi is that you can decouple php process from client connection. You run only 50 processes while you can take 1000 connections. With perfork number of connections = number of processes.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
    Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now