Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why tc cannot do ingress shaping? Does ingress shaping make sense?

In my work, I found tc can do egress shaping, and can only do ingress policing. I wonder that why tc doesn't implement ingress shaping?

Code sample:

#ingress
tc qdisc add dev eth0 handle ffff: ingress
tc filter add dev eth0 parent ffff: protocol ip prio 50 \
   u32 match ip src 0.0.0.0/0 police rate 256kbit \
   burst 10k drop flowid :1
#egress
tc qdisc add dev eth0 root tbf \
   rate 256kbit latency 25ms burst 10k

But I can't do this:

#ingress shaping, using tbf
tc qdisc add dev eth0 ingress tbf \
   rate 256kbit latency 25ms burst 10k

I found a solution called IFB(updated IMQ) can redirect the traffic to egress. But it seems not a good solution because it's wasting CPU. So I don't want to use this.

Does ingress shaping make sense? And why tc doesn't support it?

like image 810
damn_c Avatar asked Apr 08 '13 14:04

damn_c


2 Answers

Although tc shaping rules for ingress are very limited, you can create a virtual interface and apply egress rules to it, as described here:

https://serverfault.com/questions/350023/tc-ingress-policing-and-ifb-mirroring

(You may not need the virtual interface if your VMs already use virtual interfaces and you can apply tc to them.)

The caveat with ingress shaping is that it may take a long time for an incoming stream to respond to your shaping actions, due to all the buffers in routers between the stream source and your interface. And until the stream does respond to a reduced limit, it will continue to flood your downstream! Meanwhile you will be throwing away good packets, reducing your throughput.

Likewise when a high-priority stream ends or drops off, it will take some time for the low-priority stream to grow back to its full rate. This can be quite disruptive if it happens often!

The result of this is that dynamic shaping may work as desired for groups of steady rate long-lived streams, but will offer little advantage to short-lived or varying rate high-priority streams when your downstream is flooded: the low-priority streams will simply take too long to back off. However classifying and limiting low and medium-priority packets to a static rate somewhere below your maximum downrate could be helpful, to guarantee at least some space for high-priority data.

I don't have any figures on this, and latency has improved a lot since the ADSL days. So I think it may be worth testing, if low latency or high throughput of high-priority packets is something you desire more than overall throughput, and you can live with the limitations above.

As Janoszen and the ADSL HOWTO mention, streams could respond much more quickly if we could adjust the TCP window size as part of the shaping.

Search TLDP for further research.

like image 100
joeytwiddle Avatar answered Oct 14 '22 01:10

joeytwiddle


Shaping works on the send buffer. Ingress shaping would require control over the remote send buffer.

like image 24
Janos Pasztor Avatar answered Oct 14 '22 02:10

Janos Pasztor