Project

General

Profile

Actions

Docs ModMemCache » History » Revision 20

« Previous | Revision 20/24 (diff) | Next »
phsource, 2009-02-15 19:48
Added link to Google Groups resource for newer mod_mem_cache patches


mod_mem_cache

Module: mod_mem_cache

Description

Serving several thousands small files for lighttpd is quite challenging. Operating System has to do a lot of random access, which increase io-wait. mod_mem_cache is the plugin which stores content of files in memory for faster serving. It's more configurable than OS buffers (at least, linux buffers), in some cases yields better performance.

For example, you can configure it to cache files smaller than 5 kb, just cache files with a specific mime type or different strategies to free memory when the configured limit has been reached.

Installation

This module is a 3rd party module, is not included in the official distribution. You need to download it from here:
For lighttpd 1.4.13: [http://blog.quehy.com/tag/mod_mem_cache mod_mem_cache]
For lighttpd 1.4.15: [http://bergstroem.nu/lighttpd-1.4.15.mod_mem_cache.v1.2.patch] (unsupported, straight port from 1.4.13 patch)
For lighttpd 1.4.19: [http://blog.quehy.com/archives/197.html], Patch File for Freebsd Ports [http://trac.lighttpd.net/trac/attachment/wiki/Docs/ModMemCache/patch-mod_mem_cache.patch]
For lighttpd 1.4.xx and svn: [http://foobar.nerdbase.de/lighty/lighttpd-1.4.x-svn-mod_mem_cache.patch] (works with mod_magnet too, kudoz quehy!)
For lighttpd 1.5.x: [http://groups.google.com/group/mod_cache/files], patches for non-stable versions

Important
mod_mem_cache and mod_cml (--with-lua) do not play nicely together since mod_mem_cache modifies how lighttpd handles cachable items. There probably won't be a patch for this since mod_cml_lua is deprecated.

Options

See [http://blog.quehy.com/archives/171.html]

mem-cache.filetypes
   content-type arrays which want to put into memory.

mem-cache.filetypes=("text/css")
   Default: not set, cache all files

mem-cache.enable
   enable or disable mod_mem_cache.

mem-cache.enable = "disable" 
    $HTTP["host"] == "images.example.org" {
      mem-cache.enable = "enable" 
    }

   Default: enable

mem-cache.max-memory
    maxium memory in Mbytes mod-mem-cache can use.

    Default: 512 (means 512 ''Megabytes'').

mem-cache.max-file-size
    maxium file size in Kbytes of single file to cache in memory.

    Default: 512 (means 512 ''Kilobytes'').

mem-cache.lru-remove-count
    number of cached memory items to remove when used memory reached maxmemory by LRU algorthim

    Default: 200.

mem-cache.expire-time
    memory cache's expire time in minutes. 

mem-cache.expire-time = 1440 # 1 day

    Default: 0 (means to check file update for every request)

mem-cache.slru-thresold
    Adjusts slru threshold (against hit counter)

    Default: 0 (disabled) 

Example

  • mem-cache.filetypes = ("application/x-javascript", "text/css", "text/html", "text/javascript") # Cache javascript, css, html file in memory
  • mem-cache.max-memory = 1024 # Use 1G memory cache
  • mem-cache.max-file-size = 1024 # Cache maxium 1M-size file

Additional info concerning SLRU balancing

The SLRU has one LRU cache for the probationary segment, one for the protected segment. On the first miss an entry is added to the probationary LRU cache without any data. Only if its hit count increases over threshold it is propagated to the protected LRU cache which has real content. That way you decrease the propability that an entry is kicked out of the LRU cache as you increase the threshold for one entry getting into the cache. In practice, mem-cache.slru-thresold should adjust to archieve higher hit-rate and less memory usage

Updated by phsource almost 16 years ago · 20 revisions