Limit Download Speed with Apache

By  on  

My adventures into retro gaming have brought me back into the semi-seedy world of piracy websites and the technology considerations that dictate their business model.  Annoying popups and pornographic advertisements aside, the most obvious technological observation I made was that each of these sites used bandwidth throttling as a way to make money.  Want that game to download quickly?  Stump up $10 per month and it will be lightning fast; otherwise you're relegated to sleep-inducing download speeds.

In researching download speed limits, it became apparent that dynamic rate limitation is incredibly inefficient, and that the best way to throttle downloads is by configuring different servers or virtual directories with different download speeds, and directing each user to each server based on the download speed they should have.

Configuring Apache's Download Speed Limit

To throttle the download speed on Apache servers, enable the mod_ratelimit extension:

<!-- Requires 2.4+ -->
LoadModule ratelimit_module modules/mod_ratelimit.so

Then set different download speeds by directory with the following Apache configuration:

<IfModule mod_ratelimit.c>
    <!-- 100kb/second limit -->
    <Location /tier1>
        SetOutputFilter RATE_LIMIT
        SetEnv rate-limit 100
    </Location>

    <!-- 500kb/second limit -->
    <Location /tier2>
        SetOutputFilter RATE_LIMIT
        SetEnv rate-limit 500
    </Location>
</IfModule>

Some type of dynamic Apache config would allow custom URLs per user which would obscure download speed URLs so users couldn't dynamically spoof URLs to get some else's download speed.

The download speed limit and throttling business seems booming: just look at MEGA and other likewise services.  The science behind download throttling is big business and I hope to learn more about it.  In the mean time, it's nice to know that download speed limitation can be done with a few Apache directives!

Recent Features

  • By
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

  • By
    Camera and Video Control with HTML5

    Client-side APIs on mobile and desktop devices are quickly providing the same APIs.  Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop.  One of those APIs is the getUserMedia API...

Incredible Demos

  • By
    Fx.Rotate:  Animated Element Rotation with MooTools

    I was recently perusing the MooTools Forge and I saw a neat little plugin that allows for static element rotation: Fx.Rotate. Fx.Rotate is an extension of MooTools' native Fx class and rotates the element via CSS within each A-grade browser it...

  • By
    Image Data URIs with PHP

    If you troll page markup like me, you've no doubt seen the use of data URI's within image src attributes. Instead of providing a traditional address to the image, the image file data is base64-encoded and stuffed within the src attribute. Doing so saves...

Discussion

  1. is it possible to limit only download thread for download managers?? like In internet download manager there is setting up to 32 threads.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!