Linux – CPU load on some apache threads is >10%, other threads are 0.2%

apache-2.2high-loadlinux

I have an apache box running a WordPress website.

For some reason it seems some apache threads are using most of the CPU (10%+), and the remainder little (0.1~).

The box is a dual CPU, Intel(R) Xeon(R) CPU E5620 @ 2.40GHz (which each CPU has 4 cores, and 8 threads).

What is the reason the threads are shown like this, should they not be equal CPU per user?

Is there any set of apache optimizations to help reduce load (CentOS, base apache2 install with PHP and MySQL)?

prefork and worker MPM settings are default below

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker.c>
StartServers         4
MaxClients         300
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

high load

Best Answer

For some reason it seems some apache threads are using most of the CPU (10%+), and the remainder little (0.1~).

What you need to take more notice of here is your actual activity. In the snapshot you have provided, the number of running tasks is 7, with a load of 4.

So, at this point in time the number of people needing serving was 7 (probably -- I can only see 6 attributed to httpd though). The remainder are sleeping processes that wont wake up unless some event happens.

The reason you have a high percentage of CPU on some processes are a lower on the other is because only so many of them have something to do within the given second period measured in top.

Is there any set of apache optimizations to help reduce load?

Well, your load probably hovers around 3 to 4 because half the running processes you have probably dont complete within 5 seconds (load is measured internally every five seconds).

  1. There is too many active apache processes there. What are your prefork settings? Try setting it to something more feasible. A max of 72 might be a reasonable start and tune from there. Even if you could serve everyone with that number of processes you'll cause all processes to slow down in equal proportion and load to go up in line with the number of people being served. Better to serve up what you can quickly and reject what you can't serve than serve everyone very slowly.

  2. I get the feeling that some parts of your wordpress page are computationally expensive. Try caching some of this more expensive content.