Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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...

share|improve this question
    
Use a CDN (Content Distribution Network). You upload to them, your users stream from the CDN, you don't have to worry as much about your bandwidth usage. –  Tom O'Connor Feb 18 '13 at 0:33
    
I have a little video on demand solution. So I need to do it on my server. –  user1709024 Feb 18 '13 at 0:49
    
Is that enough bandwidth to actually play the video? –  Michael Hampton Feb 18 '13 at 1:09
    
200kb/s? .. Yes, that is enought / user. I use mp4 video convert. It's good, small.. –  user1709024 Feb 18 '13 at 2:25

3 Answers 3

up vote 2 down vote accepted

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.

share|improve this answer
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 0:48
    
Your distribution may have packaged an already compiled version of it, otherwise fedora has the .tgz file here –  DerfK Feb 18 '13 at 0: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 1: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 1:05

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.