Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues with bandwidth plugin and htb introduction #1097

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions plugins/meta/bandwidth/ifb_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@ const (
UnShapedClassMinorID uint16 = 1
)

func CreateIfb(ifbDeviceName string, mtu int, qlen int) error {
if qlen < 1000 {
qlen = 1000
}
func CreateIfb(ifbDeviceName string, mtu int, _ int) error {
// numtxqueues mismatch between veth and ifb is causing performance issues
// (similar to mismatch between Host-veth0 and Container peer: https://github.com/torvalds/linux/blob/9d3684c24a5232c2d7ea8f8a3e60fe235e6a9867/drivers/net/veth.c#L1199-L1206)
// do not enable until netlink library offer setting numtxqueues on a ifb device
// if qlen < 1000 {
// qlen = 1000
// }

linkAttrs := netlink.NewLinkAttrs()
linkAttrs.Name = ifbDeviceName
linkAttrs.Flags = net.FlagUp
linkAttrs.MTU = mtu
// linkAttrs.TxQLen = qlen

err := netlink.LinkAdd(&netlink.Ifb{
LinkAttrs: netlink.LinkAttrs{
Name: ifbDeviceName,
Flags: net.FlagUp,
MTU: mtu,
TxQLen: qlen,
},
LinkAttrs: linkAttrs,
})
if err != nil {
return fmt.Errorf("adding link: %s", err)
Expand Down Expand Up @@ -75,7 +79,7 @@ func CreateIngressQdisc(rateInBits, burstInBits uint64, excludeSubnets []string,
exclude = true
}

return createHTB(rateInBits, burstInBits, hostDevice.Attrs().Index, subnets, exclude)
return createHTB(rateInBits, burstInBits, hostDevice.Attrs().MTU, hostDevice.Attrs().Index, subnets, exclude)
}

func CreateEgressQdisc(rateInBits, burstInBits uint64, excludeSubnets []string, includeSubnets []string, hostDeviceName string, ifbDeviceName string) error {
Expand Down Expand Up @@ -134,15 +138,15 @@ func CreateEgressQdisc(rateInBits, burstInBits uint64, excludeSubnets []string,
}

// throttle traffic on ifb device
err = createHTB(rateInBits, burstInBits, ifbDevice.Attrs().Index, subnets, exclude)
err = createHTB(rateInBits, burstInBits, ifbDevice.Attrs().MTU, ifbDevice.Attrs().Index, subnets, exclude)
if err != nil {
// egress from the container/netns pov = ingress from the main netns/host pov
return fmt.Errorf("create htb container egress qos rules: %s", err)
}
return nil
}

func createHTB(rateInBits, burstInBits uint64, linkIndex int, subnets []string, excludeSubnets bool) error {
func createHTB(rateInBits, burstInBits uint64, mtu int, linkIndex int, subnets []string, excludeSubnets bool) error {
// Netlink struct fields are not clear, let's use shell

defaultClassID := UnShapedClassMinorID
Expand All @@ -160,7 +164,7 @@ func createHTB(rateInBits, burstInBits uint64, linkIndex int, subnets []string,
Parent: netlink.HANDLE_ROOT,
},
Defcls: uint32(defaultClassID),
// No idea what these are so let's keep the default values from source code...
// Keep the default values from source code
Version: 3,
Rate2Quantum: 10,
}
Expand All @@ -184,6 +188,12 @@ func createHTB(rateInBits, burstInBits uint64, linkIndex int, subnets []string,
Handle: netlink.MakeHandle(1, ShapedClassMinorID),
Parent: netlink.MakeHandle(1, 0),
},
// maximum bytes per cycle to dequeue, kernel is warning and limiting unreasonable values
// should be set to MTU + hardware header length of 14 bytes to avoid bursts which may cause subsequent txqueuelen drops
// https://github.com/torvalds/linux/blob/baeb9a7d8b60b021d907127509c44507539c15e5/net/sched/sch_htb.c#L2037
// https://github.com/torvalds/linux/blob/baeb9a7d8b60b021d907127509c44507539c15e5/net/sched/sch_htb.c#L2052-L2055
Quantum: uint32(mtu + 14),

Rate: rateInBytes,
Buffer: bufferInBytes,
// Let's set up the "burst" rate to twice the specified rate
Expand All @@ -206,8 +216,15 @@ func createHTB(rateInBits, burstInBits uint64, linkIndex int, subnets []string,
Handle: netlink.MakeHandle(1, UnShapedClassMinorID),
Parent: qdisc.Handle,
},
// maximum bytes per cycle to dequeue, kernel is warning and limiting unreasonable values
// should be set to MTU + hardware header length of 14 bytes to avoid bursts which may cause subsequent txqueuelen drops
// https://github.com/torvalds/linux/blob/baeb9a7d8b60b021d907127509c44507539c15e5/net/sched/sch_htb.c#L2037
// https://github.com/torvalds/linux/blob/baeb9a7d8b60b021d907127509c44507539c15e5/net/sched/sch_htb.c#L2052-L2055
Quantum: uint32(mtu + 14),

Rate: bigRate,
Ceil: bigRate,

// No need for any burst, the minimum buffer size in q_htb.c should be enough to handle the rate which
// is already more than enough
}
Expand Down