Table of Contents

Class MemoryLearner

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

Works out a server's next heap ceiling from the runs the app has seen of it. Pure.

public static class MemoryLearner
Inheritance
MemoryLearner
Inherited Members

Remarks

The estimate a server starts with is generous on purpose (a ceiling is a limit, not a reservation), but a generous ceiling still counts against the machine's budget, and a server that only ever holds a gigabyte alive does not need four. What it keeps alive after a collection, over the last runs, is what it needs; 1.6 times that leaves room for the load it has not met yet.

  • A run counts when it lasted 20 minutes, had a player on, and its live heap stayed under 85 % of its ceiling. A run that reached 85 % was held back by the ceiling, so what it shows is the ceiling and not the need: it is treated as pressure.
  • The next ceiling is 1.6 × the 95th percentile of the peak live heap of the last ten runs that count, rounded up to 512 MB, never below the floor.
  • It goes down slowly: only with at least three runs that count, and by at most 1 GB per start. Underestimating costs far more than overestimating (out of memory kills the server; a high ceiling costs nothing until it is used).
  • It goes up at once: after running out of memory, ×1.5; after any other pressure, 1 GB more or ×1.25, whichever is more. This also covers the restart after a crash.

Fields

LimitedShare

The share of the ceiling from which a run was held back by it.

public const double LimitedShare = 0.85

Field Value

double

MaxLowerMb

The most the ceiling goes down at one start, in MB.

public const long MaxLowerMb = 1024

Field Value

long

MinimumRun

The shortest run that counts.

public static readonly TimeSpan MinimumRun

Field Value

TimeSpan

RunsLookedAt

How many of the latest counting runs are looked at.

public const int RunsLookedAt = 10

Field Value

int

RunsToLower

The fewest counting runs for the ceiling to go down.

public const int RunsToLower = 3

Field Value

int

Methods

AfterPressure(long, bool)

The ceiling a running server would get at its next start if it were found short of memory now: what the band says it will have.

public static long AfterPressure(long ceilingMb, bool outOfMemory)

Parameters

ceilingMb long
outOfMemory bool

Returns

long

Counts(MemorySession)

True when a run says what the server needs.

public static bool Counts(MemorySession s)

Parameters

s MemorySession

Returns

bool

Next(IReadOnlyList<MemorySession>, long, long)

The ceiling to start with, or null when the history says nothing yet and the estimate stands.

public static LearnedCeiling? Next(IReadOnlyList<MemorySession> sessions, long floorMb, long estimateMb)

Parameters

sessions IReadOnlyList<MemorySession>

The server's runs, oldest first.

floorMb long

The lowest ceiling the app ever gives this server.

estimateMb long

What it would start with with no history.

Returns

LearnedCeiling

WasLimited(MemorySession)

True when a run was short of memory: it ran out, was held back by its ceiling, or the app judged it so.

public static bool WasLimited(MemorySession s)

Parameters

s MemorySession

Returns

bool