Snodo.Extensions.Tasks.Stress (snodo_tasks v0.5.0)

Copy Markdown View Source

Deterministic correctness workloads for Tasks contention and runner soak.

The harness runs against any Snodo.Extensions.Tasks.Store. Without a :store option it starts a private Store.Memory process. Callers that own a database pass a store reference they have already configured, so this module never depends on a particular database. In this repository the PostgreSQL and SQLite packages have Mix tasks (mix tasks.postgres.stress, mix tasks.sqlite.stress) that prepare a database and call run/1; those tasks are not part of the published packages.

The report separates exact lifecycle invariants from observed timings so the same workload can run in CI and on developer machines without flaky latency thresholds.

This is diagnostic evidence, not a production capacity claim.

Options

  • :tasks, :writers, :rounds - positive integers that size the workload (defaults 25, 8, and 3).
  • :timeout_ms - a positive integer (default 30,000). It bounds each wait the harness performs: readiness of one batch of writers or workers, Runner completion and instrumentation for one round, one fencing Task, and each busy-retry loop. Every wait gets a fresh deadline, so a whole run can take much longer, and a store call that blocks is not interrupted until the surrounding wait expires.
  • :store - a {module, state} store reference. The module must also export history/3, returning {:ok, entries} in commit order where each entry is a map with an :event key holding the committed Snodo.Extensions.Tasks.Event, for the read access returned by authorize/3 for {:get, task_id}. The store must accept at least :tasks active tasks in one scope and keep every Task the run creates. Task IDs carry a random per-run prefix, so a store that already holds tasks can be reused.
  • :workload - the label reported as "workload" (default "snodo_tasks_memory").
  • :busy? - an arity-1 predicate that marks a store result as documented backpressure that did not change state, such as SQLite's {:error, :database_busy}. In the CAS race a busy result is a lost attempt, counted as busy, and never an applied transition. Workload setup and the fencing steps retry busy results and report the total as busyRetries; the harness then checks the stored state, so a store that commits and still reports busy fails the run.

Fixed limits: harness claims use a 60,000 ms lease; the Runner uses a lease of max(2 * timeout_ms, 60_000) ms and a heartbeat of timeout_ms; busy retries back off from 1 ms up to 50 ms between attempts.

Summary

Functions

Runs deterministic CAS-contention, lease-fencing, and runner-soak workloads.

Types

report()

@type report() :: %{required(String.t()) => term()}

Functions

run(opts \\ [])

@spec run(keyword()) :: report()

Runs deterministic CAS-contention, lease-fencing, and runner-soak workloads.