From e6a47f705da746372e53620132b37e0f43101525 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Fri, 6 Jul 2018 00:11:36 -0500 Subject: [PATCH] when dropping a queue, select one at random based on queue size in bytes --- src/yggdrasil/switch.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 1a0e781..f47526f 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -12,6 +12,7 @@ package yggdrasil // A little annoying to do with constant changes from backpressure import ( + "math/rand" "sync" "sync/atomic" "time" @@ -624,7 +625,13 @@ func (b *switch_buffers) cleanup(t *switchTable) { const maxSize = 4 * 1048576 // Maximum 4 MB for b.size > maxSize { // Drop a random queue - for streamID := range b.bufs { + target := rand.Uint64() % b.size + var size uint64 // running total + for streamID, buf := range b.bufs { + size += buf.size + if size < target { + continue + } remove(streamID) break }