0

I am trying to use tc with HTB to throttle bandwidth used by my containers in bridge network mode. To test the result, I used iperf3.

without throttling, I got the following result:

root@bab903207804:/# iperf3 -c <iperf_server_ip>
Connecting to host <iperf_server_ip>, port 5201
[  4] local 172.17.0.10 port 42906 connected to <iperf_server_ip> port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  96.2 MBytes   807 Mbits/sec    1    399 KBytes
[  4]   1.00-2.00   sec  87.5 MBytes   734 Mbits/sec    1    383 KBytes
[  4]   2.00-3.00   sec  88.8 MBytes   745 Mbits/sec    0    535 KBytes
[  4]   3.00-4.00   sec  88.8 MBytes   744 Mbits/sec    7    503 KBytes
[  4]   4.00-5.00   sec  88.8 MBytes   744 Mbits/sec    0    625 KBytes
[  4]   5.00-6.00   sec  88.8 MBytes   744 Mbits/sec   12    527 KBytes
[  4]   6.00-7.00   sec  88.8 MBytes   745 Mbits/sec    1    513 KBytes
[  4]   7.00-8.00   sec  87.5 MBytes   734 Mbits/sec    0    632 KBytes
[  4]   8.00-9.00   sec  88.8 MBytes   744 Mbits/sec    1    549 KBytes
[  4]   9.00-10.00  sec  88.8 MBytes   744 Mbits/sec    0    660 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec   892 MBytes   749 Mbits/sec   23             sender
[  4]   0.00-10.00  sec   886 MBytes   743 Mbits/sec                  receiver

Which is quite as expected on my 1 Gig NIC. Then I tried to limit the rate to be 50kbps:

sudo tc qdisc add dev docker0 handle 1: root htb default 11
sudo tc class add dev docker0 parent 1: classid 1:1 htb rate 50kbps
sudo tc class add dev docker0 parent 1:1 classid 1:11 htb rate 50kbps

After that, a second iperf test showed reduced rate:

root@bab903207804:/# iperf3 -c <iperf_server_ip>
Connecting to host <iperf_server_ip>, port 5201
[  4] local 172.17.0.10 port 43002 connected to <iperf_server_ip> port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  8.75 MBytes  73.4 Mbits/sec    0    144 KBytes
[  4]   1.00-2.00   sec  2.50 MBytes  21.0 Mbits/sec    0    260 KBytes
[  4]   2.00-3.00   sec  1.25 MBytes  10.5 Mbits/sec    1    245 KBytes
[  4]   3.00-4.00   sec  1.25 MBytes  10.5 Mbits/sec    0    276 KBytes
[  4]   4.00-5.00   sec  2.50 MBytes  21.0 Mbits/sec    0    308 KBytes
[  4]   5.00-6.00   sec  2.50 MBytes  21.0 Mbits/sec    0    327 KBytes
[  4]   6.00-7.00   sec  1.25 MBytes  10.5 Mbits/sec    0    338 KBytes
[  4]   7.00-8.00   sec  2.50 MBytes  21.0 Mbits/sec    0    339 KBytes
[  4]   8.00-9.00   sec  1.25 MBytes  10.5 Mbits/sec    0    339 KBytes
[  4]   9.00-10.00  sec  1.25 MBytes  10.5 Mbits/sec    0    339 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  25.0 MBytes  21.0 Mbits/sec    1             sender
[  4]   0.00-10.00  sec  18.8 MBytes  15.8 Mbits/sec                  receiver

I understand that the rate limit I set is a long term average, but the number still too far away from being convincing.

Then I start an iperf3 server container on the same docker bridge and fired a test client on a remote machine, this time it was pretty accurate:

root@f1ac0ef22798:/# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from <remote_client_ip>, port 38686
[  5] local 172.17.0.9 port 5201 connected to <remote_client_ip> port 38687
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec  49.5 KBytes   405 Kbits/sec
[  5]   1.00-2.00   sec  42.4 KBytes   348 Kbits/sec
[  5]   2.00-3.00   sec  42.4 KBytes   348 Kbits/sec
[  5]   3.00-4.00   sec  48.1 KBytes   394 Kbits/sec
[  5]   4.00-5.00   sec  43.8 KBytes   359 Kbits/sec
[  5]   5.00-6.00   sec  39.6 KBytes   324 Kbits/sec
[  5]   6.00-7.00   sec  45.2 KBytes   371 Kbits/sec
[  5]   7.00-8.00   sec  41.0 KBytes   336 Kbits/sec
[  5]   8.00-9.00   sec  50.9 KBytes   417 Kbits/sec
[  5]   9.00-10.00  sec  43.8 KBytes   359 Kbits/sec
[  5]  10.00-11.00  sec  46.7 KBytes   382 Kbits/sec
[  5]  11.00-12.00  sec  43.8 KBytes   359 Kbits/sec
[  5]  12.00-12.95  sec  42.4 KBytes   366 Kbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-12.95  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-12.95  sec   580 KBytes   367 Kbits/sec                  receiver

So looks like my rate limit is only accurate on inbound traffic. outbound rate is reduced but still way too high. Why is that? How do I limit outbount traffic?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.