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
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:
@@ -12,8 +12,12 @@
|
||||
// M10.6 (ADR-0094): sessions' probe markers move within the habitat sites' bounding cells,
|
||||
// or within --m10-area. M10.8c (ADR-0096): with --m10-handoff-key, markers are durable probe
|
||||
// records and a marker crossing into a --m10-neighbour's area is handed over with a ticket.
|
||||
// M10.9a (ADR-0097): the host's step and this bridge's work per simulated tick feed a load
|
||||
// governor; above its thresholds grant logins are refused and replication is shed.
|
||||
#include "evo/persistence/postgres.hpp"
|
||||
#include "evo/persistence/region_lease.hpp"
|
||||
#include "evo/server/ops.hpp"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -23,6 +27,7 @@
|
||||
#include "evo/client/environment_view.hpp"
|
||||
#include "evo/network/handoff_ticket.hpp"
|
||||
#include "evo/processes/lineage_region.hpp"
|
||||
#include "evo/server/load_governor.hpp"
|
||||
#include "evo/server/pg_slot.hpp"
|
||||
#include "evo/server/postgres_action_ledger.hpp"
|
||||
#include "evo/server/postgres_control_ledger.hpp"
|
||||
@@ -183,9 +188,11 @@ template <typename Host> class M10Bridge {
|
||||
std::printf("m10 window closed activation=%s\n", window_->activation_id().c_str());
|
||||
return false;
|
||||
}
|
||||
void after_step() {
|
||||
// `host_work`: this iteration's host step, measured by the caller.
|
||||
void after_step(std::chrono::nanoseconds host_work) {
|
||||
if (!sessions_ || !accepting(wall_seconds()))
|
||||
return;
|
||||
const auto started = std::chrono::steady_clock::now();
|
||||
auto& host = *host_;
|
||||
const auto& s = host.status();
|
||||
const server::HostFacts facts{s.ready && s.phase == server::HostPhase::running, s.epoch,
|
||||
@@ -233,6 +240,16 @@ template <typename Host> class M10Bridge {
|
||||
: "refused",
|
||||
static_cast<unsigned long long>(e.session), e.account.c_str(),
|
||||
static_cast<unsigned>(e.reason));
|
||||
measure(host_work, std::chrono::steady_clock::now() - started, s);
|
||||
}
|
||||
// The listener's load for /metrics.
|
||||
void metrics(server::OpsCounters& c) const {
|
||||
c.m10_enabled = sessions_ != nullptr;
|
||||
if (!sessions_)
|
||||
return;
|
||||
c.m10_sessions = sessions_->sessions();
|
||||
c.m10_refused_logins = sessions_->refused_for_load();
|
||||
c.m10_load = governor_.state();
|
||||
}
|
||||
void shutdown() {
|
||||
if (sessions_)
|
||||
@@ -240,6 +257,40 @@ template <typename Host> class M10Bridge {
|
||||
}
|
||||
|
||||
private:
|
||||
// Busy time accumulates until the simulated tick advances by k; it then counts as k equal
|
||||
// per-tick samples (ADR-0097). A recovery's jump starts a new count instead.
|
||||
void measure(std::chrono::nanoseconds host_work, std::chrono::nanoseconds session_work,
|
||||
const server::HostStatus& s) {
|
||||
busy_ += host_work + session_work;
|
||||
session_busy_ += session_work;
|
||||
if (s.simulated_tick <= measured_tick_)
|
||||
return;
|
||||
const auto ticks = s.simulated_tick - measured_tick_;
|
||||
const bool counted = measured_tick_ != 0 && ticks <= server::load_window_ticks;
|
||||
measured_tick_ = s.simulated_tick;
|
||||
const auto per = [&](std::chrono::nanoseconds total) {
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(total).count() /
|
||||
static_cast<std::int64_t>(ticks));
|
||||
};
|
||||
const auto per_tick = per(busy_), session_per_tick = per(session_busy_);
|
||||
busy_ = session_busy_ = {};
|
||||
if (!counted)
|
||||
return;
|
||||
const auto now_us =
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count());
|
||||
bool changed = false;
|
||||
for (std::uint64_t i = 0; i < ticks; ++i)
|
||||
changed = governor_.observe(per_tick, session_per_tick, s.tick_debt, now_us) || changed;
|
||||
if (!changed)
|
||||
return;
|
||||
const auto& load = governor_.state();
|
||||
sessions_->set_load(load.refusing, load.shed);
|
||||
std::printf("m10 load refusing=%d shed=%u p95_us=%llu\n", load.refusing ? 1 : 0,
|
||||
static_cast<unsigned>(load.shed), static_cast<unsigned long long>(load.p95_us));
|
||||
}
|
||||
static const processes::EnvironmentalCommunity&
|
||||
community(const processes::EnvironmentalCommunity& c) {
|
||||
return c;
|
||||
@@ -383,6 +434,9 @@ template <typename Host> class M10Bridge {
|
||||
std::unique_ptr<server::PgSlot> slot_;
|
||||
std::unique_ptr<server::PostgresControlLedger> control_;
|
||||
std::unique_ptr<server::PostgresActionLedger> actions_;
|
||||
server::LoadGovernor governor_{*server::LoadGovernor::create({})};
|
||||
std::chrono::nanoseconds busy_{}, session_busy_{};
|
||||
std::uint64_t measured_tick_{};
|
||||
std::unique_ptr<server::PostgresProbeLedger> probes_; // Handoff mode only.
|
||||
std::unique_ptr<server::PostgresHandoffLedger> handoff_; // Handoff mode only.
|
||||
std::optional<std::array<std::int64_t, 4>> area_cells_;
|
||||
@@ -407,7 +461,10 @@ template <typename Host> class M10Bridge {
|
||||
[[nodiscard]] bool accepting(std::uint64_t) const noexcept {
|
||||
return false;
|
||||
}
|
||||
void after_step() {}
|
||||
void after_step(std::chrono::nanoseconds) {}
|
||||
void metrics(server::OpsCounters& c) const {
|
||||
c.m10_enabled = false;
|
||||
}
|
||||
void shutdown() {}
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user