Traffic shaping on Linux with HTB: weird results
- by DADGAD
I'm trying to have some simple bandwidth throttling set up on a Linux server
and I'm running into what seems to be very weird stuff despite a seemingly trivial
config.
I want to shape traffic coming to a specific client IP (10.41.240.240) to a hard
maximum of 75Kbit/s. Here's how I set up the shaping:
# tc qdisc add dev eth1 root handle 1: htb default 1 r2q 1
# tc class add dev eth1 parent 1: classid 1:1 htb rate 75Kbit
# tc class add dev eth1 parent 1:1 classid 1:10 htb rate 75kbit
# tc filter add dev eth1 parent 1:0 protocol ip prio 1 u32 match ip dst
10.41.240.240 flowid 1:10
To test, I start a file download over HTTP from the said client machine and measure the resulting speed by looking at Kb/s in Firefox.
Now, the behaviour is rather puzzling: the DL starts at about 10Kbyte/s and proceeds to pick up speed until it stabilizes at about 75Kbytes/s (Kilobytes, not Kilobits as configured!). Then, If I start several parallel downloads of that very same file, each download stabilizes at about 45Kbytes/s; the combined speed of those downloads thus greatly exceeds the configured maximum.
Here's what I get when probing tc for debug info
[root@kup-gw-02 /]# tc -s qdisc show dev eth1
qdisc htb 1: r2q 1 default 1 direct_packets_stat 1
Sent 17475717 bytes 1334 pkt (dropped 0, overlimits 2782 requeues 0)
rate 0bit 0pps backlog 0b 12p requeues 0
[root@kup-gw-02 /]# tc -s class show dev eth1
class htb 1:1 root rate 75000bit ceil 75000bit burst 1608b cburst 1608b
Sent 14369397 bytes 1124 pkt (dropped 0, overlimits 0 requeues 0)
rate 577896bit 5pps backlog 0b 0p requeues 0
lended: 1 borrowed: 0 giants: 1938
tokens: -205561 ctokens: -205561
class htb 1:10 parent 1:1 prio 0 **rate 75000bit ceil 75000bit** burst 1608b cburst 1608b
Sent 14529077 bytes 1134 pkt (dropped 0, overlimits 0 requeues 0)
**rate 589888bit** 5pps backlog 0b 11p requeues 0
lended: 1123 borrowed: 0 giants: 1938
tokens: -205561 ctokens: -205561
What I can't for the life of me understand is this: how come I get a "rate 589888bit 5pps"
with a config of "rate 75000bit ceil 75000bit"? Why does the effective rate get so much higher than the configured rate? What am I doing wrong? Why is it behaving the way it is?
Please help, I'm stumped. Thanks guys.