mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03: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
					
				
					 2 changed files with 41 additions and 29 deletions
				
			
		| 
						 | 
				
			
			@ -556,8 +556,10 @@ func DEBUG_simLinkPeers(p, q *peer) {
 | 
			
		|||
	goWorkers := func(source, dest *peer) {
 | 
			
		||||
		source.linkOut = make(chan []byte, 1)
 | 
			
		||||
		send := make(chan []byte, 1)
 | 
			
		||||
		source.out = func(bs []byte) {
 | 
			
		||||
			send <- bs
 | 
			
		||||
		source.out = func(bss [][]byte) {
 | 
			
		||||
			for _, bs := range bss {
 | 
			
		||||
				send <- bs
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		go source.linkLoop()
 | 
			
		||||
		go func() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -784,39 +784,49 @@ func (t *switchTable) handleIdle(port switchPort) bool {
 | 
			
		|||
	if to == nil {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	var best string
 | 
			
		||||
	var bestPriority float64
 | 
			
		||||
	var packets [][]byte
 | 
			
		||||
	var psize int
 | 
			
		||||
	t.queues.cleanup(t)
 | 
			
		||||
	now := time.Now()
 | 
			
		||||
	for streamID, buf := range t.queues.bufs {
 | 
			
		||||
		// Filter over the streams that this node is closer to
 | 
			
		||||
		// Keep the one with the smallest queue
 | 
			
		||||
		packet := buf.packets[0]
 | 
			
		||||
		coords := switch_getPacketCoords(packet.bytes)
 | 
			
		||||
		priority := float64(now.Sub(packet.time)) / float64(buf.size)
 | 
			
		||||
		if priority > bestPriority && t.portIsCloser(coords, port) {
 | 
			
		||||
			best = streamID
 | 
			
		||||
			bestPriority = priority
 | 
			
		||||
	for psize < 65535 {
 | 
			
		||||
		var best string
 | 
			
		||||
		var bestPriority float64
 | 
			
		||||
		for streamID, buf := range t.queues.bufs {
 | 
			
		||||
			// Filter over the streams that this node is closer to
 | 
			
		||||
			// Keep the one with the smallest queue
 | 
			
		||||
			packet := buf.packets[0]
 | 
			
		||||
			coords := switch_getPacketCoords(packet.bytes)
 | 
			
		||||
			priority := float64(now.Sub(packet.time)) / float64(buf.size)
 | 
			
		||||
			if priority > bestPriority && t.portIsCloser(coords, port) {
 | 
			
		||||
				best = streamID
 | 
			
		||||
				bestPriority = priority
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if bestPriority != 0 {
 | 
			
		||||
		buf := t.queues.bufs[best]
 | 
			
		||||
		var packet switch_packetInfo
 | 
			
		||||
		// TODO decide if this should be LIFO or FIFO
 | 
			
		||||
		packet, buf.packets = buf.packets[0], buf.packets[1:]
 | 
			
		||||
		buf.size -= uint64(len(packet.bytes))
 | 
			
		||||
		t.queues.size -= uint64(len(packet.bytes))
 | 
			
		||||
		if len(buf.packets) == 0 {
 | 
			
		||||
			delete(t.queues.bufs, best)
 | 
			
		||||
		if bestPriority != 0 {
 | 
			
		||||
			buf := t.queues.bufs[best]
 | 
			
		||||
			var packet switch_packetInfo
 | 
			
		||||
			// TODO decide if this should be LIFO or FIFO
 | 
			
		||||
			packet, buf.packets = buf.packets[0], buf.packets[1:]
 | 
			
		||||
			buf.size -= uint64(len(packet.bytes))
 | 
			
		||||
			t.queues.size -= uint64(len(packet.bytes))
 | 
			
		||||
			if len(buf.packets) == 0 {
 | 
			
		||||
				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 {
 | 
			
		||||
			// Need to update the map, since buf was retrieved by value
 | 
			
		||||
			t.queues.bufs[best] = buf
 | 
			
		||||
			// Finished finding packets
 | 
			
		||||
			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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue