Received Sat, 29 Nov 2008 17:41:42 PHT
Mod_cache on apache2.2: Server performance improvement with mod_cache - A simple howto configuration of mod_cache.conf
My system: openSUSE 11.0 x86_64 with apache2.2. The configuration also works on previous openSUSE versions - I also run mod_cache successfully on SuSE 10.1.
The purpose and idea of adding the simple mod_cache to your apache2 is twofold:
- serve the most common repeated file requests directly our of your RAM memory to reduce file access time and hence page load time and also to reduce wear and tear of your hard drive by reducing the number if drive access instances.
- reduce mysql use by converting most frequently downloaded dynamic pages into static cache pages. If you have plenty of RAM, then you may cache dynamic pages also in your RAM. If your entire system is high traffic dynamic only, then you may upgrade RAM to dozens of GB or more to speed up your system.
Mod_cache step by step howto
Typically mod_cache is part of the apache2.2 core package. Hence mod_cache should be on your system but needs to be loaded and configured. If for any reason mod_cache is missing, install the below modules using YAST or your preferred system manager:
- cache
- mem_cache
- mod_disk_cache
1. create a new file in /etc/apache2/conf.d/mod_cache.conf
vi /etc/apache2/conf.d/mod_cache.conf
Now add the below 2 configuration modules to that file. Change path names as needed to comply with your own system. You see that I cache my 2 dynamic site sections on with mod_disk_cache - my blog and my gallery2. All else is cached in my RAM. For the moment I don't have enough RAM memory to cache all in memory. This setup works perfectly for me. After the mod_cache was installed on my system, I typically have more free memory than before without mod_cache. Why ? Because apparently mod_cache works more efficiently in caching content than the Linux system / kernel does by default. The overall load is reduced, performance substantially improved - hence the apache2 plus mod_cache does its job to improve system performance.
<IfModule mod_cache.c>
<IfModule mod_disk_cache.c>
CacheRoot /tmp/cacheroot
CacheEnable disk /path_to_my/dynamic_gallery
CacheEnable disk /path_to_my_dynamic_blog
CacheMaxFileSize 512000
CacheDirLevels 5
CacheDirLength 1
</IfModule>
<IfModule mod_mem_cache.c>
CacheEnable mem /
MCacheSize 4096
MCacheMaxObjectCount 100
MCacheMinObjectSize 1
MCacheMaxObjectSize 2048
</IfModule>
</IfModule>
2. Add the modules to be loaded to your /etc/sysconfig/apache2
vi /etc/sysconfig/apache2
Add to /etc/sysconfig/apache2 the below 3 module short names to get all 3 required modules loaded:
cache mem_cache mod_disk_cache
Above 3 module names belong into the APACHE_MODULES - section of /etc/sysconfig/apache2.
APACHE_MODULES="cache mem_cache mod_disk_cache actions alias ...
3. Test your apache2 configuration !
rcapache2 extreme-configtest
If any other output but OK, then you get a precise error description with configuration file and line where you have an error. extreme-configtest - errors are self explaining and thus easy to solve. There should be NO error unless you had one before starting this modification or your system is different from original openSUSE !!
Restart your Apache server
If above configtest OK, then either reload your new apache configuration or restart your apache server:
rcapache2 reload
or
rcapache2 restart
Then use top to monitor your server performance.
You also may refer to original resource on Apache.org website for the Caching Guide documentation.
God bless
hans






