
                                     Mod_Throttle
                      User specific throttling for Apache 1.2.x
                                           
   [1]Cut to the chase
   
   I'll admit it - I've been web master for a number of adult sites, some
   professional and some personal. One thing you can be certain of with sites with
   adult content is that you're going to have traffic. The first site I set up on a
   personal basis sat behind a 28.8kbps modem link, what a mistake. As soon as the
   site was discovered, it was saturated. I upgraded to 128kbps frame relay link
   and swamped it within a week or so as well. After a bit, I had to upgrade to
   384kbps, but no joy. At that point I had to grit my teeth and go all the way to
   T1. One thing about T1 links is that they are expensive, and I started selling
   web hosting to support my habit. Unfortunately, on the first night at T1 speeds,
   I got a rather irate phone call from my up stream provider. It seemed I was
   maxing out the link and was all my my lonesome swamping the Cisco 2500 that I
   was attached to.
   
   It was real obvious that I needed to throttle my web activity. Initially I did
   this by cutting down the number of concurrent connections that I allowed.
   Unfortunately, when other people started to pay for part of the bandwidth, their
   smaller sites suffered disproportionately. So I started to run multiple copies
   of Apache, each listening on different ports, with the main server redirecting
   queries to individual daemons with lower limits. You can imagine the
   administrative nightmares.
   
   Even with this, things were not happy. When you limit traffic by the number of
   concurrent sessions, you have no fine control over exactly what happens. Some
   customers had only 2 (!) concurrent sessions enabled and were still running
   gigabytes a month of traffic.
   
   What to do? An Apache module seemed to be the solution. I'd looked at
   [2]mod_limit and [3]mod_sessions, the first of which cuts a user off cold, and
   the second of which just eased my administrative issues. Neither of which solved
   my problems.
   
   In the end I wrote mod_throttle. Mod_throttle started as a series of hacks on
   mod_limit, but there's very little code left from it at this point.
   Mod_throttle's main function is to set average Bps limits for individual
   customers. It also supports a greatly enhanced version of mod_limit's status
   [4]display, so you can actually see who's pushing the envelope. Mod_throttle
   works by inserting increasingly long delays in service when a user is over their
   limit.
   
   How well does it work? For me it works marvelously. It's reduced the memory/cpu
   loads on my server by two-thirds and keeps the users exactly in their limits
   with as little pain as possible.
   
   [5]Download mod_throttle.tar.gz v1.0
   
   Installation is pretty standard for Apache:
    1. Go to the Apache src directory.
    2. Unzip and untar the archive. It puts itself into the modules directory.
    3. Add "throttle" to modules/Makefile
    4. Add "modules/throttle/mod_throttle.o" to the list of modules in
       Configuration.
    5. Run Configure.
    6. Re-install.
    7. Be happy.
       
   You can skip #7 if you really have to, but don't blame me if things don't work
   out. It also helps if you add lines similar to these to your httpd.conf file:
   
#
# Location of the file that contains the throttle limits for each user.
# Enteries in the file are of the form "username throttle" where throttle
# is the highest Bps (that's Bytes per second) that is allowed.
#
ThrottleConfig    /var/www/conf/limits
#
# This needs a bit of explaining. If Apache is started during a high usage period,
# some web sites will hit a wall more-or-less immediately. Slack gives them this many
# seconds of grace (1 hour in this case.) This doesn't mean they have free-reign for
# the first hour -- if they ramp up fast enough, they'll still get throttled.
#
ThrottleSlack     3600
#
# Color coding for the status display. If you don't like the blinking red of 'critical',
# either change the source or set critical to 110 percent load.
#
ThrottleIndicator blue     5
ThrottleIndicator green    30
ThrottleIndicator amber    70
ThrottleIndicator red      80
ThrottleIndicator critical 90
#
# This sets the viewable location of the status display.
#
<location /throttle>
SetHandler throttle-info
</location>

   Send bugs, requests, etc to [6]mlovell@bigrock.com

References

   1. file://localhost/u1/debian/up/apache/apache-1.3b7/debian/mod_throttle.html#download
   2. ftp://ftp.apache.org/apache/dist/contrib/modules/
   3. http://www.zyzzyva.com/module_registry/retreive.cgi?branch=contrib
   4. file://localhost/throttle
   5. file://localhost/u1/debian/up/apache/apache-1.3b7/debian/mod_throttle.tar.gz
   6. mailto:mlovell@bigrock.com
