Class DownloadRateTracker
Measures transfer rate over a trailing time window and estimates remaining time.
public class DownloadRateTracker
- Inheritance
-
DownloadRateTracker
- Inherited Members
Remarks
A sliding window rather than a cumulative average. Dividing total bytes by total elapsed time keeps reporting a healthy rate for minutes after a transfer has actually stalled, because the historical average drags the number up — which is exactly when the player most needs to be told something is wrong. A trailing window converges on zero within FishMMO.Client.DownloadRateTracker.windowSeconds of the last byte arriving.
Time is supplied by the caller rather than read from UnityEngine.Time so this
class stays independent of the engine clock and can be exercised directly.
Constructors
DownloadRateTracker(float)
public DownloadRateTracker(float windowSeconds = 3)
Parameters
windowSecondsfloat
Properties
BytesPerSecond
Most recent rate in bytes per second, or 0 before enough samples exist.
public double BytesPerSecond { get; }
Property Value
Methods
EstimateSecondsRemaining(ulong, long)
Estimates seconds until completion, or null when it cannot be estimated.
public double? EstimateSecondsRemaining(ulong bytesDownloaded, long totalBytes)
Parameters
bytesDownloadedulongCumulative bytes received so far.
totalByteslongExpected total, or 0 when unknown.
Returns
Remarks
Returns null rather than a large number when the rate is zero. An estimate derived from a stalled transfer is not a long estimate, it is no estimate — and showing one implies progress that is not happening.
Reset()
Discards all history. Call before starting a new transfer so a previous download's rate cannot be attributed to it.
public void Reset()
Sample(float, ulong)
Records an observation and recomputes the rate.
public void Sample(float time, ulong bytesDownloaded)