0628阙宏宇
Upcoming SlideShare
Loading in...5
×
 

0628阙宏宇

on

  • 3,451 views

 

Statistics

Views

Total Views
3,451
Views on SlideShare
3,144
Embed Views
307

Actions

Likes
11
Downloads
141
Comments
0

17 Embeds 307

http://club.blogbeta.com 190
http://thuannvn.blogspot.com 65
http://www.caiwangqin.com 31
http://blog.caiwangqin.com 5
http://thuannvn.blogspot.fr 2
http://thuannvn.blogspot.com.es 2
http://i.mtime.com 2
http://thuannvn.blogspot.ca 1
http://thuannvn.blogspot.co.at 1
http://thuannvn.blogspot.nl 1
http://thuannvn.blogspot.cz 1
http://thuannvn.blogspot.in 1
http://thuannvn.blogspot.com.br 1
http://thuannvn.blogspot.hk 1
http://www.slideshare.net 1
http://thuannvn.blogspot.de 1
http://thuannvn.blogspot.be 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

0628阙宏宇 0628阙宏宇 Presentation Transcript

  • Lighttpd & Modcache http://blog.quehy.com/ 2009/06/28 Beta 技术沙龙 http://club.blogbeta.com 官方 twitter : @betasalon
  • 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
    • 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 )
  • 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
  • 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
  • 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" )
    • ))
    • )
  • 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/
  • 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
  • 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
  • Modcache vs Squid
    • 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 config(1)
    • cache.bases
      • List of cache directories. For examples: cache.bases = (&quot;/data/cache&quot;, &quot;/data2/cache&quot;)
    • 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 = (&quot;(^|.)linux.com.cn$&quot;) 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
  • Modcache config(2)
    • cache.support-queries
      • Try to cache query with '?'. default is 'disable'. When cache.support-queries = &quot;enable&quot; and cache.dynamic-mode = &quot;disable&quot;, modcache will treat &quot;/uri?q1&quot; or &quot;/uri?q2&quot; as &quot;/uri&quot; and save them to local cache file of &quot;/uri&quot;. When cache.support-queries and cache.dynamic-mode are both enabled, modcache will treat &quot;/uri?q1&quot; and &quot;/uri?q2&quot; 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 &quot;disable&quot;. Note: cache.support-queries has to be enabled when dynamic-mode is enabled.
    • cache.programs-ext
      • List of local program extension, such as &quot;.php&quot;. modcache will replace them with &quot;.cache.html&quot; to aviod confliction with other modules, such as mod_fastcgi. default is not set
  • 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=&quot;^200.100.1.&quot; allow 200.100.1.0/24 to purge cache. Default is not set
  • Cache.refresh-pattern
    • Key of modcache, idea from squid ’ s refresh-pattern
    • cache.refresh-pattern format is &quot;url_pcre_regex&quot; => &quot;minutes options&quot;. Note: zero 'minutes' means cache forever and minutes option is mandatory.
  • 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).
  • 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.
  • 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
  • Modcache Cook Books (1)
    • Site with several millions image files
    • server.modules = (
    • # ...., # other modules
    • &quot;mod_cache&quot;, # make sure mod_cache loaded before mod_proxy
    • &quot;mod_proxy&quot;
    • )
    • proxy.worked-with-mod-cache = &quot;enable&quot;
    • cache.bases = (&quot;/data/cache&quot;)
    • cache.support-queries = &quot;enable&quot;
    • cache.max-memory = 2000 # 2000M suitable for 4G memory server
    • cache.refresh-pattern = (
    • &quot;.(?i)(jpg|bmp|jpeg|gif|png|ico)$&quot; => &quot;0 use-memory&quot;, #cache for ever until removed from memory
    • &quot;.&quot; => &quot;120 &quot; # other uses disk based cache
    • )
  • Modcache Cook Books (2)
    • Softwares/Music/Video download site
    • # uses several separate disks
    • cache.bases = (&quot;/data/cache1&quot;, &quot;/data/cache2&quot;, &quot;/data/cache3&quot;, &quot;/data/cache4&quot;)
    • cache.support-queries = &quot;enable&quot;
    • cache.refresh-pattern = (
    • &quot;.(?i)(rar|zip|exe|wmv|avi|mp3|ape|rm|mpeg|mpg|wma|asf|rmvb)$&quot; => &quot;10080 fetchall-for-range-request&quot;,
    • &quot;.&quot; => &quot;120&quot;
    • )
  • Modcache Cook Books (3)
    • BBS Site
    • server.modules = (
    • &quot;mod_compress&quot;, #use it to compress html/css files
    • &quot;mod_cache&quot;, &quot;mod_proxy&quot;
    • )
    • mimetype.assign = (
    • &quot;.css&quot; => &quot;text/css&quot;,
    • &quot;.js&quot; => &quot;application/x-javascript&quot;,
    • &quot;.html&quot; => &quot;text/html&quot;,
    • &quot;.htm&quot; => &quot;text/html&quot;
    • )
  • Modcache Cook Books (3)
    • BBS Site(continued)
    • # compress output for css/js/html/htm
    • compress.filetype = (&quot;application/x-javascript&quot;, &quot;text/css&quot;, &quot;text/html&quot;)
    • cache.support-queries = &quot;enable&quot;
    • cache.dynamic-mode = &quot;enable&quot;
    • cache.bases = (&quot;/data/cache&quot;)
    • cache.refresh-pattern = (
    • &quot;.(?i)(js|css|xml)$&quot; => &quot;240&quot;,
    • &quot;.(?i)(htm|html|shtml)$&quot; => &quot;30 ignore-vary&quot;,
    • &quot;.(?i)(/|php)$&quot; => &quot;5 use-memory update-on-refresh memory-compress&quot;,
    • &quot;.&quot; => &quot;30 update-on-refresh&quot; # default to update every 30 minutes and on refresh requests
    • )
  • Modcache Cook Books (4)
    • Video share site
    • server.modules = (
    • &quot;mod_flv_streaming&quot;, &quot;mod_cache&quot;, &quot;mod_proxy&quot;
    • )
    • flv-streaming.extensions = (&quot;.flv&quot;)
    • cache.bases = (&quot;/data/cache1&quot;, &quot;/data/cache2&quot;, &quot;/data/cache3“)
    • cache.support-queries = &quot;enable&quot;
    • cache.refresh-pattern = (
    • &quot;.(?i)(flv)$&quot; => &quot;0 flv-streaming&quot;, # flv_streaming for flv files
    • &quot;.&quot; => &quot;120&quot;
    • )
  • Thanks for listening Q&A