Skip to content

Commit

Permalink
Fix burst of PacketInQueue (#5456)
Browse files Browse the repository at this point in the history
The burst was not effective because the number of tokens was hardcoded
to 1, leading to 10ms delay when processing every successive DNS
response. For example, in some scenario it takes a client 10 DNS queries
to get a valid DNS response, the later 9 DNS responses would be delayed
90ms in total. This affected the DNS resolution delay when a Pod has any
FQDN policy applied.

This commit fixes the burst setting of the PacketInQueue. The connection
time of accessing a FQDN is reduced from 134ms to 41ms according to my
test.

Signed-off-by: Quan Tian <qtian@vmware.com>
  • Loading branch information
tnqn authored Aug 31, 2023
1 parent ab72727 commit 4ccd785
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/ovs/openflow/ofctrl_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ type PacketInQueue struct {
}

func NewPacketInQueue(size int, r rate.Limit) *PacketInQueue {
return &PacketInQueue{rateLimiter: rate.NewLimiter(r, 1), packetsCh: make(chan *ofctrl.PacketIn, size)}
return &PacketInQueue{rateLimiter: rate.NewLimiter(r, size), packetsCh: make(chan *ofctrl.PacketIn, size)}
}

func (q *PacketInQueue) AddOrDrop(packet *ofctrl.PacketIn) bool {
Expand Down
10 changes: 10 additions & 0 deletions pkg/ovs/openflow/ofctrl_bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,13 @@ func TestOFMeterStats(t *testing.T) {
return packetCounts[1] == int64(100) && packetCounts[2] == int64(0)
}, 2*time.Second, 50*time.Millisecond)
}

func TestPacketInQueue(t *testing.T) {
burst := 200
q := NewPacketInQueue(burst, rate.Limit(100))
for i := 0; i < burst; i++ {
assert.True(t, q.AddOrDrop(nil), "Packet should not be dropped before reaching the burst")
}
assert.False(t, q.AddOrDrop(nil), "Packet should be dropped after reaching the burst")
assert.Equal(t, float64(burst), q.rateLimiter.Tokens())
}

0 comments on commit 4ccd785

Please sign in to comment.