Add M10.9a load measurement, governor and overload shedding
Foundation / checks (deploy) (push) Successful in 3m20s
Foundation / checks (ecs) (push) Successful in 1m59s
Foundation / checks (client) (push) Failing after 10m0s
Foundation / checks (network) (push) Successful in 13m9s
Foundation / checks (tsan) (push) Successful in 8m1s
Foundation / checks (checks) (push) Successful in 32m2s
Foundation / checks (postgres) (push) Failing after 26m39s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

ADR-0097 (M10.9 load and abuse qualification; only evolution-dev
reference-worker runs qualify). evo-server measures each simulated tick's
work (host step plus the M10 bridge, with the session layer's share kept
separately) and feeds a portable LoadGovernor: grant logins are refused
at a 2 s p95 of 15 ms or any tick debt, replication is shed in up to
three levels at 20 ms or debt >= 2 (radius cap 7/7/5/3, far updates
x1/x2/x2/x4, no fresh baselines, own markers unaffected), and both relax
after 5 s of calm. Handoff tickets are still admitted. /metrics gains
evo_m10_* gauges when the listener is enabled.

Adds the missing ADR index entries for ADR-0094 to ADR-0096. Refreshes
the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-07 06:34:40 -04:00
co-authored by Claude Opus 5.5
parent 265163a9a6
commit b8cb9db297
22 changed files with 676 additions and 34 deletions
+69
View File
@@ -0,0 +1,69 @@
#include "evo/server/load_governor.hpp"
#include <algorithm>
#include <utility>
namespace evo::server {
std::expected<LoadGovernor, LoadPolicyError> LoadGovernor::create(LoadPolicy p) {
if (p.relax_us == 0 || p.relax_us >= p.refuse_us || p.refuse_us > p.shed_us ||
p.shed_us > p.tick_budget_us || p.step_us == 0 || p.settle_us == 0 || p.max_shed > 3)
return std::unexpected(LoadPolicyError::invalid);
return LoadGovernor{p};
}
namespace {
using Window = std::array<std::uint64_t, load_window_ticks>;
// The first `n` samples sorted; nearest rank: the smallest sample with at least `percent` of
// the window at or below it.
Window sorted_of(const Window& w, std::size_t n) {
Window sorted{};
std::copy_n(w.begin(), n, sorted.begin());
std::sort(sorted.begin(), sorted.begin() + static_cast<std::ptrdiff_t>(n));
return sorted;
}
std::uint64_t rank(const Window& sorted, std::size_t n, std::size_t percent) {
return sorted.at((((n * percent) + 99) / 100) - 1);
}
} // namespace
bool LoadGovernor::observe(std::uint64_t work_us, std::uint64_t session_us, std::uint64_t tick_debt,
std::uint64_t now_us) {
window_.at(next_) = work_us;
session_window_.at(next_) = std::min(session_us, work_us);
next_ = (next_ + 1) % window_.size();
state_.samples = std::min(state_.samples + 1, window_.size());
const auto n = state_.samples;
const auto sorted = sorted_of(window_, n);
state_.p95_us = rank(sorted, n, 95);
state_.p99_us = rank(sorted, n, 99);
state_.max_us = sorted.at(n - 1);
const auto sessions = sorted_of(session_window_, n);
state_.session_p95_us = rank(sessions, n, 95);
state_.session_p99_us = rank(sessions, n, 99);
const auto before = std::pair{state_.refusing, state_.shed};
const bool hot = state_.p95_us >= policy_.refuse_us || tick_debt > 0;
const bool overloaded = state_.p95_us >= policy_.shed_us || tick_debt >= 2;
if (hot)
state_.refusing = true;
if (overloaded && state_.shed < policy_.max_shed &&
(!stepped_ || now_us - last_step_us_ >= policy_.step_us)) {
++state_.shed;
stepped_ = true;
last_step_us_ = now_us;
}
if (state_.p95_us >= policy_.relax_us || tick_debt > 0) {
calm_ = false;
} else if (!calm_) {
calm_ = true;
calm_since_us_ = now_us;
} else if (now_us - calm_since_us_ >= policy_.settle_us) {
if (state_.shed > 0)
--state_.shed; // One level per settle interval, then logins.
else
state_.refusing = false;
calm_since_us_ = now_us;
}
return before != std::pair{state_.refusing, state_.shed};
}
} // namespace evo::server