Project

General

Profile

Docs TrafficShaping » History » Revision 10

Revision 9 (zkv, 2008-11-21 23:12) → Revision 10/15 (metalfoo, 2008-12-11 16:57)

h1. Traffic Shaping 

 {{>toc}} 

 *Module: core* 

 h2. Description 

 Starting with 1.3.8, lighttpd supports limiting the bandwidth for a single connection or config context like a virtual host or a URL. 

 h2. Options 

 *connection.kbytes-per-second* 
 Limit the throughput for each single connection to the given limit in kbyte/s 
 Default: 0 (no limit) 

 *server.kbytes-per-second* 
 Limit the throughput for all connections to the given limit in kbyte/s 
 Default: 0 (no limit) 

 If you want to specify a limit for a special virtual server use: 

 <pre> 

     $HTTP["host"] == "www.example.org" { 
       server.kbytes-per-second = 128 
     } 

 </pre> 

 which will override the default for this host. 

 *Note:* 

 Keep in mind that a limit below 32kb/s might actually limit the traffic to 32kb/s.  
 This is caused by the size of the TCP send buffer. 

 h2. Selective traffic shaping plugin(>=1.5-svn) 

 There is a small plugin to use selective traffic shaping on a per-connection base. You can e.g. use php and do: 

 <pre> 

  <?php 
  header("X-LIGHTTPD-KBytes-per-second: 50"); 
  header("X-Sendfile: /path/to/file"); 
  ?> 

 </pre> 

 to set the speed of the current connection. 

 h2. Plugin options 

 *speed.just-copy-header = "enable"* 
 Use this on the frontend to just copy the header from the response to the request header (forward it to the backend) 
 Default: "disabled" (just use it) 

 *speed.use-request = "enable"* 
 Use this on the backend to fetch the speed from the request. This is not useful on the frontend, i think :)  
 Default: "disabled" (don't look in the request headers) 

 h3. Build it 

 See the attached file for the most recent version of mod_speed. To build it, download a recent version of Lighttpd 1.5 (from SVN or official pre-release), place this file in the @src@ directory and add it the following lines to your @Makefile.am@: 

 <pre> 
 lib_LTLIBRARIES += mod_speed.la 
 mod_speed_la_SOURCES = mod_speed.c 
 mod_speed_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
 mod_speed_la_LIBADD = $(common_libadd) 
 </pr> Download here: http://trac.lighttpd.net/trac/attachment/wiki/Docs/TrafficShaping/mod_speed.c