Class MainThreadQueueHelper
- Namespace
- FishMMO.Server.Implementation
- Assembly
- FishMMO.Server.dll
Shared utility for main-thread queue drain and enqueue operations. Eliminates copy-paste boilerplate across server systems (D1).
Back-pressure observability: the underlying
MainThreadQueueData enforces a hard capacity cap (currently
10,000 pending actions) and returns false from TryEnqueue
when full. Most call sites discard that bool because there is no useful
off-thread fallback — the response broadcast is already on the main
thread by contract. To keep the loss visible to operators, every
rejected enqueue is counted here in a per-queue-type drop counter and
surfaced through a rate-limited warning. A sustained non-zero drop rate
indicates the main thread is stalling long enough for async DB workers
to saturate the queue (10K * 16 ms drain budget ≈ several seconds of
hang) and is a stronger DoS / GC-pause signal than any individual
client time-out.
public static class MainThreadQueueHelper
- Inheritance
-
MainThreadQueueHelper
- Inherited Members
Methods
Drain<TQueue>(IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>, int, bool)
Drains the main-thread queue, processing up to maxActions (or all if drainAll is true).
public static void Drain<TQueue>(IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour> server, int maxActions, bool drainAll) where TQueue : class, IMainThreadQueueData
Parameters
serverIServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>Server instance (null-safe).
maxActionsintMaximum actions to drain per call.
drainAllboolIf true, drains all queued actions regardless of maxActions.
Type Parameters
TQueueThe specific IMainThreadQueueData subtype for this system.
GetDroppedCount<TQueue>()
Returns the running total of rejected enqueues for the specified queue type since process start. Intended for metrics scrape / health endpoints.
public static long GetDroppedCount<TQueue>() where TQueue : class, IMainThreadQueueData
Returns
Type Parameters
TQueue
TryEnqueue<TQueue>(IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>, Action)
Enqueues an action on the main-thread queue. Returns false if the queue is at capacity or unavailable. On rejection, increments a per-queue-type drop counter and emits a rate-limited warning so operators can detect sustained main-thread back-pressure that would otherwise present only as silent client time-outs.
public static bool TryEnqueue<TQueue>(IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour> server, Action action) where TQueue : class, IMainThreadQueueData
Parameters
serverIServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>Server instance (null-safe).
actionActionThe action to enqueue.
Returns
- bool
True if enqueued successfully; false if queue full or unavailable.
Type Parameters
TQueueThe specific IMainThreadQueueData subtype for this system.