mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 16:00:25 +08:00 
			
		
		
		
	限制读写线程最小值为4,最大值为32
This commit is contained in:
		@@ -7,8 +7,9 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var WriterLimiter = NewLimiter(runtime.NumCPU())
 | 
					var maxThreads = runtime.NumCPU()
 | 
				
			||||||
var ReaderLimiter = NewLimiter(runtime.NumCPU())
 | 
					var WriterLimiter = NewLimiter(maxThreads)
 | 
				
			||||||
 | 
					var ReaderLimiter = NewLimiter(maxThreads)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Limiter struct {
 | 
					type Limiter struct {
 | 
				
			||||||
	threads chan struct{}
 | 
						threads chan struct{}
 | 
				
			||||||
@@ -16,6 +17,13 @@ type Limiter struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewLimiter(threads int) *Limiter {
 | 
					func NewLimiter(threads int) *Limiter {
 | 
				
			||||||
 | 
						if threads < 4 {
 | 
				
			||||||
 | 
							threads = 4
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if threads > 32 {
 | 
				
			||||||
 | 
							threads = 32
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var threadsChan = make(chan struct{}, threads)
 | 
						var threadsChan = make(chan struct{}, threads)
 | 
				
			||||||
	for i := 0; i < threads; i++ {
 | 
						for i := 0; i < threads; i++ {
 | 
				
			||||||
		threadsChan <- struct{}{}
 | 
							threadsChan <- struct{}{}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user