I have a site where users can download large files. However, sometimes when a user downloads, they hog all the bandwidth, thus showing down the entire website. Is there any way on Apache 2 on Windows Server 2003 to limit the bandwidth a specific IP (user) can use at a given moment?
I want to cap the download speed for each user to 60kbps. Thanks!
Originally posted by amitroy5 Thanks for the idea, but I need it for Apache 2 on Windows. Also, I want to do it by user rather than by website. Thanks!
One method would be to use some form of script (PPHP, perl, ...) to get the files - the user requests http://<host>/<dir>/file.php?filename=<file> and file.php reads the file and sends it no faster than 60Kb/s (or some other rate). Something like "read 6Kb and send, sleep for 0.1 secound, loop until end of file".
If you want to limit a user over multiple connections (i.e. 60KB/s total rather than 60Kb/s per file if they are getting more than one) then you'll need to record their activiy somewhere in a DB or in the filesystem (each process would record "at time xx:xx I sent xxKb to <user>" and would check before sending anything that no more than <rate>Kb has gone in the last minute or so..
* Bandwidth management, as intelegent as you can program
* Will stop download managers using multiple streams for the same file (each user will be less of a hog)
* You'll have to write it if you can't find someone who has done it before!
* Extra complication. At least one more thing that could wrong...
* Takes more CPU/RAM (PHP thread/proces for each download, and perhaps some SQL activity)
* Will stop download managers using multiple streams for the same file (my irritate some of your users)
Oh, and with the above technique make sure the files in question are stored outside the document root(s) configure to be visible to the world in Apache, otherwise people may work out how to bypass your script get at the file directly.