http://www.apachefreaks.com/tutorials/32/1.php *Limiting the Max Bandwidth on a Virtual Host*

You can limit on Virtual Hosts or by directory. You'll have to decide which method to choose, however the the syntax is the same. The syntax would look something like:

<IfModule mod_bandwidth.c> BandWidthModule On BandWidth all NUM_BYTES </IfModule>

I still believe this is a bad idea because if you have a heavy-hitter with the file downloads, the site in this virtual host won't even load until someone is done downloading.

*Limiting Bandwidth on a File Size*

I think this is the best method because the site will still load as fast as possible, however the file downloads won't be as fast. It also helps prevent those download managers that slam your servers and download 5 - 10 instances of a single file at one time and combine the results into the expected file at the end.

The syntax is:

<IfModule mod_bandwidth.c> BandWidthModule On LargeFileLimit FILE_SIZE_KB MAX_FILE_TRANSFER_BYTES </IfModule>

Whereas the file size is (inconsistently) in Kilobytes and the transfer rate is in Bytes. This works extremely well and it is on a per-file, per-connection basis. The same user can download 2 files at the MAX_FILE_TRANSFER_BYTES, however they can never exceed that setting per file download.


Limiting Connections

If you want to limit the number of connections you can use the following setting:

<IfModule mod_bandwidth.c> BandWidthModule On MaxConnection MAX_NUM_CONNECTIONS </IfModule>

Basically, this works server-wide or on a virtual host basis. It's pretty straight forward, if the MAX_NUM_CONNECTIONS value is exceeded, the connection will be rejected.

I still do not think this is a great idea, if you limit your bandwidth properly, but if someone has an extremely busy site and it's eating up your resources, such as RAM and CPU, then this should be considered as an option.


Preventing Common Problems There's one small problem with mod_bandwidth, however the developers have made a correction with a Perl file for you. You can download this Perl file, alter the LINKDIR setting to the path you used above for the link directories and run it on system startup.

Here's quick rundown of how to clean those links that may be left behind when a user cancels a transfer:

cd <http://www.linuxforum.com/shell/cd/44-34.php> /usr/local/bin wget ftp://ftp.cohprog.com/pub/apache/module/cleanlink.pl

Now, edit this downloaded file and alter the $LINKDIR variable. $LINKDIR=3D/var/apachebwThere is also a $TIME variable which declares how often (in seconds) to clean these links. Run the file once and then add it to your rc.local file: perl /usr/local/bin/cleanlink.pl

echo <http://www.linuxforum.com/shell/echo/119-35.php> perl /usr/local/bin/cleanlink.pl >> /etc/rc.local

ThrottleBandwith (last edited 2006-02-24 17:27:33 by VincentBatts)