mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	when dropping a queue, select one at random based on queue size in bytes
This commit is contained in:
		
							parent
							
								
									1a65c065d0
								
							
						
					
					
						commit
						e6a47f705d
					
				
					 1 changed files with 8 additions and 1 deletions
				
			
		| 
						 | 
					@ -12,6 +12,7 @@ package yggdrasil
 | 
				
			||||||
//  A little annoying to do with constant changes from backpressure
 | 
					//  A little annoying to do with constant changes from backpressure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"math/rand"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"sync/atomic"
 | 
						"sync/atomic"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
| 
						 | 
					@ -624,7 +625,13 @@ func (b *switch_buffers) cleanup(t *switchTable) {
 | 
				
			||||||
	const maxSize = 4 * 1048576 // Maximum 4 MB
 | 
						const maxSize = 4 * 1048576 // Maximum 4 MB
 | 
				
			||||||
	for b.size > maxSize {
 | 
						for b.size > maxSize {
 | 
				
			||||||
		// Drop a random queue
 | 
							// 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)
 | 
								remove(streamID)
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue