Concurrency Gate¶
ConcurrencyGate limits how many handlers for a given opcode may execute at the same time.
Source mapping¶
src/Nalix.Network/Throttling/ConcurrencyGate.cs
What it does¶
- keeps a separate entry per opcode
- uses per-opcode semaphores
- optionally queues waiting work
- cleans up idle opcode entries
- trips a breaker when rejection pressure stays too high
Basic usage¶
Most commonly it is driven by metadata:
[PacketConcurrencyLimit(4, queue: true, queueMax: 32)]
public async Task HandleUpload(MyPacket packet, IConnection connection) { }
Imperative usage is also possible:
using var lease = await gate.EnterAsync(
opCode,
new PacketConcurrencyLimitAttribute(4, queue: true, queueMax: 32),
ct);
Queue behavior¶
queue: falsemeans fail fastqueue: truemeans wait for a slotqueueMaxlimits how much waiting work can accumulate
Diagnostics¶
GenerateReport() includes:
- acquired, rejected, queued, and cleaned totals
- breaker status
- tracked opcode count
- per-opcode capacity and queue depth