Apache Out of Control

I could use some help from the expert team.  :-)  It appears that apache is running my CPU usage up.  See below.  Any ideas how I can tune apache to run smoothly?  Thanks!

top - 15:26:09 up 17:42,  1 user,  load average: 6.24, 2.62, 1.39
Tasks: 102 total,  19 running,  83 sleeping,   0 stopped,   0 zombie
Cpu(s): 99.0% us,  1.0% sy,  0.0% ni,  0.0% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:    483500k total,   470968k used,    12532k free,    61804k buffers
Swap:  2096472k total,      148k used,  2096324k free,   197592k cached

28471 apache    18   0 43068  14m 7904 R 18.4  3.1   0:54.98 httpd
28037 apache    18   0 43040  16m 9556 R 17.4  3.5   1:32.40 httpd
28452 apache    18   0 43100  14m 7872 R 17.0  3.1   0:59.17 httpd
28473 apache    18   0 43080  14m 7212 R 17.0  3.0   1:06.88 httpd
27208 mysql     16   0  129m  24m 3912 S  3.6  5.2   9:19.74 mysqld
28038 apache    18   0 43008  15m 8536 R  2.6  3.2   1:49.03 httpd
28045 apache    16   0 43088  15m 8712 S  2.6  3.3   1:09.00 httpd
28056 apache    18   0 43164  15m 9064 R  2.6  3.4   1:46.36 httpd
28229 apache    18   0 43088  14m 7248 R  2.6  3.0   1:24.19 httpd
28458 apache    18   0 43084  14m 7608 R  2.6  3.1   0:52.51 httpd
28049 apache    18   0 43076  14m 7788 R  2.0  3.1   1:32.82 httpd
28050 apache    18   0 43064  14m 7752 R  2.0  3.1   1:09.80 httpd
28053 apache    18   0 43092  14m 8084 R  2.0  3.2   1:09.18 httpd
28124 apache    18   0 43120  14m 7932 R  2.0  3.1   1:13.01 httpd
28466 apache    18   0 43080  14m 7156 R  2.0  3.0   0:33.49 httpd
28468 apache    18   0 43084  15m 8716 R  2.0  3.3   0:58.15 httpd
28071 apache    16   0 43096  14m 7748 S  1.3  3.1   1:34.49 httpd
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What are you doing?  Static pages? Dynamic pages?  

It looks like you are running MySQL also, by chance are you running some type of application under Apache that is accesing MySQL?  Could it be chewing up your CPU?
QuetysisAuthor Commented:
The pages are written in PHP.  The site is an online store.  We are also running MySQL and the store accesses the database.  Seems to me like the problem is with apache and not MySQL but I'm only basing this off of the fact that apache has spawned numerious processes and the MySQL information I looked at showed minimal database usage.
The may be IN Apache, not with Apache.  There is a difference.  

The application (PHP code) runs within the Apache process, so any and all CPU that the application uses will show up under the Apache tasks.  So the performance problem may be with the PHP code.

The problem may also be with the server you are running it on, it appears that you have a single CPU box and my personal opinion is that if you are running both an application and a database on a box you should have at least a dual CPU box.  You also have to look at CPU busy over a timeframe and not necessarly snap shots:

----> load average: 6.24, 2.62, 1.39

IIRC this means that over the last 5 minutes there have been and average 6.24 processes actually doing work, over the last 10 minutes there have been an average of 2.62 processes actually doing work, and over the 15 minutes there have been 1.39 processes actually doing work.  For a single CPU box a load average of 1.39 is not that bad.

As for the number of Apache processes, this is controlled by the apache parms.  You tell apache the number of processes to start automatically, the minimum number of spare processes, and the maximum number of  spare processes.  You need one for each concurrent connection.  IIRC, Apache defaults are:

    start = 8
    minspare = 5
    maxspare = 10

This means that when apache starts it will start 8 processes automatically, there must be at least 5 idle at all times, so once you get 4 concurrent connection, apache will start a new process.  At anypoint in time, there will be a max of 10 spare processes.  So the number of apache processes should be a minumum of 8 at all times and a maximum of 10+active.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.