« You know you've read a good book.. | Main | I'm interesting »

Quick and dirty guide to having a 100k/s throttle policy

Was doing this on multiple servers today, might as well get a blog entry out of it.
Note: this requires mod_so to be installed.. w/o that you'll need to do a lot more work.
To find out if you have mod_so, use /usr/local/apache/bin/httpd -l


  1. Download mod_throttle
    http://www.snert.com/Software/mod_throttle/mod_throttle312.tgz

  2. upack & unzip the tgz file
    tar -xzvf mod_throttle312.tgz

  3. Edit mod_throttle.c Change: (this is for a freebsd system)

    #define USE_POSIX_SERIALIZATION
    #undef USE_SYSTEM_V_SERIALIZATION

  4. Edit Makefile

    Important stuff:
    1. APXS=/usr/local/apache/bin/apxs
    2. APACHECTL=/usr/local/apache/bin/apachectl

  5. make install (that's not a mistake, don't need to do make first).
    You'll need to do this as root or using sudo since it edits the httpd.conf file.

  6. Edit httpd.conf to set a throttle policy

    #
    # Throttle policy limits connections to 100k/s per IP address
    # Keeps a history of 1000 ip addresses
    #

    <IfModule mod_throttle.c>
       ThrottleClientIP 1000
       ThrottlePolicy Speed 100K 1s
       <Location /ts>
          SetHandler throttle-status
       </Location>
    </IfModule>

  7. Restart apache

    /usr/local/apache/bin/apachectl restart

  8. You're now throttling the entire server to 100k/s per IP.

Comments

Would like to know more from you