Apache Tuning

In these days, I managed some server. When I monited the web performance, I feel the web response is very slow, even it is no response. So I try to tun the performance for Apache.

Include the mpm worker module

Apache 2.0 improved the performance and added many new functions than Apache 1.3. In my tuning, I add the mpm_worker for Apache 2. It is very important to add the --with-mpm=worker attribute.

steven $ ./configure --prefix=/usr/local/httpd --enable-isapi --enable-file-cache --enable-echo --disable-charset-lite --enable-charset-lite --enable-cache --enable-disk-cache --enable-mem-cache --enable-example --enable-case-filter --enable-case-filter-in --enable-dumpio --enable-auth-ldap --enable-ext-filter --enable-deflate --enable-log-forensic --enable-logio --enable-mime-magic --enable-headers --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-ssl --enable-optional-hook-export --enable-optional-hook-import --enable-optional-fn-import --enable-http --enable-cgi --enable-cgid --enable-speling --enable-rewrite --enable-so --with-suexec-uidmin --with-suexec-gidmin --with-suexec-logfile --with-suexec-safepath --enable-static-htpasswd --enable-static-htdigest --enable-static-rotatelogs --enable-static-logresolve --with-mpm=worker

Make your machine to work hard.

A high class hardware, you must tun it to have high performance. In the talbe, the configuration can allow 5,000 connections in a time.

root # vi /usr/local/httpd/conf/extra/httpd-mpm.conf
-------------------------------------------------------
<IfModule mpm_worker_module>
StartServers 3
MaxClients 5000
ServerLimit 50
MinSpareThreads 50
MaxSpareThreads 200
ThreadLimit 200
ThreadsPerChild 100
MaxRequestsPerChild 200
</IfModule>
-------------------------------------------------------
root #

廣 告

The tips for mpm worker, you can read the Apache Document for more information.

Do not wait!

Of course, I recommend you cna turn off the DNS resolving function, adjust the MaxKeepAliveRequests value up, and set the Timeout value down.

root # vi /usr/local/httpd/conf/extra/httpd-default.conf
-------------------------------------------------------
# Set the timeout in 60 seconds.
Timeout 60
# Turn on the KeepAlive
KeepAlive On
MaxKeepAliveRequests 5000
KeepAliveTimeout 3
# Turn off the DNS resolve
HostnameLookups Off
-------------------------------------------------------
root #

In my case, these servers are serving the education and government units, so the network is not in my consider. The important thing is how do I make the servers can serve more connections at one time. So, in this articale, I won't discuss the network bandwidth.

Come closer your CPU

If your Linux box is supporting a service, you can try to turn the nice value to high. I think the hardware resources must set to Apache if the box is only serving a service.
You can tun the nice value from -20 to +19. If you do not adjust the nice value, It will set to 0 in default.

Setting the nice value to -10 when at start apache.

root # nice -10 /usr/local/httpd/bin/apachectl start &

If Apache is running, use renice command to re-set the nice value.
Find the apache's PID and re-set the nice value.

root # netstat -ntulp | grep httpd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19249/httpd
root # renice -10 19249


You can use top and find the nice value in NI field.

Turn off the unnecessary services

Turn off the unnecessary services to release more resources. Most system installers will install full packages when installation time. We can control which services to start at booting.
If you have Fedora/Redhat Linux OS, you can use chkconfig to show which services that start at boot time.

root $ chkconfig --list
~ Ignore ~
rawdevices 0:off 1:off 2:off 3:off 4:on 5:on 6:off
acpid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
ipchains 0:off 1:off 2:on 3:off 4:on 5:on 6:off
iptables 0:off 1:off 2:on 3:off 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
anacron 0:off 1:off 2:on 3:off 4:off 5:off 6:off
lpd 0:off 1:off 2:on 3:off 4:on 5:off 6:off
xfs 0:off 1:off 2:on 3:off 4:on 5:on 6:off
ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
portmap 0:off 1:off 2:off 3:off 4:on 5:on 6:off
xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
autofs 0:off 1:off 2:off 3:off 4:on 5:on 6:off
nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
nfslock 0:off 1:off 2:off 3:off 4:on 5:off 6:off
identd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
~ Ignore ~
root #

If your Linux box is only serving the web service. In recommend is turn off other unnecessary services, especially the SQL service.

Do not start MySQL service at booting time.

root # chkconfig mysqld off

If MySQL is running, and you want to turn off it.

root # service mysqld stop
OR
root # /etc/init.d/mysqld stop

Reference

This articale is my note that in this case. There are many focus that I have not discuss. If you have any ideas about tuning apache, you can send a mail to me, and welcome to point my warning.

Lists in Reference:

01/20/2007


Home Page