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

Lets say I have 3 queues (# indicates data):

Q1: (in)[            ###](out)
Q2: (in)[          #####](out) 
Q3: (in)[  #############](out)

Lets say I put all my ICMP packets in Q1 and all the constant downloads in Q3.

How do I use the tc command (from iproute2) to empty Q1 when it has data, and ignore the other 2 queues?

Currently I'm limiting the rate of Q3, but this feels quite crude. I'd like Q3 to download at full rate at times when Q1 has no traffic.

Is this possible?

Update: See my version 1 of my QoS script.

Update 2: I have further updated my script (see version 2), but I've changed ISP since to one that does not do QoS at their end (so no need for the dynamic speed changes). I have however, added -u and -d args so I can change my up/down limits without needing to edit the script. The problem with this script is that the queue speeds never reach the value of ceil; they only ever reach rate - which I believe is not supposed to happen.

Update 3: I have no idea why, but version 3 of my QoS script works! If someone could explain why, that'd be great... I've only made very minor changes; I can't see how what I did made it work... I altered the burst settings after I discovered it was working.

share|improve this question
add comment

3 Answers

Nice Script, I like the part with the time depended dynamic download speed. ;) Anyway, I am doing excactly what you want. I did it with htb, but switched a few months ago to hfsc. The trick is to limit q3 with rate to a very low rate, but give it with ceil the full bandwith. q1 on the other hand gets a higher rate and the same ceil. One realworld example:

tc class add dev ppp0 parent 1: classid 1:1 htb rate 100kbps ceil 100kbps
tc class add dev ppp0 parent 1:1 classid 1:10 htb rate 60kbps ceil 100kbps prio 1 
tc class add dev ppp0 parent 1:1 classid 1:11 htb rate 39kbps ceil 100kbps prio 2 
tc class add dev ppp0 parent 1:1 classid 1:12 htb rate 1kbps ceil 100kbps prio 3

Q1 would be 1:10

Q2 would be 1:11

Q3 would be 1:12

Maybe your problem lies within your sophisticated script. Try a more lightweight version for debbuging.

tc -s -d class show dev <interface> should show some stats about the queues. Let´s show us the output if q1 has nothing to do and q3 doesn´t use the full bandwith. Also you could give hfsc a try.

One Remark: QOS or Traffic Control on your incoming traffic is pretty useless in most configurations. Typically you are in a reciever role who has no power over recieving what amount of data/time. You could use Ingress-Queueing but it won´t help much, it only discardes already recieved packets.

That is not as bad as it sounds because most dial-in connections are nowadays asymetric, which means that the transmitting direction is the bottleneck. (Always from your point of view)

share|improve this answer
When I use kbps instead of kbit, it says: Illegal "rate" -- here's an example: htb rate 400kbps ceil 500kbps burst 300k prio 3 –  nbolton Dec 5 '09 at 19:05
Also, using this example (with kbit), it limits the traffic at 300kbit and never reaches the ceil speed: htb rate 400kbit ceil 500kbit burst 300k prio 3 –  nbolton Dec 5 '09 at 19:06
add comment

Look into use of "priority", "rate", and "ceil".

You should be able to basically give Q3 a low rate (and high ceiling)...and Q1 a "lower" priority (which makes it actually more important). What this should do is give Q1 the predominant bandwidth...when its not in use...Q3 should then be raised to its ceiling (as its not as important).

share|improve this answer
When I do this, Q3 seems to be limited to rate, and only ever hits ceil if I use burst. I haven't tried with priority yet - would this automatically increase the allowed rate of Q3? –  nbolton Nov 9 '09 at 12:01
I looked into the use of priority - and added prio to my htb classes ranging from 0 to 2, but this seems to do absolutely nothing... Any ideas? –  nbolton Nov 9 '09 at 16:46
Throw the lines you're using in the comments. W/o them i'm guessing as to what you are using wrt parents, etc. –  user6373 Nov 9 '09 at 18:42
Sure, I'll use pastebin though as it's a little hairy. –  nbolton Nov 10 '09 at 11:01
add comment
up vote 0 down vote accepted

Here's my working version: qos-v3.sh

This even works on QoS for downloads too; but it takes a short while to "stabilize". This is because, as I understand it, the servers will still try and send to you at the maximum possible speed - but because the QoS script is dropping packets, the incoming connection will often slow down the rate at which it sends packets (until packets stop getting dropped).

Like 7 of 9 would say: crude but effective (oh god, I didn't...)

share|improve this answer
add comment

Your Answer


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.