• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

Apache Performance

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
0
techsrx
Asked:
techsrx
  • 3
  • 2
1 Solution
 
a1jCommented:
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.
0
 
crazedsanityCommented:
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 http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Apache/Q_26749583.html ].

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.
0
 
techsrxAuthor Commented:
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
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
a1jCommented:
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
        </Directory>



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.
 
0
 
techsrxAuthor Commented:
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

httpd.conf

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

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.
0
 
a1jCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now