Apache is consuming all my CPU

il15

Verified User
Joined
Sep 2, 2010
Messages
11
Hello, I'm always having a high load average and when I tried to see what happend, Apache is the problem.

I have installed a wordpress blog in the server.

this is ps aux:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 10348 744 ? Ss Nov22 0:01 init [3]
apache 1399 10.3 1.3 124596 39976 ? S 12:03 0:10 /usr/sbin/httpd -k start -DSSL
dovecot 1435 0.0 0.0 38188 2332 ? S Nov23 0:00 pop3-login
dovecot 1472 0.0 0.0 38188 2328 ? S Nov23 0:00 pop3-login
nobody 3158 0.0 0.0 48712 752 ? S 12:03 0:00 /usr/local/directadmin/directadmin d
nobody 3184 0.0 0.0 48712 752 ? S 12:03 0:00 /usr/local/directadmin/directadmin d
nobody 3206 0.0 0.0 48712 752 ? S 12:03 0:00 /usr/local/directadmin/directadmin d
apache 3804 8.6 0.9 114972 30416 ? S 12:03 0:05 /usr/sbin/httpd -k start -DSSL
apache 3831 7.6 1.0 115472 30840 ? R 12:03 0:04 /usr/sbin/httpd -k start -DSSL
nobody 3994 0.0 0.0 48712 1516 ? Ss 11:51 0:00 /usr/local/directadmin/directadmin d
dovecot 4037 0.0 0.0 38204 2336 ? S Nov23 0:00 imap-login
ftp 5279 0.0 0.0 8800 940 ? Ss 11:51 0:00 proftpd: (accepting connections)
dovecot 5389 0.0 0.0 38204 2332 ? S Nov23 0:00 imap-login
apache 5565 8.9 1.2 122280 37372 ? R 12:03 0:04 /usr/sbin/httpd -k start -DSSL
dovecot 5854 0.0 0.0 38204 2340 ? S Nov23 0:00 imap-login
dovecot 5858 0.0 0.0 38204 2332 ? S Nov23 0:00 imap-login
apache 8118 17.3 1.3 124860 40232 ? S 12:04 0:02 /usr/sbin/httpd -k start -DSSL
apache 8119 3.9 0.9 115472 30564 ? S 12:04 0:00 /usr/sbin/httpd -k start -DSSL
apache 8122 11.8 1.0 116584 31952 ? S 12:04 0:01 /usr/sbin/httpd -k start -DSSL
root 8139 10.8 1.8 148452 58016 ? Ss 12:04 0:01 /usr/bin/spamd -d -c -m 5
dovecot 9322 0.0 0.0 38204 2336 ? S 11:51 0:00 imap-login
root 9323 0.0 1.8 148452 55752 ? S 12:04 0:00 spamd child
root 9324 0.0 1.8 148452 55656 ? S 12:04 0:00 spamd child
root 9572 0.0 0.1 86064 3420 ? Rs 12:00 0:00 sshd: root@pts/0
apache 9573 10.4 1.2 123112 38544 ? S 12:00 0:25 /usr/sbin/httpd -k start -DSSL
root 9717 0.0 0.0 10724 972 pts/0 R+ 12:04 0:00 ps aux
apache 9975 10.2 1.0 115780 31180 ? S 12:00 0:23 /usr/sbin/httpd -k start -DSSL
apache 9977 9.2 1.2 124080 39508 ? S 12:00 0:21 /usr/sbin/httpd -k start -DSSL
dovecot 12263 0.0 0.0 38188 2332 ? S 11:48 0:00 pop3-login
dovecot 13480 0.0 0.0 38204 2332 ? S 09:13 0:00 imap-login
dovecot 13543 0.0 0.0 38204 2564 ? S 09:13 0:00 imap-login
root 15369 0.0 0.0 12064 1632 pts/0 Ss 12:01 0:00 /bin/bash
dovecot 15910 0.0 0.0 38188 2328 ? S 11:56 0:00 pop3-login
dovecot 16003 0.0 0.0 38204 2336 ? S 07:42 0:00 imap-login
root 16291 0.0 0.0 12604 672 ? S<s Nov22 0:00 /sbin/udevd -d
dovecot 17669 0.0 0.0 38204 2564 ? S Nov23 0:00 imap-login
root 17794 0.0 0.0 5908 604 ? Ss Nov22 0:00 syslogd -m 0
root 17808 0.0 0.0 10460 848 ? Ss Nov22 0:00 dovecot
root 17809 0.0 0.0 15456 1652 ? S Nov22 0:00 dovecot-auth
root 17821 0.0 0.0 62624 1212 ? Ss Nov22 0:00 /usr/sbin/sshd
root 17833 0.0 0.0 21644 904 ? Ss Nov22 0:00 xinetd -stayalive -pidfile /var/run/xinetd.pid
root 17847 0.0 0.0 11928 1396 ? S Nov22 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql
mysql 17885 7.7 1.5 368464 47496 ? Sl Nov22 199:05 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql
dovecot 17929 0.0 0.0 38188 2328 ? S Nov22 0:00 pop3-login
dovecot 17930 0.0 0.0 38188 2332 ? S Nov22 0:00 pop3-login
dovecot 17931 0.0 0.0 38188 2332 ? S Nov22 0:00 pop3-login
dovecot 17932 0.0 0.0 38188 2332 ? S Nov22 0:00 pop3-login
dovecot 17933 0.0 0.0 38188 2332 ? S Nov22 0:00 pop3-login
dovecot 17934 0.0 0.0 38188 2332 ? S Nov22 0:00 pop3-login
dovecot 17935 0.0 0.0 38188 2332 ? S Nov22 0:00 pop3-login
dovecot 17936 0.0 0.0 38188 2332 ? S Nov22 0:00 pop3-login
dovecot 17937 0.0 0.0 38188 2332 ? S Nov22 0:00 pop3-login
dovecot 17939 0.0 0.0 38188 2328 ? S Nov22 0:00 pop3-login
root 18056 0.0 0.0 20876 1172 ? Ss Nov22 0:00 crond
root 18068 0.0 0.0 46744 820 ? Ss Nov22 0:00 /usr/sbin/saslauthd -m /var/run/saslauthd -a pam -n 2
root 18070 0.0 0.0 46744 552 ? S Nov22 0:00 /usr/sbin/saslauthd -m /var/run/saslauthd -a pam -n 2
apache 23796 10.4 1.0 116108 31528 ? S 11:57 0:43 /usr/sbin/httpd -k start -DSSL
root 25816 0.0 0.2 93292 8124 ? Ss 00:13 0:01 /usr/sbin/httpd -k start -DSSL
apache 27777 10.7 1.0 115780 31200 ? S 12:01 0:18 /usr/sbin/httpd -k start -DSSL

Please can you help me? I don't know what to do...
 
its using 10% what is the problem?

Enable extended status if you wanna see the requests
 
10% is only the first line, if you continue with all lines Apache are consuming 90%
 
please can you be more specific, i'm new with all these things
 
I already have a SuperCache Running in wordpress.

Please can you help me apache's configs? What should I do?
 
Do you have SSH access? Are you an experienced with SSH user?

As described in the topic, the link to which I've already posted, try to lower ServerLimit and MaxClients. See and tune /etc/httpd/conf/extra/httpd-mpm.conf

Additional, you may want to set extra limits on number of processes/connections to Dovecot (login_processes_count) and Exim, set limits to PHP.INI (memory_limit).
 
I have this file (What are the good numbers for maxclients and servet limit? Do I have to change the number all the times that server limit or maxclients appear?:


# 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
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 450
MaxClients 450
MaxRequestsPerChild 10000
</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 mpm_worker_module>
StartServers 2
ServerLimit 450
MaxClients 450
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 10000
</IfModule>

# BeOS MPM
# StartThreads: how many threads do we initially spawn?
# MaxClients: max number of threads we can have (1 thread == 1 client)
# MaxRequestsPerThread: maximum number of requests each thread will process
<IfModule mpm_beos_module>
StartThreads 10
MaxClients 50
MaxRequestsPerThread 10000
</IfModule>

# NetWare MPM
# ThreadStackSize: Stack size allocated for each worker thread
# StartThreads: Number of worker threads launched at server startup
# MinSpareThreads: Minimum number of idle threads, to handle request spikes
# MaxSpareThreads: Maximum number of idle threads
# MaxThreads: Maximum number of worker threads alive at the same time
# MaxRequestsPerChild: Maximum number of requests a thread serves. It is
# recommended that the default value of 0 be set for this
# directive on NetWare. This will allow the thread to
# continue to service requests indefinitely.
<IfModule mpm_netware_module>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 1000
MaxRequestsPerChild 10000
MaxMemFree 100
</IfModule>

# OS/2 MPM
# StartServers: Number of server processes to maintain
# MinSpareThreads: Minimum number of idle threads per process,
# to handle request spikes
# MaxSpareThreads: Maximum number of idle threads per process
# MaxRequestsPerChild: Maximum number of connections per server process
<IfModule mpm_mpmt_os2_module>
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxRequestsPerChild 10000
</IfModule>
 
It's very hard to say, what number do you need...
I've got next (do not set it so low):

Code:
<IfModule mpm_prefork_module>
    StartServers          6
    MinSpareServers       6
    MaxSpareServers       10
    ServerLimit           21
    MaxClients            21
    MaxRequestsPerChild   100
</IfModule>

They've been chosen experimentally (numbers should be even lower, cause they depend on CPU's core quantity). But I have a frontend before apache, and in your case this will be too little.

Change ServerLimit to 150 and watch the server and logs...
 
I have change the numbers with the ones you gave me, but the server still with a high load average.

What can i do?

This is my server:

rocessor Name Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz
Vendor ID GenuineIntel
Processor Speed (MHz) 2005.038
Processor Name Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz
Vendor ID GenuineIntel
Processor Speed (MHz) 2005.038
Processor Name Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz
Vendor ID GenuineIntel
Processor Speed (MHz) 2005.038
Processor Name Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz
Vendor ID GenuineIntel
Processor Speed (MHz) 2005.038
Total Memory 3072000 kB
Free Memory 2261132 kB
 
Did you restart apache? Will you post top's ouput here?
It's very hard to recommend anything without having a full picture.
 
And what pages/scripts are requested? httpd-status?
The limits of apache will not help in all cases. Exaime, what do the requested scripts do? MySQL slow logs?
 
See the output of httd status. Find PHP/Perl scripts, which are requested mostly.
Open them in your favourite text editor and learn, what it does.

To see mysql slow log you should enable it /etc/my.cnf
 
I add to my.cnf:

log-slow-queries=/var/log/mysql-slow-queries.log
long_query_time = 1
log-queries-not-using-indexes

and also i created the mysql-slow-queries.log, I restarted the mysql server and still not working....
 
Last edited:
# chown mysql:mysql /var/log/mysql-slow-queries.log
# chmod 640 /var/log/mysql-slow-queries.log

I do that, but after restart mysql I get this:

mysqladmin var -uestudio -p968143458 |grep log_slow
| log_slow_queries | OFF
 
What is your mysql version?
Check /var/lib/mysql/<hostname>.err log for any errors.

Is apache still making troubles for you?
 
Back
Top