mod_mem_cache¶
模块: mod_mem_cache
描述¶
Lighttpd 处理数千个小文件颇具挑战性。操作系统需要进行大量随机存取,这会增加 IO 等待时间。mod_mem_cache 插件将文件内容存储在内存中以提供更快的服务。它比操作系统缓冲区(至少是 Linux 缓冲区)更具可配置性,在某些情况下可以带来更好的性能。
例如,您可以将其配置为缓存小于 5 KB 的文件,只缓存特定 MIME 类型的文件,或者在达到配置限制时采用不同的策略来释放内存。
安装¶
此模块是第三方模块,未包含在官方发行版中。您需要从此处下载它
对于 lighttpd 1.4.13: [http://blog.quehy.com/tag/mod_mem_cache mod_mem_cache]
对于 lighttpd 1.4.15: [http://bergstroem.nu/lighttpd-1.4.15.mod_mem_cache.v1.2.patch] (不受支持,直接从 1.4.13 补丁移植)
对于 lighttpd 1.4.19: [http://blog.quehy.com/archives/197.html], FreeBSD Ports 的补丁文件 [http://trac.lighttpd.net/trac/attachment/wiki/Docs/ModMemCache/patch-mod_mem_cache.patch]
对于 lighttpd 1.4.xx 和 svn 更新的补丁文件(适用于 rev. 2639):[https://redmine.lighttpd.ac.cn/attachments/1026/lighttpd-1.4.x-svn-mod_mem_cache.patch]
重要
mod_mem_cache 和 mod_cml (--with-lua) 不能很好地协同工作,因为 mod_mem_cache 会修改 lighttpd 处理可缓存项的方式。可能不会为此发布补丁,因为 mod_cml_lua 已被弃用。
选项¶
参见 [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)
示例¶
- mem-cache.filetypes = ("application/x-javascript", "text/css", "text/html", "text/javascript") # 在内存中缓存 javascript, css, html 文件
- mem-cache.max-memory = 1024 # 使用 1G 内存缓存
- mem-cache.max-file-size = 1024 # 缓存最大 1M 大小的文件
关于SLRU平衡的额外信息¶
SLRU 为试用段设有一个 LRU 缓存,为受保护段设有一个。首次未命中时,条目将不带任何数据添加到试用 LRU 缓存中。只有当其命中计数超过阈值时,它才会被传播到具有实际内容的受保护 LRU 缓存。通过这种方式,您可以降低条目被逐出 LRU 缓存的概率,因为您增加了单个条目进入缓存的阈值。实践中,mem-cache.slru-threshold 应调整以实现更高的命中率和更少的内存使用。