Skip to main content

engine.solvers.durability

engine.solvers.durability

Durable-execution solvers: what a runtime pays to survive a crash (added 2026-10-20).

Domain implementations behind mlsysim.solvers. Each model is arithmetic on stated inputs: one group commit’s work and waits, the bytes full snapshots and deltas write, checkpoint strides priced on a fixed crash trace with Young’s balance in turns, and the cost of keeping a trajectory’s recovery and replay data. None models a particular storage engine or workflow runtime.

Classes

Name Description
CheckpointTraceModel Checkpoint strides priced on one fixed crash trace, against Young’s balance in turns.
GroupCommitModel Storage work per record against the wait each record sees in one group commit.
RetentionCostModel What keeping one trajectory’s recovery and replay data costs, against one attempt.
SnapshotVolumeModel Bytes written by full snapshots and by deltas over one monotonically growing trajectory.

CheckpointTraceModel

engine.solvers.durability.CheckpointTraceModel()

Checkpoint strides priced on one fixed crash trace, against Young’s balance in turns.

A policy checkpoints at every multiple of its stride (and at the final turn). A crash after turn c restores the last checkpoint and rebuilds the c mod stride turns since it from the log; the policy’s total is its checkpoint pauses plus the restores plus the rebuilt turns. The balance stride sqrt(2 pause / (rate * cost)) uses the trace’s crash rate, once with the cost of rebuilding a logged turn and once with the cost of re-executing an unlogged one.

Methods

Name Description
solve Price checkpoint strides on a supplied crash trace.
solve
engine.solvers.durability.CheckpointTraceModel.solve(
    turns,
    crashes,
    strides,
    pause,
    restore,
    rebuild_per_turn,
    reexecute_per_turn,
)

Price checkpoint strides on a supplied crash trace.

Parameters
Name Type Description Default
turns int Positive trajectory length in turns. required
crashes sequence of int Nonempty crash positions in [0, turns], interpreted after the indicated turn. required
strides sequence of int Nonempty positive checkpoint spacings to compare. required
pause Quantity Positive pause to capture one checkpoint. required
restore Quantity Nonnegative fixed restore time per crash. required
rebuild_per_turn Quantity Positive time to rebuild one lost turn from a log. required
reexecute_per_turn Quantity Positive time to re-execute one lost turn without the log. required
Returns
Name Type Description
CheckpointTraceResult Per-stride pause/recovery/total seconds and lost-turn counts, cheapest candidate, and continuous balance strides in turns.
See Also

mlsysim.physics.reliability.calc_checkpoint_stride : Compute the continuous pause/rework balance.

Notes

Equation: Lost turns at crash c for stride k = c mod k. Total time equals checkpoint_count*pause + crash_count*restore + lost_turns*rebuild. Continuous balance stride = sqrt(2*pause/(crash_rate*turn_cost)).

Assumptions: Every candidate sees the same trace; capture occurs at stride multiples and at the final turn. The balance uses crashes/turns as a rate.

Excludes: Failures during checkpoint or recovery, checkpoint corruption, and a probabilistic guarantee about future traces.

References

Young (1974), “A first order approximation to the optimum checkpoint interval.” https://doi.org/10.1145/361147.361115 (bibliography key: young1974). The continuous balance minimizes pause/k + crash_rate*turn_cost*k/2.

Derivation: Count every scheduled pause, fixed restore, and rebuilt turn on the supplied trace. For the continuous comparison, minimizing pause/k + crash_rate*turn_cost*k/2 gives the square-root balance; this is a separate expected-loss approximation, not the discrete trace optimum.

Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim.solvers import CheckpointTraceModel
>>> r = CheckpointTraceModel().solve(8, [3], [1, 2], Q_(1, "s"),
...     Q_(1, "s"), Q_(1, "s"), Q_(2, "s"))
>>> assert r.best_stride in r.total_time

GroupCommitModel

engine.solvers.durability.GroupCommitModel()

Storage work per record against the wait each record sees in one group commit.

One flush acknowledges batch_size records; the work charged to each falls as flush / batch_size, but every record still waits the whole flush, and the first arrival also waits the batch timer. Amortization raises throughput; it never shortens one record’s wait.

Methods

Name Description
solve Separate amortized flush work from the first and last record waits.
solve
engine.solvers.durability.GroupCommitModel.solve(
    batch_timer,
    flush_time,
    batch_size,
)

Separate amortized flush work from the first and last record waits.

Parameters
Name Type Description Default
batch_timer Quantity Nonnegative collection interval before the flush begins. required
flush_time Quantity Nonnegative duration of one synchronous flush. required
batch_size int Positive record count acknowledged by the flush. required
Returns
Name Type Description
GroupCommitResult Amortized work per record and first/last record waits, all time quantities.
See Also

mlsysim.physics.reliability.calc_group_commit_waits : Compute the amortized work and per-arrival waits.

Notes

Equation: Work per record = flush_time/batch_size; first wait = timer + flush; last wait = flush_time.

Assumptions: The first record arrives when collection starts and the last arrives when the flush begins; one flush acknowledges the whole batch.

Excludes: Queueing between groups, variable flush duration, and partial acknowledgments.

References

Derivation: Divide the shared flush work among the acknowledged records. The first arrival waits for collection and flushing; the last arrival waits only for flushing, independent of that amortized work.

Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim.solvers import GroupCommitModel
>>> r = GroupCommitModel().solve(Q_(1, "ms"), Q_(2, "ms"), 4)
>>> assert r.first_wait >= r.last_wait >= r.work_per_record

RetentionCostModel

engine.solvers.durability.RetentionCostModel()

What keeping one trajectory’s recovery and replay data costs, against one attempt.

The log is turns * (envelope + payload); one workspace snapshot is added; the total is priced at an object-storage rate for the retention period and compared with the cost of one attempt.

Methods

Name Description
solve Price recovery logs and one workspace snapshot over a retention period.
solve
engine.solvers.durability.RetentionCostModel.solve(
    turns,
    envelope,
    payload,
    workspace,
    rate,
    period,
    attempt_cost,
)

Price recovery logs and one workspace snapshot over a retention period.

Parameters
Name Type Description Default
turns int Nonnegative number of retained trajectory turns. required
envelope Quantity Nonnegative metadata bytes per turn. required
payload Quantity Nonnegative payload bytes per turn. required
workspace Quantity Nonnegative bytes in one workspace snapshot; total retained bytes must be positive. required
rate Quantity Nonnegative storage price in currency/(byte*time). required
period Quantity Nonnegative retention duration. required
attempt_cost Quantity Positive cost of one attempt, in currency. required
Returns
Name Type Description
RetentionCostResult Log and total bytes, USD cost quantities, and dimensionless cost and workspace shares.
Notes

Equation: Log bytes = turns*(envelope+payload); total = log + workspace; cost = total*rate*period; attempt share = cost/attempt_cost.

Assumptions: All retained bytes live for the full period at a uniform rate. One workspace snapshot accompanies the per-turn log.

Excludes: Replication, retrieval charges, tier changes, and deletion overhead.

References

Derivation: Add per-turn envelope and payload bytes across the trajectory, then add the single workspace snapshot. Byte-time times unit storage price gives the retention cost; divide by attempt cost to express its share.

Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim.solvers import RetentionCostModel
>>> r = RetentionCostModel().solve(2, Q_(1, "byte"), Q_(2, "byte"),
...     Q_(3, "byte"), Q_(1, "USD/GB/day"), Q_(1, "day"), Q_(1, "USD"))
>>> assert r.total_bytes >= r.log_bytes

SnapshotVolumeModel

engine.solvers.durability.SnapshotVolumeModel()

Bytes written by full snapshots and by deltas over one monotonically growing trajectory.

turns // stride checkpoints; full snapshots grow with the square of the checkpoint count, deltas linearly, so the ratio is (n + 1) / 2.

Methods

Name Description
solve Compare full-snapshot and incremental-delta checkpoint write volume.
solve
engine.solvers.durability.SnapshotVolumeModel.solve(turns, stride, state_growth)

Compare full-snapshot and incremental-delta checkpoint write volume.

Parameters
Name Type Description Default
turns int Nonnegative completed trajectory turns; must contain at least one stride. required
stride int Positive checkpoint spacing in turns. required
state_growth Quantity Positive added state bytes per turn. required
Returns
Name Type Description
SnapshotVolumeResult Checkpoint count, full and incremental byte totals, and their dimensionless ratio.
See Also

mlsysim.physics.reliability.calc_snapshot_write_volume : Sum full snapshots and incremental deltas.

Notes

Equation: N = floor(turns/stride); full = growth*stride*N*(N+1)/2; delta = growth*stride*N.

Assumptions: State starts empty and grows by equal bytes every turn. Only complete strides are checkpointed; no final partial-stride save is added.

Excludes: State deletion, compression, metadata, and checkpoint service time.

References

Derivation: Full snapshots contain one, two, and then up to N strides of new state; summing this arithmetic progression gives N*(N+1)/2 strides. Deltas contain one stride each, for N strides in total.

Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim.solvers import SnapshotVolumeModel
>>> r = SnapshotVolumeModel().solve(4, 2, Q_(1, "MB"))
>>> assert r.full_bytes >= r.delta_bytes
Back to top