Friday, February 20, 2009

Apache Http server Cache

I did some investigation on our web server after looking at the Content Caching mechanism.
there are several thing to confirm:
1. using Gzip or not?
2. What kind of files should we cache?
3. Which Cache method should i choose?
4. What kind of configurations to each Cache method?

Testing preparation: prepare one simple web page and Jmeter as load generating tool


Disk cache config:

IfModule mod_cache.c
IfModule mod_disk_cache.c
CacheRoot c:/cacheroot
CacheEnable disk /
CacheDirLevels 3
CacheDirLength 2
/IfModule
/IfModule

Mem cache config:
IfModule mod_cache.c
IfModule mod_disk_cache.c
CacheDefaultExpire 86400
CacheEnable mem /
MCacheSize 100000
MCacheMaxObjectCount 10000
MCacheMinObjectSize 100
MCacheMaxObjectSize 6400000
MCacheRemovalAlgorithm LRU
/IfModule
/IfModule

we just want to cache some static files on web server, like .js,.css and some images, which are not modified often.

First, we confirm to use Gzip to improve our web site performance(even if there is some bugs on it). If only apply Cache on Apache http server, the response time is not good if you have a few large static file to load...

Disable Gzip:
1> with Mod_mem_cache: 4160ms in average response time
2> with Mod_disk_cache: 4185ms in average response time

Enable Gzip without any Apache cache:
3> 2885ms in average response time, however, the CPU% is almost 90% with highest Gzip level(Level 9)

Note: To enable Gzip, add Accept-Encoding: gzip,deflate into JMeter header manager;


So I intent to use both Apache cache and Gzip to see any great improvement on response time and CPU% on web server.

But,finding that we using Mod_mem_cache, while Gzip can not be effected... do not know why
For Mod_disk_cache, it can be living with Gzip, and more important, it will reduce CPU% of apache server! that is great!
So, it might do a pre-Gzip job first, then cache it into the cache root directive, here is the result data for your reference:

Enable Gzip:
1> with Mod_disk_cache: 2793ms in average response time
CPU%=15%
if you want to see if Mod_disk_cache works or not, one way is to look at the cache root directive folder, if there is some strange files created after or during testing, then it works!

for Mod_disk_cache configration: you have to adjust these two interesting items:
CacheDirLevels
CacheDirLength
because different combination can give different numbers, more info please see http://httpd.apache.org/docs/2.2/mod/mod_disk_cache.html

one reminder, htcacheclean is used to keep the size of mod_disk_cache's storage within a certain limit.
you can use cmd command line to run it as a daemon mode:
C:/AppServ/Apache2.2/bin/htcacheclean -t -i -d30 -pD:/cacheroot -l1M
or
create a .bat then add a schedule task:
C:/AppServ/Apache2.2/bin/htcacheclean -t -n -v -pD:/cacheroot -l1M

In one word: we want to enable mod_disk_cache+Gzip on apache http server, currently :)

No comments:

Post a Comment