Submit adds a packet to the appropriate shard's queue. Uses client address hash for affinity (same client -> same worker). Returns false if queue is full (backpressure).
(item WorkItem)
| 78 | // Uses client address hash for affinity (same client -> same worker). |
| 79 | // Returns false if queue is full (backpressure). |
| 80 | func (p *WorkerPool) Submit(item WorkItem) bool { |
| 81 | idx := hashAddr(item.ClientAddr) % uint32(p.workers) |
| 82 | select { |
| 83 | case p.queues[idx] <- item: |
| 84 | return true |
| 85 | default: |
| 86 | atomic.AddUint64(&p.dropped[idx], 1) |
| 87 | if item.Buffer != nil { |
| 88 | handler.PutBuffer(item.Buffer) |
| 89 | } |
| 90 | return false |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Dropped returns total dropped packets across all shards. |
| 95 | func (p *WorkerPool) Dropped() uint64 { |