Ratify M10.1 timing and workload budgets with session traces
Foundation / checks (deploy) (push) Successful in 1m0s
Foundation / checks (ecs) (push) Successful in 3m34s
Foundation / checks (network) (push) Successful in 8m8s
Foundation / checks (client) (push) Successful in 14m49s
Foundation / checks (tsan) (push) Successful in 7m35s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 16m18s
Foundation / checks (checks) (push) Canceled after 29m27s
Foundation / checks (deploy) (push) Successful in 1m0s
Foundation / checks (ecs) (push) Successful in 3m34s
Foundation / checks (network) (push) Successful in 8m8s
Foundation / checks (client) (push) Successful in 14m49s
Foundation / checks (tsan) (push) Successful in 7m35s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 16m18s
Foundation / checks (checks) (push) Canceled after 29m27s
ADR-0089 records the maintainer-ratified 50 ms tick, 1 s flush with final outcomes p95 <= 1.5 s, responsiveness targets and reference hardware, plus derived scheduling, sequence, identity, baseline, queue/byte/work budgets and the exact/tolerant determinism contract (schemas/network/m10-budgets-v1.md). Adds SessionClient traffic counters, `evo-dev-session trace` and a reproducible trace script; development-reference results are in M10_TIMING_TRACES. Records that genome v1 and metabolism rates are per tick, so the quantum fixes biology rates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,11 +15,21 @@
|
||||
// "probe awaiting-restart") for the connection to be lost and re-established at a
|
||||
// newer epoch with a fresh baseline, and repeats the acknowledgement check.
|
||||
// Prints "probe passed" on success. Used by tools/ops/session-drill.sh.
|
||||
// evo-dev-session trace --connect HOST:PORT --server-name NAME --ca FILE --grants FILE
|
||||
// [--intents 1..1000] [--interval-ms 50..10000] [--out FILE.csv] [--timeout 10..600]
|
||||
// M10.1 timing experiment: after a fresh baseline, sends one intention per interval
|
||||
// and records, on the client's monotonic clock, send -> IntentResult (admission
|
||||
// round trip) and send -> IntentOutcome (durable), the outcome tick against the view
|
||||
// tick at send, view inter-arrival times and received bytes. Prints nearest-rank
|
||||
// percentiles ("trace ..." lines); --out writes every sample as CSV. Fails on any
|
||||
// loss or rejection, so a run measures one uninterrupted session.
|
||||
// Exit: 0 written/passed, 1 failure, 2 usage.
|
||||
#include "evo/network/dev_credentials.hpp"
|
||||
#include "evo/network/session_client.hpp"
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -257,6 +267,191 @@ int probe(const Args& a, bool expect_restart) {
|
||||
std::puts("probe passed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Nearest-rank percentile of a non-empty sample (sorted copy).
|
||||
double percentile(std::vector<double> v, double p) {
|
||||
std::sort(v.begin(), v.end());
|
||||
const auto rank =
|
||||
static_cast<std::size_t>(std::ceil(p / 100.0 * static_cast<double>(v.size())));
|
||||
return v[std::clamp<std::size_t>(rank, 1, v.size()) - 1];
|
||||
}
|
||||
void report(const char* name, const std::vector<double>& v) {
|
||||
if (v.empty()) {
|
||||
std::printf("trace %s n=0\n", name);
|
||||
return;
|
||||
}
|
||||
std::printf("trace %s n=%zu p50=%.1f p95=%.1f p99=%.1f max=%.1f\n", name, v.size(),
|
||||
percentile(v, 50), percentile(v, 95), percentile(v, 99),
|
||||
*std::max_element(v.begin(), v.end()));
|
||||
}
|
||||
int trace(const Args& a) {
|
||||
const auto connect = a.get("--connect");
|
||||
const auto name = a.get("--server-name");
|
||||
const auto ca = a.get("--ca");
|
||||
const auto bundle_path = a.get("--grants");
|
||||
const auto timeout = number(a.get("--timeout").value_or("300"));
|
||||
const auto intents = number(a.get("--intents").value_or("120"));
|
||||
const auto interval = number(a.get("--interval-ms").value_or("250"));
|
||||
if (!connect || !name || !ca || !bundle_path || !timeout || *timeout < 10 || *timeout > 600 ||
|
||||
!intents || *intents < 1 || *intents > 1000 || !interval || *interval < 50 ||
|
||||
*interval > 10000)
|
||||
return 2;
|
||||
const auto colon = connect->rfind(':');
|
||||
if (colon == std::string_view::npos || colon == 0)
|
||||
return 2;
|
||||
const std::uint64_t port = number(connect->substr(colon + 1)).value_or(0);
|
||||
const auto bundle = read_file(*bundle_path);
|
||||
if (port == 0 || port > 65535 || bundle.empty() || bundle.size() % dev_grant_bytes != 0)
|
||||
return 2;
|
||||
SessionClientConfig config;
|
||||
config.host = std::string{connect->substr(0, colon)};
|
||||
config.port = static_cast<std::uint16_t>(port);
|
||||
const auto pem = read_file(*ca);
|
||||
config.trust = {{pem.begin(), pem.end()}, std::string{*name}};
|
||||
for (std::size_t at = 0; at < bundle.size(); at += dev_grant_bytes) {
|
||||
DevGrant grant{};
|
||||
std::copy_n(bundle.begin() + static_cast<std::ptrdiff_t>(at), grant.size(), grant.begin());
|
||||
config.grants.push_back(grant);
|
||||
}
|
||||
auto made = SessionClient::create(std::move(config));
|
||||
if (!made)
|
||||
return 2;
|
||||
auto& c = **made;
|
||||
using Clock = std::chrono::steady_clock;
|
||||
const auto start = Clock::now();
|
||||
const auto ms = [&](Clock::time_point t) {
|
||||
return std::chrono::duration<double, std::milli>(t - start).count();
|
||||
};
|
||||
const auto deadline = start + std::chrono::seconds{*timeout};
|
||||
struct Sample {
|
||||
double sent{}, result{-1}, outcome{-1};
|
||||
std::uint64_t tick_at_send{}, outcome_tick{}, commit{};
|
||||
int status{-1};
|
||||
};
|
||||
std::vector<Sample> samples;
|
||||
std::vector<double> view_at;
|
||||
std::vector<std::uint64_t> view_tick;
|
||||
std::vector<double> view_bytes;
|
||||
std::optional<std::uint64_t> last_tick;
|
||||
ClientTraffic seen{};
|
||||
std::uint64_t sequence = 0, resolved = 0;
|
||||
std::optional<Clock::time_point> next_send;
|
||||
const auto failed = [](const char* why) {
|
||||
std::printf("trace failed: %s\n", why);
|
||||
return 1;
|
||||
};
|
||||
while (resolved < *intents) {
|
||||
const auto now = Clock::now();
|
||||
if (now >= deadline)
|
||||
return failed("timeout");
|
||||
c.poll(now);
|
||||
for (const auto& e : c.take_events()) {
|
||||
using Kind = ClientEvent::Kind;
|
||||
if (e.kind == Kind::lost || e.kind == Kind::closed || e.kind == Kind::unknown ||
|
||||
e.kind == Kind::exhausted || e.kind == Kind::backpressure)
|
||||
return failed("session interrupted (a trace must be one uninterrupted session)");
|
||||
if ((e.kind == Kind::result || e.kind == Kind::outcome) &&
|
||||
(e.sequence == 0 || e.sequence > samples.size()))
|
||||
return failed("unexpected sequence");
|
||||
if (e.kind == Kind::result) {
|
||||
auto& sample = samples[e.sequence - 1];
|
||||
sample.result = ms(now);
|
||||
sample.status = static_cast<int>(e.result.status);
|
||||
if (e.result.status != IntentStatus::admitted) {
|
||||
++resolved;
|
||||
std::printf("trace rejected sequence=%llu status=%u\n",
|
||||
static_cast<unsigned long long>(e.sequence),
|
||||
static_cast<unsigned>(e.result.status));
|
||||
}
|
||||
} else if (e.kind == Kind::outcome) {
|
||||
auto& sample = samples[e.sequence - 1];
|
||||
sample.outcome = ms(now);
|
||||
sample.outcome_tick = e.outcome.tick;
|
||||
sample.commit = e.outcome.commit_sequence;
|
||||
++resolved;
|
||||
}
|
||||
}
|
||||
const auto traffic = c.traffic();
|
||||
if (const auto v = c.latest_view(); v && (!last_tick || *last_tick != v->server_tick)) {
|
||||
last_tick = v->server_tick;
|
||||
view_at.push_back(ms(now));
|
||||
view_tick.push_back(v->server_tick);
|
||||
const auto views = traffic.environment_views - seen.environment_views;
|
||||
if (views > 0)
|
||||
view_bytes.push_back(static_cast<double>(traffic.environment_view_bytes -
|
||||
seen.environment_view_bytes) /
|
||||
static_cast<double>(views));
|
||||
seen = traffic;
|
||||
}
|
||||
// Start after a fresh, current baseline; then one intention per interval.
|
||||
if (samples.size() < *intents && c.latest_view() &&
|
||||
c.environment().freshness() == evo::client::Freshness::current) {
|
||||
if (!next_send)
|
||||
next_send = now;
|
||||
if (now >= *next_send) {
|
||||
const auto x = static_cast<std::int16_t>(sequence % 2 == 0 ? 1000 : -1000);
|
||||
if (c.send({sequence + 1, 0, x, 0})) {
|
||||
++sequence;
|
||||
samples.push_back({ms(now), -1, -1, c.latest_view()->server_tick, 0, 0, -1});
|
||||
*next_send += std::chrono::milliseconds{*interval};
|
||||
}
|
||||
}
|
||||
}
|
||||
// Poll continuously: a 1 ms sleep is about one 15.6 ms timer tick on Windows and
|
||||
// would dominate the measured round trips. Costs one core for the run.
|
||||
std::this_thread::yield();
|
||||
}
|
||||
std::vector<double> admission, durable, lead, intervals;
|
||||
std::uint64_t admitted = 0, durable_count = 0;
|
||||
for (const auto& s : samples) {
|
||||
if (s.status == static_cast<int>(IntentStatus::admitted)) {
|
||||
++admitted;
|
||||
admission.push_back(s.result - s.sent);
|
||||
}
|
||||
if (s.outcome >= 0) {
|
||||
++durable_count;
|
||||
durable.push_back(s.outcome - s.sent);
|
||||
lead.push_back(static_cast<double>(s.outcome_tick) -
|
||||
static_cast<double>(s.tick_at_send));
|
||||
}
|
||||
}
|
||||
for (std::size_t i = 1; i < view_at.size(); ++i)
|
||||
intervals.push_back(view_at[i] - view_at[i - 1]);
|
||||
const double seconds = ms(Clock::now()) / 1000.0;
|
||||
std::printf("trace intents=%zu admitted=%llu outcomes=%llu interval_ms=%llu\n", samples.size(),
|
||||
static_cast<unsigned long long>(admitted),
|
||||
static_cast<unsigned long long>(durable_count),
|
||||
static_cast<unsigned long long>(*interval));
|
||||
report("admission_ms", admission);
|
||||
report("durable_ms", durable);
|
||||
report("outcome_tick_lead", lead);
|
||||
report("view_interval_ms", intervals);
|
||||
report("environment_view_bytes", view_bytes);
|
||||
const auto total = c.traffic();
|
||||
std::printf("trace views=%zu ticks=%llu seconds=%.1f received_bytes_per_s=%.0f frames=%llu\n",
|
||||
view_at.size(),
|
||||
static_cast<unsigned long long>(
|
||||
view_tick.empty() ? 0 : view_tick.back() - view_tick.front()),
|
||||
seconds, static_cast<double>(total.bytes) / seconds,
|
||||
static_cast<unsigned long long>(total.frames));
|
||||
if (const auto out = a.get("--out")) {
|
||||
std::ofstream csv{std::string{*out}, std::ios::trunc};
|
||||
csv << "kind,sequence,sent_ms,tick_at_send,result_ms,status,outcome_ms,outcome_tick,"
|
||||
"commit\n";
|
||||
for (std::size_t i = 0; i < samples.size(); ++i) {
|
||||
const auto& s = samples[i];
|
||||
csv << "intent," << i + 1 << ',' << s.sent << ',' << s.tick_at_send << ',' << s.result
|
||||
<< ',' << s.status << ',' << s.outcome << ',' << s.outcome_tick << ',' << s.commit
|
||||
<< '\n';
|
||||
}
|
||||
for (std::size_t i = 0; i < view_at.size(); ++i)
|
||||
csv << "view,," << view_at[i] << ',' << view_tick[i] << ",,,,,\n";
|
||||
if (!csv)
|
||||
return failed("cannot write --out");
|
||||
}
|
||||
std::puts("trace passed");
|
||||
return 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
@@ -275,14 +470,18 @@ int main(int argc, char** argv) {
|
||||
}) > 0;
|
||||
const auto probe_args = parse(static_cast<int>(rest.size()), rest.data());
|
||||
code = probe_args ? probe(*probe_args, restart) : 2;
|
||||
}
|
||||
} else if (args && command == "trace")
|
||||
code = trace(*args);
|
||||
if (code == 2)
|
||||
std::fputs("usage: evo-dev-session credentials --environment dev --server-name NAME "
|
||||
"--out DIR [--days N]\n"
|
||||
" evo-dev-session grants --environment dev --key FILE --world N "
|
||||
"--frame N --region N --subject N --out FILE [--count N] [--lifetime S]\n"
|
||||
" evo-dev-session probe --connect HOST:PORT --server-name NAME --ca FILE "
|
||||
"--grants FILE [--expect-restart] [--timeout S]\n",
|
||||
stderr);
|
||||
std::fputs(
|
||||
"usage: evo-dev-session credentials --environment dev --server-name NAME "
|
||||
"--out DIR [--days N]\n"
|
||||
" evo-dev-session grants --environment dev --key FILE --world N "
|
||||
"--frame N --region N --subject N --out FILE [--count N] [--lifetime S]\n"
|
||||
" evo-dev-session probe --connect HOST:PORT --server-name NAME --ca FILE "
|
||||
"--grants FILE [--expect-restart] [--timeout S]\n"
|
||||
" evo-dev-session trace --connect HOST:PORT --server-name NAME --ca FILE "
|
||||
"--grants FILE [--intents N] [--interval-ms MS] [--out FILE.csv] [--timeout S]\n",
|
||||
stderr);
|
||||
return code;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user