Xen limit incoming traffic speed

bandwidth-controlxen

I've tried using 'rate' to limit the traffic speed of a VM inside the config file but that only limits the outgoing traffic speed of traffic from the VM. I want to limit the speed traffic can flow both ways.

Thanks

Best Answer

I use XEN 4.2.2 at the time of this reply.

  • Remove rate=X from your guest config file and shut it down.
  • Make sure your kernel have at least the following enabled:
  • IP: advanced router
  • TCP: advanced congestion control (all options enabled)
  • QoS and/or fair queueing (all options enabled expect the debug ones)
  • Install 'tc' command
  • Verify it's working by running: tc -s qdisc ls dev eth0

If you get no errors, you're ready to modify /etc/xen/scripts/vif-bridge

Find this word 'online)'

Just add before ;;

tc qdisc add dev "$dev" root tbf rate 120mbit burst 20mbit latency 5ms peakrate 125mbit minburst 20mbit mpu 64

So the modified version of vif-bridge should look like this:

online)        
        setup_virtual_bridge_port "$dev"

        mtu="`ip link show $bridge | awk '/mtu/ { print $5 }'`"

        if [ -n "$mtu" ] && [ "$mtu" -gt 0 ]

        then

                ip link set $dev mtu $mtu || :

        fi         

        add_to_bridge "$bridge" "$dev"

        tc qdisc add dev "$dev" root tbf rate 120mbit burst 20mbit latency 5ms peakrate 125mbit minburst 20mbit mpu 64

        ;;

Find this word 'offline)'

Append to first line: do_without_error tc qdisc del dev "$dev" root

offline)
        do_without_error tc qdisc del dev "$dev" root

        do_without_error brctl delif "$bridge" "$dev"

        do_without_error ifconfig "$dev" down

        ;;

Using the above TBF rule your guest should have roughly 12.5MB/s upload and 14.0M/s download speed; a bit over 120Mbps

If you upload/download same time, both upload and download speed should be about 7.5MB/s ~ 150Mbps total bandwidth

This is what I got after an hour tweaking. If you find better values; please let us know