Linux – Incoming (ingress) traffic shaping on Linux – bw is lower than expected

iproute2linuxtraffic-shaping

I want to limit incoming (download) speed for Linux box.

Both, the box, which is configured, and trafic source (HTTP server) are connected to the same switch, if shaping is not configured, download speed is 30MBps

I use tc according to http://lartc.org/lartc.html

########## downlink #############
# slow downloads down to somewhat less than the real speed  to prevent 
# queuing at our ISP. Tune to see how high you can set it.
# ISPs tend to have *huge* queues to make sure big downloads are fast
#
# attach ingress policer:

/sbin/tc qdisc add dev $DEV handle ffff: ingress

# filter *everything* to it (0.0.0.0/0), drop everything that's
# coming in too fast:

/sbin/tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
   0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1

But, effective download speed is much less, than configured. Here are results of my experiments

set rate, KBps: real rate, KBps

  • 32 KBps: 30 KBps
  • 64 KBps: 50 KBps
  • 128 KBps: 106 KBps
  • 256 KBps: 160 KBps
  • 512 KBps: 210 KBps
  • 1024 KBps: 255 KBps

For small bandwidth shaping works quite fine, but on 1024 KBit effective bitrate is 75% less, than expected.

Is is possible to effectively limit incoming bandwidth?

Best Answer

bw is lower than expected

I think you have to increase burst as well correspondingly.

Is is possible to effectively limit incoming bandwidth?

I'd say you surely can achieve similar effect dropping packets, instead of receving them. For protos like TCP, which have bandwidth self-tuning mechanisms, it would effectively work. Take a look at http://www.linuximq.net/faq.html