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 have a debian server at home using my personal internet connection (50 mbps up). I've set up a simple SFTP service with OpenSSH to share big files (10 Gb+) with multiple users.

Here's my problem : regarding bandwidth repartition, it's the jungle. I have users with standard ADSL connection, others with optic fiber connection, etc. Each user has a different download speed, and usually the largest download bandwidth wins.

I'd like to know if it's possible to divide my upload bandwidth "almost equally" between the users.

Ideally, each user would be able to download a file up to 50/n mbps (where n is the number of users connected).

Thank you very much for your help.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Since you're using Debian Linux, you can do it quite simple. You can use this script for "fair" repartition on the bandwidth:

#Put here your Internet-interface instead of eth1
ext_iface=eth1
eiface_addr=192.169.158.150

###############Remove shaper rules###############################3
iptables -t mangle --flush

tc qdisc del dev $ext_iface root 2> /dev/null > /dev/null

iptables -t mangle -D POSTROUTING -o $ext_iface -j shape-in 2> /dev/null > /dev/null
iptables -t mangle -F shape-in 2> /dev/null > /dev/null
iptables -t mangle -X shape-in 2> /dev/null > /dev/null

##############Adding shaper rules###################################
tc qdisc add dev $ext_iface root handle 1:0 htb default 10
tc class add dev $ext_iface parent 1:0 classid 1:1 htb rate 100mbit ceil 100mbit

tc class add dev $ext_iface parent 1:1 classid 1:5 htb rate 100mbit ceil 100mbit prio 0
tc class add dev $ext_iface parent 1:1 classid 1:10 htb rate 48mbit ceil 48mbit prio 0

tc qdisc add dev $ext_iface parent 1:5 handle 5: pfifo limit 5
tc qdisc add dev $ext_iface parent 1:10 handle 10: pfifo limit 10

iptables -t mangle -N shape-in
iptables -t mangle -I POSTROUTING -o $ext_iface -j shape-in

#Priority for pings
iptables -t mangle -A shape-in -p icmp -j MARK --set-mark 5

#Priority for Server Access
iptables -t mangle -A shape-in -s $eiface_addr -j MARK --set-mark 5

#Othet packets (user\'s internet traffic)
iptables -t mangle -A shape-in -m mark --mark 0 -j MARK --set-mark 10

tc filter add dev $ext_iface parent 1:0 prio 0 protocol ip handle 5 fw flowid 1:5
tc filter add dev $ext_iface parent 1:0 prio 1 protocol ip handle 10 fw flowid 1:10

Note that the users will get 48/n channel and there is two Mbs left for a reserve.

share|improve this answer
    
Thank you very much that gave me a chance to learn to use tc. –  Nicolas Bazire Oct 20 '10 at 18:58

What, exactly, is the problem you are having? Are the slower downloaders being starved out completely whenever someone with a fiber line is downloading? Unless that's the case, you should probably just let your server's TCP/IP stack deal with your clients' varying download speeds as best it can. Everyone should eventually get their chunk of your upload.

Also, I believe your notion of 50/n mbps per user as "fair" is misguided. For example, say you have only two users connected, one on fiber capable of 50 mbps download, and the other on dialup at 56 kbps. Do you really want to limit the fiber downloader to just 25 mbps, and basically waste the remaining 25 mbps on the dialup user?

If I were in your position, I wouldn't bother trying to impose this particular notion of "fairness". If you did, it wouldn't be long before users would figure out a way to grab a bigger chunk of your upload bandwidth anyway, by, for example, opening additional connections.

share|improve this answer
    
Your "dial-up vs fiber" example is quite extreme :) Here's a concrete example : 3 users are connected : 1x50mbps and 2x10mbps. Well the last two users with lowest bandwidths are starving, literally : they're downloading at ~2mbps only. I don't really care about "wasting bandwidth" (allowing too much bandwidth for a user that won't reach its limit), the idea is protecting slower downloaders from being "deprived" by faster downloaders because they don't have enough bandwidth. –  Nicolas Bazire Oct 18 '10 at 21:07
    
Thanks for the clarifying example. There are a number of related questions in ServerFault that deal with allocation of bandwidth among multiple concurrent users. Check them out: "QoS - split bandwidth across all IPs during high load"; "how can I limit per user bandwidth?"; "How bandwidth is allocated to concurrent users?" –  Steven Monday Oct 18 '10 at 21:40
    
Thank you for your help Steven, I've read those questions but I thought maybe some "SFTP specific" solution existed. –  Nicolas Bazire Oct 18 '10 at 22:17

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.