5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-10 07:30:27 +00:00

when a link becomes idle and packet are buffered that the link could send, send at least 65535 bytes worth instead of 1 packet, this reduces syscall overhead when small packets are sent through the network

This commit is contained in:
Arceliar 2019-08-18 12:29:07 -05:00
parent 62337bcd64
commit 8af1a7086c
2 changed files with 41 additions and 29 deletions

View File

@ -556,9 +556,11 @@ func DEBUG_simLinkPeers(p, q *peer) {
goWorkers := func(source, dest *peer) { goWorkers := func(source, dest *peer) {
source.linkOut = make(chan []byte, 1) source.linkOut = make(chan []byte, 1)
send := make(chan []byte, 1) send := make(chan []byte, 1)
source.out = func(bs []byte) { source.out = func(bss [][]byte) {
for _, bs := range bss {
send <- bs send <- bs
} }
}
go source.linkLoop() go source.linkLoop()
go func() { go func() {
var packets [][]byte var packets [][]byte

View File

@ -784,10 +784,13 @@ func (t *switchTable) handleIdle(port switchPort) bool {
if to == nil { if to == nil {
return true return true
} }
var best string var packets [][]byte
var bestPriority float64 var psize int
t.queues.cleanup(t) t.queues.cleanup(t)
now := time.Now() now := time.Now()
for psize < 65535 {
var best string
var bestPriority float64
for streamID, buf := range t.queues.bufs { for streamID, buf := range t.queues.bufs {
// Filter over the streams that this node is closer to // Filter over the streams that this node is closer to
// Keep the one with the smallest queue // Keep the one with the smallest queue
@ -812,11 +815,18 @@ func (t *switchTable) handleIdle(port switchPort) bool {
// Need to update the map, since buf was retrieved by value // Need to update the map, since buf was retrieved by value
t.queues.bufs[best] = buf t.queues.bufs[best] = buf
} }
to.sendPackets([][]byte{packet.bytes}) packets = append(packets, packet.bytes)
return true psize += len(packet.bytes)
} else { } else {
return false // Finished finding packets
break
} }
}
if len(packets) > 0 {
to.sendPackets(packets)
return true
}
return false
} }
// The switch worker does routing lookups and sends packets to where they need to be // The switch worker does routing lookups and sends packets to where they need to be