How to solve high CPU load by apache? (ubuntu+ec2)

40,868

Solution 1

I solved the problem by installing Apache mod Status - http://httpd.apache.org/docs/2.0/mod/mod_status.html. There you can see each PID on what URL is used.

Hope it helps anybody...

Solution 2

One way of looking at what it's doing is to use lsof ( you may have to install it ). To see what the processes in your example are accessing you would do this:

lsof -p 11121,10108,11122,10111

This will show you all of the files that process has open. Usually a high cpu on the apache process is due to something the website is trying to do server side.

Solution 3

You can use strace on the parent process to get a better idea of what its doing.

Share:
40,868
Tiago Gouvêa
Author by

Tiago Gouvêa

Just a web developer.

Updated on July 16, 2022

Comments

  • Tiago Gouvêa
    Tiago Gouvêa almost 2 years

    I'm setup a instance in Amazon EC2, a ubuntu 10.04 server running apache2, php5 and mysql.

    With less than 10 users using the system the server gets 20%, 30%, 40% of CPU load.

    Using top I see in the firsts lines:

    11121 www-data 20 0 71940 20m 11m S | 22.6 | 1.2 | 0:00.68 apache2
    10108 www-data 20 0 72196 22m 12m S | 21.9 | 1.3 | 1:15.81 apache2
    11122 www-data 20 0 71936 20m 11m S | 7.3 | 1.2 | 0:00.68 apache2
    10111 www-data 20 0 72196 22m 12m S | 1.7 | 1.3 | 1:16.43 apache2

    The CPU sum in this 4 lines are 53,5.

    How can I see more detailed the processes?
    How can I take a look into scripts running, the times it takes, the amont of processor each one consumes?

    Thanks.

  • Tiago Gouvêa
    Tiago Gouvêa over 13 years
    Ok.. I use it.. but I want to know more about the apache process. Not only "how" it process, but what. What script are running now? How much time each script are speending from my CPU?