Per requests from several guys, I made one jumbo patch for lighttpd 1.5(revision 1524). The jumbo patch includes mod_cache v1.3, mod_mem_compress, mod_mem_cache and mod_deflate patch.
Get jumbo patch here
Usage:
wget http://blog.quehy.com/doc/lighttpd-1.5.r1524.jumbo.patch svn co svn://svn.lighttpd.net/lighttpd/trunk/ cd trunk sh autogen.sh; ./configure --quiet;make; make distclean patch -p0 < ../lighttpd-1.5.r1524.jumbo.patch
mod_cache 1.3 is just released for lighttpd 1.5, no new feature is added. lighttpd 1.5(r1524) is little buggy and isn't as stable as 1.4.13, but it's sure that lighttpd 1.5's performance is beyond 1.4.13:) Please visit homepage for detail and read configuration example for lighttpd 1.5 carefully before use.
I downloaded lighttpd 1.5 (r1523) today and found mod_deflate was buggy. Bugs come from deflate.sync-flush and deflate.work-block-size.
- When deflate.sync-flush is enabled with transfer-encoding was chunked, only part of first chunk was compressed
- For chunked transfer-encoding, when deflate.work-block-size is smalled than size of one chunk, compressed output is gambled.
I removed deflate.work-block-size and deflate.sync-flush and it works for me.
Get patch here
mod_memcache is a plugin which stores content of files in memory for later visit. mod_memcache has following configuration:
- memcache.enable. enable or disable memcache, default to enable
- memcache.maxmemory. maxium memory in Mbytes used by mod_memcache, default is 512(means 512M memory).
- memcache.maxfilesize. maxium size in kbytes for single cache file, default is 512(means 512k bytes).
- memcache.lruremovenumber. number of cached items to remove when used memory reached maxmemory by LRU algorthim. default is 200.
- memcache.expire-time. cache's expire time in minutes. default is zero which means never expire
- memcache.filetypes. content-type arrays which want to put into memcache. default is not set which means to cache all types. for examples: memcache.filetypes=("text/css") to cache css files only.
http_response_handle_cachable function and mod_staticfile.c are slightly modified for http 304 code handling. memcache will set three counters in mod_status' status.statistics-url for monitoring.
patch is here. please let me know if you had questions.
PS: I like to use hash because hash is straigh forward and fast;)
Jan 刚发布了令人期待的LINUX AIO支持,我也来凑热闹把我写好的mod_memcompress plugin 奉献给大家;)
mod_memcompress工作方式类似mod_compress, 把浏览器的gzip,deflate请求的内容压缩后放到内存里,下次其它浏览器相同的请求直接从内存里输出结果。
mod_memcompress 的配置参数如下:
- memcompress.filetype, 设置压缩文件的类型。举例memcompress.filetype = ("text/html", "application/x-javascript", "text/css")
- memcompress.maxfilesize, memcompress压缩的最大文件大小,单位是Kbytes。缺省是4096
- memcompress.maxmemory, memcompress缓存占用最大的内存大小,单位是Mbytes。缺省是256
- memcompress.nocompress-url, PCRE正则表达式。匹配正则表达式的URI将不被处理。
- memcompress.enable, 打开memcompress的开关。缺省enable
- memcompress.lruremovenumber,当memcompress用到最大内存时,memcompress从缓存中删除的条目数量。缺省500个。
- memcompress.compression-level, 压缩级别,是1~9的数字,越大代表压缩率越高,压缩时占用cpu也越多。缺省是Z_DEFAULT_COMPRESSION
当压缩结果存到缓存里是,返回的HTTP头有X-Mem-Hit: to memcompress;当压缩结果从缓存中读取时,返回的HTTP头有X-Mem-Hit: by memcompress。方便判断缓存效果;)
在说说实现细节,挺有意思。memcompress把缓存结果信息hash到131072(2^17)的数组里,然后用数组的prev,next整型变量做lru伪双向链表,lurheader和lruend记录lru链表的头和尾。大家可能奇怪,为什么不用指针去实现双向链表呢。其实第一版的lru是用指针实现,但偶尔会出现指针指到不正确的地方导致Segment Fault。LRU指针不正确是可以在更新LUR表时遍历一次检查,但这样的开销就太大了;换成整型变量做LRU后,不再出现segment fault了。
Extract from lighttpd.net
The code layout
Now take a look at your plugin, mod_counter. You should see:
- the configuration structures: plugin_config and plugin_data
- the init code for the structures
- set_defaults to parse the configuration
- the patch-function which applies the conditionals
- the real work code and finally
- plugin_init function which is called once the plugin is registered into the server