Table of Contents

Class ServerBandwidthRecorder

Namespace
FishMMO.Server.Implementation
Assembly
FishMMO.Server.dll

Writes one row a minute of what this server process sent and received to server_bandwidth_minute, for the Control Panel's bandwidth page.

public sealed class ServerBandwidthRecorder
Inheritance
ServerBandwidthRecorder
Inherited Members

Remarks

One per process, owned by the tier's system. LoginServerSystem, WorldServerSystem and SceneServerSystem each start one when they finish initialising and stop it when they deinitialise. It is a plain helper rather than a ServerBehaviour so that no server scene needs another asset in its behaviour list, and so the three tiers cannot drift apart.

The source is the transport's own counters (FishNet.Transporting.WebTransport.TransportTraffic.Capture(out FishNet.Transporting.WebTransport.TransportTrafficSnapshot)): FishNet bytes counted by the WebTransport socket, and msquic's process-wide UDP payload and datagram counts, which include the handshakes and refused connections that never became a session — exactly what an operator pays egress for. FishNet's StatisticsManager is disabled on servers and is not used.

Nothing runs on the main thread but the timer. Every 60 seconds the periodic system hands one unit of work to the async worker; that work reads the database clock, captures the counters (allocation-free, any thread), files the interval in the ServerBandwidthLedger and writes every pending minute in one SET-upsert. A unit is single-flight: while one is still running the next tick is skipped, and because the counters are cumulative the following sample simply covers the longer interval.

A failure never double-counts, never blocks, and is never silent. A failed clock read defers the sample (nothing is lost). A failed write keeps its minutes pending and they are re-sent with the next sample — safe, because the write is a SET of each minute's running total, keyed before the retried delegate runs. Only after MaxPendingMinutes minutes of failures are the oldest dropped, and the drop is logged with its count. Faults go through one RepeatingFaultLog, so a database that is down for an hour logs its first error in full, a summary every fifteen minutes and one recovery line.

Fields

FinalSampleTimeoutMs

The longest the final sample at shutdown may block the main thread.

public const int FinalSampleTimeoutMs = 1500

Field Value

int

SampleIntervalSeconds

Seconds between samples. One row per minute is the table's grain.

public const float SampleIntervalSeconds = 60

Field Value

float

ShutdownReserveMs

Shutdown budget the final sample leaves for everything else. The budget (BeginShutdownBudget(int)) is shared by every behaviour's teardown, and character saves matter more than the last partial minute of bandwidth, so the final sample is skipped rather than allowed to eat into this.

public const int ShutdownReserveMs = 4000

Field Value

int

Properties

InstanceId

The id every row this process writes carries.

public Guid InstanceId { get; }

Property Value

Guid

Methods

KindOf(ServerType)

The stored tier number for a server type; 0 for anything else.

public static int KindOf(ServerType type)

Parameters

type ServerType

Returns

int

Stop()

Stops the timer and takes one last sample, bounded, so the minute the process stopped in is not lost. Main thread, from the owning system's OnDeinitialize.

public void Stop()

Remarks

Called after the transport has stopped, so the sample includes the disconnects; the native counters survive the library's deinitialisation (they are carried), so the capture is still measured. Skipped, with a line in the log, when a write is still running past the timeout or the shutdown budget is too low to spare — the budget belongs to the character saves first.

TryStart(IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>, ServerType)

Starts recording for this process, or returns null (having logged why) when it cannot: no configured ServerName to key the rows by, no bandwidth service, or no periodic system.

public static ServerBandwidthRecorder TryStart(IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour> server, ServerType type)

Parameters

server IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>

The server this process runs.

type ServerType

Its tier.

Returns

ServerBandwidthRecorder