MCPcopy Create free account
hub / github.com/HyBuildNet/quic-relay / NewWorkerPool

Function NewWorkerPool

internal/proxy/pool.go:33–59  ·  view source on GitHub ↗

NewWorkerPool creates a sharded worker pool. workers: number of workers/shards (0 = NumCPU * 2) queueSize: total queue capacity across all shards (0 = 10000)

(workers, queueSize int, handler func(*net.UDPAddr, []byte))

Source from the content-addressed store, hash-verified

31// workers: number of workers/shards (0 = NumCPU * 2)
32// queueSize: total queue capacity across all shards (0 = 10000)
33func NewWorkerPool(workers, queueSize int, handler func(*net.UDPAddr, []byte)) *WorkerPool {
34 if workers <= 0 {
35 workers = runtime.NumCPU() * 2
36 }
37 if queueSize <= 0 {
38 queueSize = 10000
39 }
40
41 queuePerShard := queueSize / workers
42 if queuePerShard < 100 {
43 queuePerShard = 100
44 }
45
46 p := &WorkerPool{
47 queues: make([]chan WorkItem, workers),
48 handler: handler,
49 workers: workers,
50 queuePerShard: queuePerShard,
51 dropped: make([]uint64, workers),
52 }
53
54 for i := 0; i < workers; i++ {
55 p.queues[i] = make(chan WorkItem, queuePerShard)
56 }
57
58 return p
59}
60
61// Start launches all worker goroutines.
62func (p *WorkerPool) Start() {

Callers 7

RunMethod · 0.85
TestWorkerPool_SubmitFunction · 0.85
TestWorkerPool_StopFunction · 0.85
TestWorkerPool_QueueSizeFunction · 0.85

Calls

no outgoing calls

Tested by 6

TestWorkerPool_SubmitFunction · 0.68
TestWorkerPool_StopFunction · 0.68
TestWorkerPool_QueueSizeFunction · 0.68