Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 833
Tiago Gouvêa Avatar asked Dec 27 '10 22:12

Tiago Gouvêa


People also ask

How do I diagnose high CPU utilization on my EC2 Ubuntu instance when my CPU is not being throttled?

Use Task Manager to identify the source of high CPU utilization. Connect to your instance using Remote Desktop Protocol (RDP). Open Task Manager, and then select the CPU column to sort by CPU. Research any processes with high CPU utilization to determine whether they are using the expected amount of CPU.


3 Answers

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...

like image 148
Softy Avatar answered Nov 06 '22 03:11

Softy


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.

like image 45
Jason Janelle Avatar answered Nov 06 '22 05:11

Jason Janelle


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

like image 2
Kyle Buser Avatar answered Nov 06 '22 05:11

Kyle Buser