mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 16:55:40 +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:
parent
62337bcd64
commit
8af1a7086c
@ -556,8 +556,10 @@ 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) {
|
||||||
send <- bs
|
for _, bs := range bss {
|
||||||
|
send <- bs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
go source.linkLoop()
|
go source.linkLoop()
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -784,39 +784,49 @@ 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 streamID, buf := range t.queues.bufs {
|
for psize < 65535 {
|
||||||
// Filter over the streams that this node is closer to
|
var best string
|
||||||
// Keep the one with the smallest queue
|
var bestPriority float64
|
||||||
packet := buf.packets[0]
|
for streamID, buf := range t.queues.bufs {
|
||||||
coords := switch_getPacketCoords(packet.bytes)
|
// Filter over the streams that this node is closer to
|
||||||
priority := float64(now.Sub(packet.time)) / float64(buf.size)
|
// Keep the one with the smallest queue
|
||||||
if priority > bestPriority && t.portIsCloser(coords, port) {
|
packet := buf.packets[0]
|
||||||
best = streamID
|
coords := switch_getPacketCoords(packet.bytes)
|
||||||
bestPriority = priority
|
priority := float64(now.Sub(packet.time)) / float64(buf.size)
|
||||||
|
if priority > bestPriority && t.portIsCloser(coords, port) {
|
||||||
|
best = streamID
|
||||||
|
bestPriority = priority
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if bestPriority != 0 {
|
||||||
if bestPriority != 0 {
|
buf := t.queues.bufs[best]
|
||||||
buf := t.queues.bufs[best]
|
var packet switch_packetInfo
|
||||||
var packet switch_packetInfo
|
// TODO decide if this should be LIFO or FIFO
|
||||||
// TODO decide if this should be LIFO or FIFO
|
packet, buf.packets = buf.packets[0], buf.packets[1:]
|
||||||
packet, buf.packets = buf.packets[0], buf.packets[1:]
|
buf.size -= uint64(len(packet.bytes))
|
||||||
buf.size -= uint64(len(packet.bytes))
|
t.queues.size -= uint64(len(packet.bytes))
|
||||||
t.queues.size -= uint64(len(packet.bytes))
|
if len(buf.packets) == 0 {
|
||||||
if len(buf.packets) == 0 {
|
delete(t.queues.bufs, best)
|
||||||
delete(t.queues.bufs, best)
|
} else {
|
||||||
|
// Need to update the map, since buf was retrieved by value
|
||||||
|
t.queues.bufs[best] = buf
|
||||||
|
}
|
||||||
|
packets = append(packets, packet.bytes)
|
||||||
|
psize += len(packet.bytes)
|
||||||
} else {
|
} else {
|
||||||
// Need to update the map, since buf was retrieved by value
|
// Finished finding packets
|
||||||
t.queues.bufs[best] = buf
|
break
|
||||||
}
|
}
|
||||||
to.sendPackets([][]byte{packet.bytes})
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user