how to enable memory cache

42 views
Skip to first unread message

Yaoxing

unread,
Oct 21, 2009, 3:03:16 PM10/21/09
to mod_cache
Hi all,
I'm new to lighttpd and mod_cache. Here I met some troubles. Could any
one help me?
I have a image server who has 2G memory, without memory cache, vmstat
looks like this:
procs -----------memory---------- ---swap-- -----io---- --system--
-----cpu------
r b swpd free buff cache si so bi bo in cs us
sy id wa st
1 0 112 11016 80104 1638712 0 0 38 61 0 13 0
2 95 3 0
1 1 112 9988 80136 1639872 0 0 872 1144 8126 225 4
8 70 17 0
0 1 112 10300 80160 1639848 0 0 80 6868 3962 102 0
2 74 24 0
0 1 112 9804 80160 1639980 0 0 0 0 1790 161 0
1 75 24 0

As you can see, more then 20% CPU time is spent on waiting for IO. To
speed it up, I used mod_cache. These are what I have done:
1. download lighttpd-1.4.23.modcache.v.1.8.0.tar.gz, and configure
with the following command:
./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/
info --enable-shared --enable-threads=posix --enable-checking=release
--with-system-zlib --enable-lfs --with-openssl --with-mysql --with-
zlib --with-memcache --enable-__cxa_atexit --disable-libunwind-
exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-
c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-
plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-
cpu=generic --host=x86_64-redhat-linux

Then make and install. Everything is successful. Then I modified
lighttpd.conf and append following lines:
cache.enable = "enable"
cache.max-memory-size = 1024
and of course enabled mod_cache at the beginning of lighttpd.conf
server.modules = (
"mod_cache",
"mod_rewrite",
...
However, after all this, vmstat result still looks the same. No memory
is spent caching anything, and no doubt there is a lot of network
traffic. I think I must have missed something. Can anyone help me?
Thank you!

shellcode

unread,
Oct 21, 2009, 9:06:36 PM10/21/09
to mod_...@googlegroups.com
full docs at http://www.linux.com.cn/modcache/

you need to use cache.refresh-pattern to enable memory usage. for example:

cache.refresh-pattern = (
"\.(?i)(jpg|bmp|jpeg|gif|png)$" => "2880 use-memory"
)

yaoxing zhang

unread,
Oct 22, 2009, 5:44:03 AM10/22/09
to mod_...@googlegroups.com
Great. It reduces about 10% CPU usage. Thank you
By the way, I still have another problem. Does lighttpd use only 1 CPU?
Now I can see only 1 CPU is used up to 50%, while other 3 CPUs are
almost not used at all. Is this the way how lighttpd works or should do
anything else for load balance?

Regards,
YX

shellcode

unread,
Oct 22, 2009, 6:46:51 AM10/22/09
to mod_...@googlegroups.com
you can use server.max-worker = 4.

but keep in mind that modcache's memory cache don't share across lighttpd. you got server.max-worker * cache.max-memory-size usage.

for example:
server.max-worker = 4
cache.max-memory-size = 256

4 lighttpd's modcache will eat up to 4 * 256M = 1G memory

yaoxing zhang

unread,
Oct 23, 2009, 4:35:53 AM10/23/09
to mod_...@googlegroups.com
Thank you so much.
About memory cache I still got a question. Now in my lighttpd.conf I got following lines:
.....
server.modules                 = (
        "mod_indexfile",
        "mod_cache",
        "mod_rewrite",
        "mod_access",
        "mod_expire",
        "mod_accesslog",
        "mod_dirlisting",
        "mod_staticfile",
        # 8
    )
....
# for cache module

cache.enable = "enable"
cache.max-memory-size = 1024
cache.refresh-pattern = ("\.(?i)(jpg|jpeg|gif|png)$" => "21600 use-memory")

But after one day's observing, I found that free memory doesn't reduce at all. It seems nothing's cached. This is the vmstat I get:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0    112  10148  81468 1673776    0    0    51   155   12   16  1  4 90  5  0
 0  3    112  10032  81476 1674104    0    0   252     0 4036 1059  1  5 78 16  0
 0  4    112   9608  81496 1674400    0    0   228   404 4217 1583  2  6 78 14  0
 0  3    112  10500  81476 1673464    0    0   476  4776 4079  709  2  4 69 25  0
 0  0    112   9828  81488 1673752    0    0   288     0 4173 1203  2  6 72 20  0


I also tried not to use "use-memory" option, and set a cache.bases for file cache. but still, I found nothing there. It seems mod_cache is not activated. Maybe I'm still missing something?
PS: I'm using the package lighttpd-1.4.23.modcache.v.1.8.0.tar.gz

Regards,
YX

shellcode

unread,
Oct 23, 2009, 5:37:31 AM10/23/09
to mod_...@googlegroups.com
you can read http://blog.quehy.com/archives/216.html, it's explain some cases that modcache don't cache
Reply all
Reply to author
Forward
0 new messages