1 / 23

Lighttpd & Modcache

Lighttpd & Modcache. 2009/06/28. Basic lighttpd info. Event-driven, single process Uses non-block io (network) + writev (memory) + sendfile (local files) Light weighted, simple module structure Homepage http://redmine.lighttpd.net/projects/lighttpd. Lighttpd ’ s advantages.

Download Presentation

Lighttpd & Modcache

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lighttpd & Modcache 2009/06/28

  2. Basic lighttpd info Event-driven, single process Uses non-block io (network) + writev (memory) + sendfile (local files) Light weighted, simple module structure Homepage http://redmine.lighttpd.net/projects/lighttpd

  3. Lighttpd’s advantages No need to sync data and variables between modules Modern OS/Hardware are so powerful that event-driven model works great Handy conditional configuration Easy to write modules (http://redmine.lighttpd.net/projects/lighttpd/wiki/Devel )

  4. Lighttpd’s disadvantages Sometimes one process isn’t enough (try server.max-workers) One block io operation may block whole http service mod_fastcgi doesn’t work as fast as it should be because of poor request distribution algorithm

  5. General lighttpd tuning • server.event-handler = "linux-sysepoll“ • server.max-fds = 16384 # set max open fd limit to 16k • server.max-keep-alive-idle = 0 #don’t use keep-alive • server.max-read-idle = 30 # smaller read timeout • server.max-write-idle = 180 # smaller write timeout

  6. Mod_fastcgi Tuning server.max-request-size = 40960 #maximum 40M post content length fastcgi.server = ( ".php" => (( "socket" => "/tmp/php-fastcgi.socket", "bin-path" => "/usr/bin/php-cgi -c /etc/php.ini", "max-procs" => 20, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "9", #lighttpd will fork 20*10=200 php-cgi children "PHP_FCGI_MAX_REQUESTS" => "50000“ # php child restart after processing 50k requests ), "broken-scriptfilename" => "enable", "allow-x-send-file" => "enable", "check-local" => "disable", "bin-copy-environment" => ( "PATH", "SHELL", "USER" ) )) )

  7. Basic modcache info Project started when squid can’t fulfill need v1.0 released at 10/2006, v1.8 released at 06/2009 Open source, BSD License Supports both disk-based cache and memory-based cache Homepage http://www.linux.com.cn/modcache/

  8. Modcache’s advantages Lighttpd based (it’s a powerful web server, far away beyond normal proxy server) Works with other lighttpd modules, such as mod_compress / mod_access Keep it as simple as possible Small source code base (< 3000 lines) Don’t use local db to store cache information

  9. Modcache’s disadvantages No internal cache files management (try /usr/sbin/tmpwatch) Rules of cache are controlled by modcache, not by backend servers Memory cache doesn’t share between different lighttpd processes It’s a patch, not included in official lighttpd release

  10. Modcache Event based Directories based Without disk management Reverse Cache only No ICP Expire time based on refresh.pattern Conditional config /ACL Small source codebase Squid Thread based DB based With disk management Reverse/Forward Cache Supports ICP Expire time based on backend response and refresh-pattern ACL Large source codebase Modcache vs Squid

  11. Modcache config(1) cache.bases List of cache directories. For examples: cache.bases = ("/data/cache", "/data2/cache") cache.domains List of domains which modcache would try to cache for. When it isn’t set, modcache would cache files of every domains. for examples: cache.domains = ("(^|\.)linux\.com\.cn$") caches *.linux.com.cn. domains. cache.ignore-hostname. Includes hostname in saved filename or not. default is disable. cache.debug Default is disable cache.enable Default is enable

  12. Modcache config(2) cache.support-queries Try to cache query with '?'. default is 'disable'. When cache.support-queries = "enable" and cache.dynamic-mode = "disable", modcache will treat "/uri?q1" or "/uri?q2" as "/uri" and save them to local cache file of "/uri". When cache.support-queries and cache.dynamic-mode are both enabled, modcache will treat "/uri?q1" and "/uri?q2" as different resource and save them to different local cache files. cache.dynamic-mode To support dynamic generated web page such as forum/bbs. default is "disable". Note: cache.support-queries has to be enabled when dynamic-mode is enabled. cache.programs-ext List of local program extension, such as ".php". modcache will replace them with ".cache.html" to aviod confliction with other modules, such as mod_fastcgi. default is not set

  13. Modcache config(3) cache.max-memory-size Number of MBytes which modcache will use to save cached content in memory. default is 256Mbytes. cache.lru-remove-count Number of content removed from memory when memory is full. default is 256. cache.purge-host pcre regex hosts ip which are allowed to PURGE cache files. for examples: cache.purge-host="^200\.100\.1\." allow 200.100.1.0/24 to purge cache. Default is not set

  14. Cache.refresh-pattern Key of modcache, idea from squid’s refresh-pattern cache.refresh-pattern format is "url_pcre_regex" => "minutes options". Note: zero 'minutes' means cache forever and minutes option is mandatory.

  15. Refresh Pattern options(1) ignore-reload Don't update cache when browser sends 'Cache-Control: no-cache' header. It's default behaviour update-on-refresh Update cache when browser sends 'Cache-Control: no-cache' header. Nocache Don't cache matched url. fetchall-for-range-request Download all content of file if client sends 'Range: xxx-yyybytes' header. Useful for multi-thread downloaders(such as flashget).

  16. Refresh Pattern options(2) rfc-violated options: override-expire Ignore backend's 'Expire' header while determining whether to cache. ignore-vary Igore backend’s ‘Vary’ header while determining whether to cache ignore-cache-control-header Ignore backend's 'Cache-Control' headers while determining whether to cache.

  17. Refresh Pattern options(3) flv-streaming to work with mod_flv_streaming. memory-compress compress memory-saved content for ‘Accept-Encoding: gzip, deflate’ request use-memory use memory to save caches instead of local disk

  18. Modcache Cook Books (1) Site with several millions image files server.modules = ( # ...., # other modules "mod_cache", # make sure mod_cache loaded before mod_proxy "mod_proxy" ) proxy.worked-with-mod-cache = "enable" cache.bases = ("/data/cache") cache.support-queries = "enable" cache.max-memory = 2000 # 2000M suitable for 4G memory server cache.refresh-pattern = ( "\.(?i)(jpg|bmp|jpeg|gif|png|ico)$" => "0 use-memory", #cache for ever until removed from memory "." => "120 " # other uses disk based cache )

  19. Modcache Cook Books (2) Softwares/Music/Video download site # uses several separate disks cache.bases = ("/data/cache1", "/data/cache2", "/data/cache3", "/data/cache4") cache.support-queries = "enable" cache.refresh-pattern = ( "\.(?i)(rar|zip|exe|wmv|avi|mp3|ape|rm|mpeg|mpg|wma|asf|rmvb)$" => "10080 fetchall-for-range-request", "." => "120" )

  20. Modcache Cook Books (3) BBS Site server.modules = ( "mod_compress", #use it to compress html/css files "mod_cache", "mod_proxy" ) mimetype.assign = ( ".css" => "text/css", ".js" => "application/x-javascript", ".html" => "text/html", ".htm" => "text/html" )

  21. Modcache Cook Books (3) BBS Site(continued) # compress output for css/js/html/htm compress.filetype = ("application/x-javascript", "text/css", "text/html") cache.support-queries = "enable" cache.dynamic-mode = "enable" cache.bases = ("/data/cache") cache.refresh-pattern = ( "\.(?i)(js|css|xml)$" => "240", "\.(?i)(htm|html|shtml)$" => "30 ignore-vary", ".(?i)(/|php)$" => "5 use-memory update-on-refresh memory-compress", "." => "30 update-on-refresh" # default to update every 30 minutes and on refresh requests )

  22. Modcache Cook Books (4) Video share site server.modules = ( "mod_flv_streaming", "mod_cache", "mod_proxy" ) flv-streaming.extensions = (".flv") cache.bases = ("/data/cache1", "/data/cache2", "/data/cache3“) cache.support-queries = "enable" cache.refresh-pattern = ( "\.(?i)(flv)$" => "0 flv-streaming", # flv_streaming for flv files "." => "120" )

  23. Thanks for listening Q&A

More Related