Copyright and Artistic Licence. |
/*----------------------------------------------------------------------------- Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, Alan Kennington. You may distribute this software under the terms of Alan Kennington's modified Artistic Licence, as specified in the accompanying LICENCE file. -----------------------------------------------------------------------------*/This software package is open and free. Please read the LICENCE file for precise details. |
DISCLAIMER. |
The author of this software disclaims any express or implied guarantee of the fitness of this software for any purpose. In no event shall the author of this software be held liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. |
Function and purpose. |
The Apache module mod_bwshare throttles HTTP requests to Apache 1 and 2
servers for each client IP address independently.
The mod_bwshare module accepts or rejects HTTP requests from each client IP address based on past downloads by that client IP address. If the HTTP client's download rate exceeds specified levels, the reponse to the HTTP client is an HTML warning message. A human browser will see a warning message indicating how long to wait.
Automatic rampant downloaders will download large numbers of useless warning
messages.
|
Requirements and compatibility. |
The bwshare module has been developed and tested under SuSE 6.2, SuSE
7.1, SuSE 9.1 and Redhat 5.2.
Some people have used it with FreeBSD 4.1 and Solaris 2.6. This should work with Apache versions 1.2.13+, 1.3.x and 2.0.44. 2004-6-18: The latest reported bwshare success is with FreeBSD 4.9-STABLE with Apache 2.0.48 on 2004-2-3.
2006-5-16:
Note that the mod_bwshare Apache module probably does not
work for Apache 1.x.y any more. I haven't tried to build it for Apache 1 for
many years. I'll back-port it to Apache 1.x again when I get some spare time.
|
Download source. | |||||
Please do not use Wget or download acceleratorsto download the source files. My web server does not accept such user agents. |
Robustness and efficiency. |
This module is apparently very reliable, which is not surprising because
reliability was a principal design objective.
I ran it for 7 months from July 2002 to February 2003 without problems. The amount of data handled during those 7 months was about 7 GBytes. It hasn't ever crashed or failed on my site from 2002 to the present. Nor have I heard of any reports of it crashing or failing.
Some other design objectives were CPU efficiency and memory compactness.
|
Installation of bwshare as a DSO module for Apache 2. |
2005-11-22:
To install bwshareas a DSO module for Apache 2 with all of the paths as in the default source settings, I do the following. moose /root# /usr/local/apache2/bin/apxs -c mod_bwshare.c moose /root# /usr/local/apache2/bin/apxs -i mod_bwshare.la moose /root# /usr/local/apache2/bin/apachectl restart I had to add the following line to the httpd.conf file first. LoadModule bwshare_module modules/mod_bwshare.so
I also added this sort of thing in a file <IfModule mod_bwshare.c> <Location /bwshare-info> SetHandler bwshare-info </Location> <Location /bwshare-trace> SetHandler bwshare-trace </Location> # Some bandwidth control parameters. <Directory /> BW_tx1debt_max 25 BW_tx1cred_rate 0.095 BW_tx2debt_max 3000000 BW_tx2cred_rate 2500 </Directory> </IfModule> Here's a typical session: moose /root# /usr/local/apache2/bin/apxs -c mod_bwshare.c /usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache2/include -c -o mod_bwshare.lo mod_bwshare.c && touch mod_bwshare.slo /usr/local/apache2/build/libtool --silent --mode=link gcc -o mod_bwshare.la -rpath /usr/local/apache2/modules -module -avoid-version mod_bwshare.lo moose /root# ls -l mod* .libs -rw-r--r-- 1 root root 152562 Nov 15 22:39 mod_bwshare.c -rw-r--r-- 1 root root 822 Nov 22 19:27 mod_bwshare.la -rw-r--r-- 1 root root 324 Nov 22 19:27 mod_bwshare.lo -rw-r--r-- 1 root root 123752 Nov 22 19:27 mod_bwshare.o -rw-r--r-- 1 root root 0 Nov 22 19:27 mod_bwshare.slo .libs: total 337 drwxr-xr-x 2 root root 208 Nov 22 19:27 . drwx------ 20 root root 944 Nov 22 19:27 .. -rw-r--r-- 1 root root 123904 Nov 22 19:27 mod_bwshare.a lrwxrwxrwx 1 root root 17 Nov 22 19:27 mod_bwshare.la -> ../mod_bwshare.la -rw-r--r-- 1 root root 823 Nov 22 19:27 mod_bwshare.lai -rw-r--r-- 1 root root 123752 Nov 22 19:27 mod_bwshare.o -rwxr-xr-x 1 root root 85438 Nov 22 19:27 mod_bwshare.so moose /root# /usr/local/apache2/bin/apxs -i mod_bwshare.la /usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' mod_bwshare.la /usr/local/apache2/modules /usr/local/apache2/build/libtool --mode=install cp mod_bwshare.la /usr/local/apache2/modules/ cp .libs/mod_bwshare.so /usr/local/apache2/modules/mod_bwshare.so cp .libs/mod_bwshare.lai /usr/local/apache2/modules/mod_bwshare.la cp .libs/mod_bwshare.a /usr/local/apache2/modules/mod_bwshare.a ranlib /usr/local/apache2/modules/mod_bwshare.a chmod 644 /usr/local/apache2/modules/mod_bwshare.a PATH="$PATH:/sbin" ldconfig -n /usr/local/apache2/modules ---------------------------------------------------------------------- Libraries have been installed in: /usr/local/apache2/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- chmod 755 /usr/local/apache2/modules/mod_bwshare.so moose /root# /usr/local/apache2/bin/apachectl restart |
Installation of bwshare as a DSO module for Apache 2 under SuSE 9.1 linux. |
Installation of bwshare as a DSO module seems to be quite simple on SuSE 9.1:
apxs2 -c mod_bwshare.c su -c "apxs2 -i mod_bwshare.la"
I do the above as an ordinary user and then give the super-user password for the
second line when it prompts me. Then I run I actually use the following as root user: apache2ctl stop ; apxs2 -i mod_bwshare.la ; apache2ctl start
I do that after running On my SuSE 9 systems, I don't need to modify the httpd.conf file, but when I run Apache 2.0.50 compiled from source, I have to add this line to the httpd.conf file: LoadModule bwshare_module modules/mod_bwshare.so |
Static installation of bwshare version 0.1.2 for Apache 2.0.16. | ||
These instructions seem to work with Apache 2.0.44 for bwshare 0.1.4.
Alternatively, these instructions work for Apache 2.0.16 with bwshare 0.1.2.
To install this software, create a directory apache/modules/bwshare in
your apache source tree.
LTFLAGS="$LTFLAGS -export-dynamic"
If autoconf causes this line to appear in your configure file,
you will have to remove it or comment it out.
The parameter --enable-bwshare must be used with the configure command in the top-level Apache source directory (in addition to any other command line arguments you normally use) if you choose the no option in the config.m4 file.
If there are any problems with the Makefile.in or config.m4
files, compare them with the corresponding files in other modules, e.g. in
apache/modules/experimental.
|
Static installation for Apache 1.2.13+ and 1.3.x. |
To install mod_bwshare with static linkage, create a directory
apache/src/modules/bwshare in your apache source tree.
Then copy Makefile.tmpl and mod_bwshare.c to the apache/src/modules/bwshare directory. The parameter --activate-module=src/modules/bwshare/mod_bwshare.o should be used with the configure command in the top-level Apache source directory (in addition to any other command line arguments which you normally use).
If there are any problems with the Makefile.tmpl file, compare it with
the Makefile.tmpl file in other modules, e.g. in
apache/src/modules/example.
The following line may be suitable in the httpd.conf file.
AddModule mod_bwshare.c See also my notes on installing Apache 1.3.23 with PHP 4.1.2 and bwshare 0.1.2. |
Bugs. |
|
Concept of operation: Purpose, principles, philosophy. | |||||||||||||||
The purpose of this module is to give the web site operator some control over
bandwidth utilization by individual client hosts.
The mod_bwshare module uses a form of
The guiding principle in this module is that two categories of clients should be
allowed unhindered access: human users and well-behaved search engines.
There are many actions which a throttling module can take when an excessive
user is identified.
Currently, the module bwshare has the following features.
Just as in IP differential service, a general bandwidth sharing module must (1) classify the traffic (e.g. according to client IP address), (2) measure the traffic (e.g. with leaky buckets tx1 and tx2), and (3) take appropriate actions (e.g. shape/police/arbitrate the traffic). |
Useful links. |
For more Apache modules, see the
Apache module registry.
For other bandwidth management modules, see the Apache Overview HOWTO. For information in Italian language about Apache bandwidth management, see this wiki: Gestione della banda in Apache. This softpedia link was made without my knowledge. |