Tuning performance of Apache Server

Apache is the most popular and widely used web server.  Apache allows us to run web applications with minimal configuration and easy administration. However for highly data driven applications Apache may go slow, sometimes really very slow. So in this post we are going to see how we can tune the performance of Apache by simply following above listed suggestions:
1. Removing almost all unused modules/ not required modules : Save memory by not loading modules that you do not need, including but not limited to mod_php, mod_ruby, mod_perl, etc.
2. Using mod_disk_cache NOT mod_mem_cache : mod_mem_cache will not share its cache amongst different Apache processes, which results in high memory usage with little performance gain since on an active server, mod_mem_cache will rarely serve the same page twice in the same Apache process.
3. Setup appropriate Expires, Etag, and Cache-Control Headers : to utilize your cache, you must tell it when a file expires, otherwise your client will not experience the caching benefits.
4. Using Piped Logging instead of direct logging : Directly logging to a file has issues when you want to rotate the log file. It must restart Apache to use the next log file.  This will cause significant slowness for your users during the restart. Particularly if you are using Passenger or some other app loader.
5. Using seperate Disk for logging : Put your logs on physically different disks than the files you are serving. This will reduce disk read overhead when logs need to be access for various purposes.
6. Make use of mod_gzip / mod_deflate : Gzip / Compress your content before sending it off and then the client will ungzip / decompress upon receipt,  this will minimize the size of file transfers, it generally will help all user experience.
7. Turning off Hostname Lookups : Stop doing expensive DNS lookups.
8. Avoiding use of  hostname in configs : If you have Hostname Lookups off, this will prevent you from having to wait for the DNS resolve of the hostnames
in your configs, use IP addresses instead.
9. Using  Persistent Connections : Set KeepAlive On and then set KeepAliveTimeout and KeepAliveRequests.  KeepAliveTimeout is how long Apache will wait for the next request, and KeepAliveRequests is the max number of requests for a client prior to resetting the connection. This will prevent the client from having to reconnect between each request.
10. Setting ExtendedStatus Off.
11. Avoiding Wildcards in DirectoryIndex : Use a specific DirectoryIndex, i.e. index.html or index.php, not index.
12. Increasing 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 one call to the tcp/ip buffer. This will help a lot.
13. Increasing 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.
14. Turning off  the safe_mode for php : It will utilize about 50-70% of your script time checking against these safe directives. Instead configure open_basedir properly and utilize plugins such as mod_itk.
15. Flushing buffers early for pre-render : It takes a relatively long time to create a web page on the back end, 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.

Comments

Popular posts from this blog

MATLAB code for Circular Convolution using Matrix method

Positive number pipe in angular 2+