Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Apache Performance

Posted on 2011-05-09
6
Medium Priority
?
483 Views
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
0
Comment
Question by:techsrx
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:a1j
ID: 35725997
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
 
LVL 9

Expert Comment

by:crazedsanity
ID: 35729641
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
 

Author Comment

by:techsrx
ID: 35734189
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Accepted Solution

by:
a1j earned 2000 total points
ID: 35734308
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
 

Author Comment

by:techsrx
ID: 35760880
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
 
LVL 4

Expert Comment

by:a1j
ID: 35786704
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

571 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