1

I would like to limit the download speed of my .flv and my .mp4 files per user on my domain. My page have got 1000-3000 visitor per day and they can't watch my things at the same time, cos 1-2 people get all my bandwidth.

I would like to give 200KiB/s / user...

If there are 10 listeners of my stream than they use 2Mib/s, not 30-40Mib/s... And I would like to give them a minimum..

I tried Bandwidth module, but it works for domains, not for user..

BandwidthModule On ForceBandWidthModule On LargeFileLimit .flv 1 204800 LargeFileLimit .mp4 1 204800

Is there any easy installable apache module? Or can I limit only download fibers? ... Download speed limit by IP, or connection...

user1709024
  • 127
  • 10

3 Answers3

2

If there is no Apache-internal solution and we are talking about Linux here there may be an option to do this with traffic shaping. All you need is a possibility to (quickly) communicate outside Apache that the respective process belongs to a certain user. Perhaps you can rewrite the URLs of your files so that Apache calls a PHP script instead. The script would determine the user and the process ID and write both to a small "daemon" (e.g. Python script) before it sends the requested data. This daemon would add an iptables rule with --pid-owner (doesn't work any more, see below: Edit) in the mangle table and mark the packet (one number for each (active) user).

You would define an HTB class for each simultaneously active user. The tc filters would assign each packet one of these classes depending on the nfmark set by iptables. You can decide whether these classes have 200KiB/s as a hard limit or get the spare bandwith in addition. This way it does not matter how many connections a user has open, the limit is global over all of them.

From time to time the "daemon" would have to check whether all processes still exist and delete the rules for those which have gone.

Edit

It seems that the option --pid-owner has been removed from iptables. The possibility to filter based on user or group does probably not help. But a PHP script knows the destination address so that it can call a script with these parameters which creates an respective rule.

Hauke Laging
  • 5,285
  • 2
  • 24
  • 40
2

It looks like mod_cband is probably your best bet. The CBandRemoteSpeed directive specifically limits number of connections, connections per second, and connection speed per client IP. It doesn't appear to have a "per file-type" option. According to the documentation it's set per <VirtualHost> so if you only wanted to throttle .flv and .mp4 files you'd need to move them to a virtualhost by themselves (say streaming.example.com) and enable cband there.

DerfK
  • 19,493
  • 2
  • 38
  • 54
  • 1
    I can't download it from the source, Cos it gives me 404 error, so I can't install mod_cband. :-( [14-11-2006] – mod_cband 0.9.7.5 is available for download!! ... But only 404 error.. – user1709024 Feb 18 '13 at 00:48
  • Your distribution may have packaged an already compiled version of it, otherwise fedora has the .tgz file [here](http://pkgs.fedoraproject.org/repo/pkgs/mod_cband/mod-cband-0.9.7.5.tgz/5c5d65dc9abe6cdc6931b6dd33be5018/) – DerfK Feb 18 '13 at 00:54
  • onfigure: error: apxs missing root@webstar:~/mod-cband-0.9.7.5# make make: *** No targets specified and no makefile found. Stop. make: *** No rule to make target `install'. Stop. – user1709024 Feb 18 '13 at 01:01
  • You need to install apache's module-building-tools (which includes `apxs`), or look and see if there's a pre-compiled module in your distribution. – DerfK Feb 18 '13 at 01:05
1

As DerfK already mentioned, mod_cband will do the job quick and dirty but it's CPU-intensive for higher workload.

The magic thing behind a professional bandwidth throttling is to provide it as a separated service.

If you are in a colcolated hosting environment, you can start with a additonal 1HE machine.

mate64
  • 1,681
  • 4
  • 18
  • 29