25 Apache Performance Tips
www.monitis.com
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
1. Remove unused modules
Save memory by not loading modules that aren’t needed,
including (but not limited to)…
… mod_php,
… mod_ruby,
… mod_perl,
etc.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
2. Use mod_disk_cache and NOT
mod_mem_cache
Mod_mem_cachewill not share its cache amongst different
apache processes, which results in high memory usage with
little performance gain. On an active server mod_mem_cache
will rarely serve the same page twice in the same Apache
process.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
3. Configure mod_disk_cache with a
flat hierarchy
Make sure you are using CacheDirLength=2and
CacheDirLevels=1to ensure htcachecleanwill not take forever
when cleaning up your cache directory.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
4. Setup appropriate Expires, Etag,
and Chache-Control headers
In order to utilize your cache you have to specify when a file
expires, otherwise your client will not experience the caching
benefits.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
5. Put the cache on a separate disk
Move your cache to a separate physical disk for the fastest
access without slowing down other processes.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
6. Use piped logging instead of
direct logging
Directly logging to a file results in issues when rotating the log
file. A restart will be necessary to use the next log file. This
causes significant slowness for you users during the restart.
Particularly if you are using Passenger or some other app
loader.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
7. Log to a different disk than the
disk serving pages
Put your logs on physically different disks than the files you
are serving.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
8. Utilize mod_gzip/mod_deflate
Gzip your content before sending it off. The client will ungzip
upon receipt which will minimize the size of file transfers. Also,
it will generally improve the user experience.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
9. Turn off HostnameLookups
Stop doing effortful DNS lookups. You will rarely ever need
them and when you do, you can always look them up when
really needed.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
10. Avoid using hostname in configs
If HostnameLookups are turned off, it will keep you from
waiting for the DNS resolving the hostnames in your configs.
Instead, use IP addresses.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
11. Use persistent connections
Set KeepAlive, KeepAliveTimeout and KeepAliveRequests.
KeepAliveTimeout defines how long Apache will wait for the
next request, and KeepAliveRequests defines the maximum
number of requests for a client prior to resetting the
connection. This will prevent the client from having to
reconnect between each request.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
12. Do not set KeepAliveTimeout too
high
If you have more requests than Apache children, settings
which are set too high could exhaust your pool of available
clients.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
13. Disable .htaccess
I.e. AllowOverride None. This will keep Apache from checking
for an .htaccess file upon each request.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
14. Allow symlinks
I.e. Options + FoolowSymLinks – SymLinksIfOwnerMatch.
Otherwise, Apache will make a separate call on each filename
to ensure it is not a symlink.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
15. Set ExtendStatus off
Although very useful, the ExtendStatus will produce several
system calls for each request to gather statistics. It‘s better to
only define a certain time frame in order to benchmark and
keep it turned off the remainder of the time.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
16. Avoid Wildcards in
DirectoryIndex
Use a specific DirectoryIndex, i.e. index.html or index.php, not
index.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
17. Increase Swappiness
Particularly on single site hosts this will increase the
performance. On Linux systems increase
/proc/sys/vm/swappiness to at least 60 if not higher. This will
result in loading as many files as possible into the memory
cache for a quicker access.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
18. Increase Write Buffer Size
Increase your write buffer size for TCP/IP buffers. On Linux
systems increase /proc/sys/net/core/wmem_max and
/proc/sys/net/core/wmem_default. If your pages fit within this
buffer, Apache will complete a process in just one call to the
TCP/IP buffer.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
19. Increase Max Open Files
If you are handling high loads, increase the number of
allowed open files. On Linux increase /proc/sys/fs/file-max
and run ulimit –H –n 4096.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
20. Setup a frontend proxy for
images and stylesheets
Allow your main web servers to process the application while
images and stylesheets are served from frontend webservers.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
21. Use mod_passenger for rails
Mod_passenger is able to share memory and resources
amongst several processes, allowing for faster spawning of
new application instances. It will also monitor these
processes and remove them when they become unncessary.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
23. Don‘t use threaded mpm with
mod_php
Look at using mod_itk, mod_php tends to segfault with
threaded mpm.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
24. Flush buffers early for pre-
render
It takes a relatively long time to create a webpage on the
backend. Flush your buffer prior to page completion to send
a partial page to the client, so it can start rendering. A good
place to do this is right after the HEAD section – so that the
browser can start fetching other objects.
25 Apache Performance Tuning Tipswww.monitis.com Uptime & Device Monitoring
25. Use a cache for frequently
accessed data
Memcached is a great for frequently used data and sessions. It
will speed up your Apache render time as databases are
slow.
facebook.com/Monitis.Monitoring
@Monitis
The All-in-One Monitoring Solution
Start your free 15-day trial for
free!
www.monitis.com

25 Apache Performance Tips

  • 1.
    25 Apache PerformanceTips www.monitis.com
  • 2.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 1. Remove unused modules Save memory by not loading modules that aren’t needed, including (but not limited to)… … mod_php, … mod_ruby, … mod_perl, etc.
  • 3.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 2. Use mod_disk_cache and NOT mod_mem_cache Mod_mem_cachewill not share its cache amongst different apache processes, which results in high memory usage with little performance gain. On an active server mod_mem_cache will rarely serve the same page twice in the same Apache process.
  • 4.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 3. Configure mod_disk_cache with a flat hierarchy Make sure you are using CacheDirLength=2and CacheDirLevels=1to ensure htcachecleanwill not take forever when cleaning up your cache directory.
  • 5.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 4. Setup appropriate Expires, Etag, and Chache-Control headers In order to utilize your cache you have to specify when a file expires, otherwise your client will not experience the caching benefits.
  • 6.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 5. Put the cache on a separate disk Move your cache to a separate physical disk for the fastest access without slowing down other processes.
  • 7.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 6. Use piped logging instead of direct logging Directly logging to a file results in issues when rotating the log file. A restart will be necessary to use the next log file. This causes significant slowness for you users during the restart. Particularly if you are using Passenger or some other app loader.
  • 8.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 7. Log to a different disk than the disk serving pages Put your logs on physically different disks than the files you are serving.
  • 9.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 8. Utilize mod_gzip/mod_deflate Gzip your content before sending it off. The client will ungzip upon receipt which will minimize the size of file transfers. Also, it will generally improve the user experience.
  • 10.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 9. Turn off HostnameLookups Stop doing effortful DNS lookups. You will rarely ever need them and when you do, you can always look them up when really needed.
  • 11.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 10. Avoid using hostname in configs If HostnameLookups are turned off, it will keep you from waiting for the DNS resolving the hostnames in your configs. Instead, use IP addresses.
  • 12.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 11. Use persistent connections Set KeepAlive, KeepAliveTimeout and KeepAliveRequests. KeepAliveTimeout defines how long Apache will wait for the next request, and KeepAliveRequests defines the maximum number of requests for a client prior to resetting the connection. This will prevent the client from having to reconnect between each request.
  • 13.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 12. Do not set KeepAliveTimeout too high If you have more requests than Apache children, settings which are set too high could exhaust your pool of available clients.
  • 14.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 13. Disable .htaccess I.e. AllowOverride None. This will keep Apache from checking for an .htaccess file upon each request.
  • 15.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 14. Allow symlinks I.e. Options + FoolowSymLinks – SymLinksIfOwnerMatch. Otherwise, Apache will make a separate call on each filename to ensure it is not a symlink.
  • 16.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 15. Set ExtendStatus off Although very useful, the ExtendStatus will produce several system calls for each request to gather statistics. It‘s better to only define a certain time frame in order to benchmark and keep it turned off the remainder of the time.
  • 17.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 16. Avoid Wildcards in DirectoryIndex Use a specific DirectoryIndex, i.e. index.html or index.php, not index.
  • 18.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 17. Increase Swappiness Particularly on single site hosts this will increase the performance. On Linux systems increase /proc/sys/vm/swappiness to at least 60 if not higher. This will result in loading as many files as possible into the memory cache for a quicker access.
  • 19.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 18. Increase Write Buffer Size Increase your write buffer size for TCP/IP buffers. On Linux systems increase /proc/sys/net/core/wmem_max and /proc/sys/net/core/wmem_default. If your pages fit within this buffer, Apache will complete a process in just one call to the TCP/IP buffer.
  • 20.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 19. Increase Max Open Files If you are handling high loads, increase the number of allowed open files. On Linux increase /proc/sys/fs/file-max and run ulimit –H –n 4096.
  • 21.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 20. Setup a frontend proxy for images and stylesheets Allow your main web servers to process the application while images and stylesheets are served from frontend webservers.
  • 22.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 21. Use mod_passenger for rails Mod_passenger is able to share memory and resources amongst several processes, allowing for faster spawning of new application instances. It will also monitor these processes and remove them when they become unncessary.
  • 23.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 23. Don‘t use threaded mpm with mod_php Look at using mod_itk, mod_php tends to segfault with threaded mpm.
  • 24.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 24. Flush buffers early for pre- render It takes a relatively long time to create a webpage on the backend. Flush your buffer prior to page completion to send a partial page to the client, so it can start rendering. A good place to do this is right after the HEAD section – so that the browser can start fetching other objects.
  • 25.
    25 Apache PerformanceTuning Tipswww.monitis.com Uptime & Device Monitoring 25. Use a cache for frequently accessed data Memcached is a great for frequently used data and sessions. It will speed up your Apache render time as databases are slow.
  • 26.
    facebook.com/Monitis.Monitoring @Monitis The All-in-One MonitoringSolution Start your free 15-day trial for free! www.monitis.com