Files
dingoandClaude Opus 5.5 1ba6748288
Foundation / checks (deploy) (push) Successful in 3m16s
Foundation / checks (ecs) (push) Successful in 1m54s
Foundation / checks (client) (push) Successful in 12m39s
Foundation / checks (network) (push) Successful in 12m56s
Foundation / checks (tsan) (push) Successful in 7m52s
Foundation / checks (checks) (push) Successful in 32m28s
Foundation / checks (postgres) (push) Failing after 26m52s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Add M10.9b evo-load multi-client load generator and process smoke
ADR-0097. evo-load runs bots on worker threads, each a RegionSessionClient
with its own account and an in-process dev grant: one intention per tick
at its input lead with marker prediction, actions every 2 s, interest
moves every 10 s, and re-login after any close. Stepped ramps report
pooled and per-client distributions (response, receipt, outcome, login,
prediction error), snapshot rate, gaps and bandwidth, drops, failed
logins and refusals, generator CPU, a starvation check among connected
bots, a budget verdict and the region's evo_m10_* gauges, ending with the
sustainable bot count. A Postgres process smoke runs 4 then 8 bots
against a real evo-server.

Fixes found while ramping: the process fixture's short pumps never read
(a chatty child blocked on its stdout pipe), and the load governor
refused on a single tick of debt (now 2 refuse, 4 shed). Refreshes the
dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 09:02:57 -04:00

60 lines
2.7 KiB
C++

#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <expected>
// M10.9a overload response (ADR-0097): a region's per-tick work and tick debt decide whether
// new logins are refused and how far replication is shed. Portable: no clocks (callers pass a
// monotonic time in microseconds), no transport. Thresholds are engineering budgets
// (schemas/network/m10-budgets-v1.md), not game rules.
namespace evo::server {
struct LoadPolicy {
std::uint64_t tick_budget_us{25'000}; // p99 per-tick region work budget (ADR-0089).
std::uint64_t refuse_us{15'000}; // Window p95 at or above: refuse new logins.
std::uint64_t shed_us{20'000}; // Window p95 at or above: shed one more level.
std::uint64_t relax_us{10'000}; // Window p95 below (and no debt): calm.
std::uint64_t step_us{1'000'000}; // At most one shed step per interval.
std::uint64_t settle_us{5'000'000}; // Calm this long relaxes one step.
std::uint8_t max_shed{3};
};
inline constexpr std::size_t load_window_ticks = 40; // 2 s of 50 ms ticks.
// Tick debt (due minus simulated) that refuses logins and that sheds. One tick is jitter (a
// commit flush, a scheduler hiccup): it only interrupts calm.
inline constexpr std::uint64_t refuse_debt_ticks = 2, shed_debt_ticks = 4;
struct LoadState {
bool refusing{};
std::uint8_t shed{};
std::uint64_t p95_us{}, p99_us{}, max_us{}; // Over the window (0 before any sample).
std::size_t samples{}; // In the window.
// The session layer's share of the same ticks (ADR-0089 budgets it per session).
std::uint64_t session_p95_us{}, session_p99_us{};
friend bool operator==(const LoadState&, const LoadState&) = default;
};
enum class LoadPolicyError : std::uint8_t { invalid };
class LoadGovernor {
public:
[[nodiscard]] static std::expected<LoadGovernor, LoadPolicyError> create(LoadPolicy policy);
// One simulated tick's region work (of which `session_us` was the session layer's) and the
// host's tick debt, at monotonic `now_us`. Returns true when `refusing` or `shed` changed.
bool observe(std::uint64_t work_us, std::uint64_t session_us, std::uint64_t tick_debt,
std::uint64_t now_us);
[[nodiscard]] const LoadState& state() const noexcept {
return state_;
}
[[nodiscard]] const LoadPolicy& policy() const noexcept {
return policy_;
}
private:
explicit LoadGovernor(LoadPolicy policy) : policy_{policy} {}
LoadPolicy policy_;
LoadState state_;
std::array<std::uint64_t, load_window_ticks> window_{}, session_window_{};
std::size_t next_{};
bool stepped_{}, calm_{};
std::uint64_t last_step_us_{}, calm_since_us_{};
};
} // namespace evo::server