Measure M10.2c loss and head-of-line behaviour of the QUIC channels
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m46s
Foundation / checks (network) (push) Successful in 8m16s
Foundation / checks (client) (push) Successful in 12m6s
Foundation / checks (tsan) (push) Successful in 7m46s
Foundation / checks (checks) (push) Successful in 31m39s
Foundation / checks (postgres) (push) Successful in 33m28s
Foundation / postgres-tools (push) Successful in 19s
Foundation / image (push) Successful in 2m15s
Foundation / server-image (push) Successful in 18m31s

evo-quic-hol-measure sends the same 20 Hz state on the DATAGRAM channel and the
ordered reliable stream plus 16 KiB reliable messages through the impairment relay
across RTT x loss. Under 5-10 % loss the stream's p95 is 3-5.5x the datagrams' and
exceeds the 250 ms target at 100 ms RTT, confirming the ADR-0090 channel split.
The relay and tool request 1 ms timer resolution on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-03 17:25:38 -04:00
co-authored by Claude Opus 5.5
parent ca762bff75
commit 1055cc8c8f
10 changed files with 405 additions and 5 deletions
+6 -1
View File
@@ -149,13 +149,18 @@ if(EVO_BUILD_QUIC)
add_library(evo_network_impair STATIC tools/network/impair/udp_relay.cpp) add_library(evo_network_impair STATIC tools/network/impair/udp_relay.cpp)
target_include_directories(evo_network_impair PUBLIC "${PROJECT_SOURCE_DIR}/tools/network/impair") target_include_directories(evo_network_impair PUBLIC "${PROJECT_SOURCE_DIR}/tools/network/impair")
if(WIN32) if(WIN32)
target_link_libraries(evo_network_impair PUBLIC ws2_32) target_link_libraries(evo_network_impair PUBLIC ws2_32 winmm)
endif() endif()
evo_owned_target(evo_network_impair) evo_owned_target(evo_network_impair)
add_executable(evo-quic-transport-tests tests/quic_transport.cpp) add_executable(evo-quic-transport-tests tests/quic_transport.cpp)
target_link_libraries(evo-quic-transport-tests PRIVATE evo_network_quic evo_network_impair evo_network_tls) target_link_libraries(evo-quic-transport-tests PRIVATE evo_network_quic evo_network_impair evo_network_tls)
evo_owned_target(evo-quic-transport-tests) evo_owned_target(evo-quic-transport-tests)
evo_msquic_runtime(evo-quic-transport-tests) evo_msquic_runtime(evo-quic-transport-tests)
# M10.2c measurement tool (development reference; not a test).
add_executable(evo-quic-hol-measure tools/network/quic_hol.cpp)
target_link_libraries(evo-quic-hol-measure PRIVATE evo_network_quic evo_network_impair evo_network_tls)
evo_owned_target(evo-quic-hol-measure)
evo_msquic_runtime(evo-quic-hol-measure)
add_test(NAME quic-transport COMMAND evo-quic-transport-tests) add_test(NAME quic-transport COMMAND evo-quic-transport-tests)
set_tests_properties(quic-transport PROPERTIES TIMEOUT 180 LABELS "quic") set_tests_properties(quic-transport PROPERTIES TIMEOUT 180 LABELS "quic")
add_executable(evo-quic-smoke-tests tests/quic_smoke.cpp) add_executable(evo-quic-smoke-tests tests/quic_smoke.cpp)
+1 -1
View File
@@ -24,7 +24,7 @@
{"name": "client", "configurePreset": "client", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests"]}, {"name": "client", "configurePreset": "client", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests"]},
{"name": "client-probe", "configurePreset": "client-probe", "targets": ["evo-client-probe"]}, {"name": "client-probe", "configurePreset": "client-probe", "targets": ["evo-client-probe"]},
{"name": "network", "configurePreset": "network", "targets": ["evo-client-state-tests", "evo-network-tests", "evo-dev-session"]}, {"name": "network", "configurePreset": "network", "targets": ["evo-client-state-tests", "evo-network-tests", "evo-dev-session"]},
{"name": "quic", "configurePreset": "quic", "targets": ["evo-quic-smoke-tests", "evo-quic-transport-tests", "evo-network-tests"]}, {"name": "quic", "configurePreset": "quic", "targets": ["evo-quic-smoke-tests", "evo-quic-transport-tests", "evo-quic-hol-measure", "evo-network-tests"]},
{"name": "client-network", "configurePreset": "client-network", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests", "evo-network-tests", "evo-dev-session"]}, {"name": "client-network", "configurePreset": "client-network", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests", "evo-network-tests", "evo-dev-session"]},
{"name": "client-package", "configurePreset": "client-package", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests", "evo-network-tests", "evo-dev-session"]} {"name": "client-package", "configurePreset": "client-package", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests", "evo-network-tests", "evo-dev-session"]}
], ],
+2 -1
View File
@@ -518,7 +518,8 @@ bounded replication and recovery under loss, overload and region transfer.
networking/M10_TIMING_TRACES.md); targets are not yet qualified on the reference networking/M10_TIMING_TRACES.md); targets are not yet qualified on the reference
hardware (10.9). 10.2 split: 10.2a selection, pins and build of msquic/OpenSSL done hardware (10.9). 10.2 split: 10.2a selection, pins and build of msquic/OpenSSL done
(ADR-0090); 10.2b bounded channels, exact CA pinning and the impairment relay done; (ADR-0090); 10.2b bounded channels, exact CA pinning and the impairment relay done;
10.2c loss/head-of-line measurements follow. 10.3-10.9 planned. 10.2c loss/head-of-line measurements done (networking/M10_TRANSPORT_MEASUREMENTS.md).
10.3-10.9 planned.
**Entry:** M9 client/session evidence and M7/M8 dev/stage durability. Read **Entry:** M9 client/session evidence and M7/M8 dev/stage durability. Read
NETWORK_ARCHITECTURE, PERSISTENCE_ARCHITECTURE and ADR-0017. The M9 transport is NETWORK_ARCHITECTURE, PERSISTENCE_ARCHITECTURE and ADR-0017. The M9 transport is
+4 -1
View File
@@ -13,7 +13,10 @@ converts or ratifies them. M10.2a selects QUIC with msquic 2.6.2 and OpenSSL 3.5
(ADR-0090), pinned and building on Windows and Linux with a loopback smoke test. M10.2b adds (ADR-0090), pinned and building on Windows and Linux with a loopback smoke test. M10.2b adds
the bounded QUIC endpoint (datagram and reliable channels, exact CA pinning with the owned the bounded QUIC endpoint (datagram and reliable channels, exact CA pinning with the owned
check authoritative, minimum-MTU start) and the owned impairment relay, tested on both check authoritative, minimum-MTU start) and the owned impairment relay, tested on both
platforms. Next: M10.2c loss and head-of-line measurements. platforms. M10.2c measures loss and head-of-line blocking through the relay: under 5-10 %
loss the ordered stream's p95 latency is 3-5.5x the datagram channel's and exceeds the
250 ms target at 100 ms RTT, while datagrams stay <= 67 ms, which confirms the channel split
(networking/M10_TRANSPORT_MEASUREMENTS.md). M10.2 is complete. Next: M10.3 session binding.
## Previous gate - 2026-10-02 ## Previous gate - 2026-10-02
+17
View File
@@ -120,3 +120,20 @@ served only by the dev fallback for now.
- **Impairment relay** (`tools/network/impair`, tests and measurements only): seeded - **Impairment relay** (`tools/network/impair`, tests and measurements only): seeded
loss, duplication, reordering, corruption, delay/jitter, payload-size limit and live loss, duplication, reordering, corruption, delay/jitter, payload-size limit and live
reconfiguration (outage). reconfiguration (outage).
## M10.2c measurements (2026-10-03)
`evo-quic-hol-measure` sent the same 20 Hz, 300-byte state on the DATAGRAM channel and
the ordered reliable stream, plus 16 KiB reliable messages, through the relay across
RTT {2, 50, 100} ms x loss {0, 1, 5, 10} % with 2 % reordering and 1 % duplication, on
Windows and Linux ([results](../networking/M10_TRANSPORT_MEASUREMENTS.md)).
- **The channel split is confirmed.** Under 5-10 % loss the ordered stream's p95 latency
is 3-5.5x the datagram channel's (head-of-line blocking). At 100 ms RTT it exceeds the
250 ms responsiveness target (10 % loss: 258 / 310 ms on Linux / Windows), while
datagram p95 stays <= 67 ms and newest-state staleness p99 <= 195 ms. Superseding state
and intentions must not use the ordered stream.
- Reliable actions and outcomes fit their budget: the slowest 16 KiB message took 510 ms,
inside the 1.5 s final-outcome budget; no reliable message was lost.
- Congestion control stays CUBIC: nothing measured here motivates BBR. Bandwidth limits,
competing flows and 20+ clients are 10.9 work.
- Limits: user-space relay on one host (no kernel TCP, netem or real paths), development
hardware. The relay and tool request 1 ms timer resolution on Windows.
+3 -1
View File
@@ -4,7 +4,9 @@ Status: locked server authority and untrusted clients; transport/reliability are
proposals for M10. M10 timing and workload budgets: ADR-0089 and proposals for M10. M10 timing and workload budgets: ADR-0089 and
[m10-budgets-v1](../../schemas/network/m10-budgets-v1.md). M10 transport: QUIC via msquic [m10-budgets-v1](../../schemas/network/m10-budgets-v1.md). M10 transport: QUIC via msquic
with OpenSSL (ADR-0090): bounded DATAGRAM and reliable-stream channels with exact CA with OpenSSL (ADR-0090): bounded DATAGRAM and reliable-stream channels with exact CA
pinning (`evo_network_quic`, M10.2b); loss/head-of-line measurements follow in M10.2c. The scoped M9 dev session (TLS 1.3, protocol v1, dev-only grants) pinning (`evo_network_quic`, M10.2b); loss/head-of-line measurements (M10.2c,
[M10_TRANSPORT_MEASUREMENTS](../networking/M10_TRANSPORT_MEASUREMENTS.md)) confirm
superseding state on DATAGRAMs and reliable actions on the ordered stream. The scoped M9 dev session (TLS 1.3, protocol v1, dev-only grants)
is specified in [DEV_SESSION_PROTOCOL](../networking/DEV_SESSION_PROTOCOL.md) and is specified in [DEV_SESSION_PROTOCOL](../networking/DEV_SESSION_PROTOCOL.md) and
ADR-0082. M0 has no networking. Steam distribution follows later through ADR-0082. M0 has no networking. Steam distribution follows later through
an identity-provider adapter; core account IDs are independent of Steam IDs. an identity-provider adapter; core account IDs are independent of Steam IDs.
+19
View File
@@ -4072,3 +4072,22 @@ relay and tests; format check; Windows MSVC 19.44 preset `quic` 3/3 and transpor
5/5 repeated runs. 5/5 repeated runs.
Not done: loss/head-of-line measurements and TCP comparison (10.2c), msquic itself under Not done: loss/head-of-line measurements and TCP comparison (10.2c), msquic itself under
sanitizers, CI integration of the quic preset, integration into the region host/client. sanitizers, CI integration of the quic preset, integration into the region host/client.
## 2026-10-03 — M10.2c loss and head-of-line measurements (ADR-0090)
Added `evo-quic-hol-measure` (`tools/network/quic_hol.cpp`, preset `quic`) and ran it for
15 s per configuration (RTT {2, 50, 100} ms x loss {0, 1, 5, 10} %, 2 % reordering, 1 %
duplication, 16 KiB reliable messages) on Windows 11 (MSVC 19.44) and WSL2 Ubuntu (GCC 14)
on a Ryzen 7 9800X3D. Results: docs/networking/M10_TRANSPORT_MEASUREMENTS.md.
Found and fixed: Windows numbers first inflated to about 31 ms at 2 ms RTT by the ~15.6 ms
default timer tick (the relay and tool now call `timeBeginPeriod(1)`, relay balanced in
its destructor; Windows baseline 6 ms p95); datagrams refused before the DATAGRAM
extension was negotiated (measurement now waits for it); clang-tidy widening findings.
Executed: Linux format check, GCC 14 build, CTest `-L quic` 2/2, clang-tidy 19 on the tool
and relay; Windows MSVC preset `quic` build and CTest 3/3; both measurement runs.
Limits: no kernel TCP/netem comparison (user-space relay by decision), single host and
loopback, development hardware, 15 samples of 16 KiB messages per configuration, run
length cuts off in-flight stream messages; msquic not under sanitizers; quic preset not
in CI.
@@ -0,0 +1,60 @@
# M10.2c transport loss and head-of-line measurements
Supports [ADR-0090](../adr/0090-m10-quic-transport.md) against the
[ADR-0089](../adr/0089-m10-timing-and-budgets.md) budgets. Development-reference
measurements on one host; they do not qualify the targets on the reference hardware.
## Method
`evo-quic-hol-measure --seconds 15` (`tools/network/quic_hol.cpp`, preset `quic`): a QUIC
server sends the same 20 Hz, 300-byte state on both channels of one connection, the
DATAGRAM channel and the single ordered reliable stream (the TCP-like case: one lost
packet delays everything behind it), plus one 16 KiB reliable message per second
(multi-packet, i.e. fragmented, delivery). Traffic crosses the owned impairment relay
with delay = RTT/2 each way, jitter RTT/20, 2 % reordering, 1 % duplication and the
listed loss, in both directions. Latency is one-way (same process clock); staleness is
the age of the newest state the client holds, sampled every 5 ms (20 Hz sending alone
gives about 25 ms average, 50 ms worst-case staleness at zero latency).
Measurement starts after the datagram channel is negotiated. The relay is user space:
this is not a kernel-TCP measurement (the maintainer chose the relay over netem).
Hosts: AMD Ryzen 7 9800X3D, Windows 11 Pro (MSVC 19.44 build, 1 ms timer resolution
requested by the tool and relay) and WSL2 Ubuntu (GCC 14 build), 2026-10-03.
## Results (ms; Linux / Windows)
| RTT | Loss | Datagram p95 latency | Stream p95 latency | Datagram p99 staleness | Stream p99 staleness | Datagrams delivered |
|---|---|---|---|---|---|---|
| 2 | 0 % | 2.5 / 6.0 | 2.5 / 6.0 | 50.2 / 52.0 | 50.2 / 52.0 | 300 / 300 |
| 2 | 10 % | 2.5 / 6.0 | 35.5 / 101.1 | 114.9 / 114.8 | 89.9 / 195.4 | 274 / 268 |
| 50 | 1 % | 28.3 / 30.1 | 28.4 / 30.6 | 75.3 / 85.3 | 130.0 / 115.1 | 298 / 297 |
| 50 | 5 % | 28.4 / 31.0 | 152.0 / 101.6 | 125.0 / 131.3 | 210.0 / 199.2 | 281 / 291 |
| 50 | 10 % | 28.5 / 37.7 | 154.9 / 205.6 | 155.0 / 125.8 | 264.9 / 309.4 | 264 / 263 |
| 100 | 0 % | 55.9 / 58.6 | 56.0 / 58.6 | 105.2 / 105.8 | 105.2 / 105.8 | 299 / 299 |
| 100 | 1 % | 56.0 / 58.2 | 62.4 / 62.6 | 105.2 / 105.9 | 150.0 / 151.0 | 298 / 299 |
| 100 | 5 % | 58.2 / 63.6 | 214.5 / 314.2 | 154.9 / 195.0 | 325.2 / 464.0 | 283 / 272 |
| 100 | 10 % | 64.2 / 66.7 | 257.9 / 310.4 | 160.0 / 154.7 | 395.2 / 420.3 | 272 / 276 |
16 KiB reliable messages (15 per run, so p95 is the maximum; Linux / Windows): 12.4 /
12.0 ms at 2 ms RTT without loss; 140.8 / 204.8 ms at 50 ms RTT and 5 % loss; 297.4 /
510.1 ms at 100 ms RTT and 5 % loss; 412.3 / 438.4 ms at 100 ms RTT and 10 % loss. All
were delivered. The reliable stream lost no state message: received counts of 294-299
of 300 are messages still in flight when the 15-second run ended.
## Conclusions
- **Head-of-line blocking is the dominant cost of the ordered stream under loss.** At
5-10 % loss with 50-100 ms RTT its p95 latency is 3-5.5x the datagram channel's. At
100 ms RTT it exceeds ADR-0089's 250 ms responsiveness target at 10 % loss on both
hosts and at 5 % loss on Windows (214.5 ms on Linux), while the datagram channel's p95
stays within 67 ms.
Superseding realtime state and intentions therefore belong on DATAGRAMs (ADR-0090
confirmed); losses there are bounded by the next update (staleness p99 <= 195 ms here).
- Reliable actions and outcomes tolerate the stream's tail: the slowest 16 KiB message took
510 ms (100 ms RTT, 5 % loss), inside the 1.5 s final-outcome budget.
- Congestion control stays msquic's default (CUBIC); at this send rate no measurement
motivates BBR. Revisit with 20+ clients and bandwidth limits in 10.9.
- The Windows build first measured about 31 ms at 2 ms RTT because 1 ms waits round to
the ~15.6 ms timer tick (as in M10.1); the relay and tool now request 1 ms resolution.
## Not covered
Kernel TCP/TLS under packet loss (no netem), real networks and NAT, bandwidth caps and
competing flows, multiple clients, the reference worker and low-spec VM, the M9 dev path.
+11
View File
@@ -16,6 +16,8 @@
#endif #endif
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
// After <winsock2.h>: timeBeginPeriod for 1 ms waits (default timer tick is ~15.6 ms).
#include <timeapi.h>
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
@@ -201,6 +203,9 @@ UdpRelay::UdpRelay(std::unique_ptr<Impl> impl) : impl_{std::move(impl)} {}
UdpRelay::~UdpRelay() { UdpRelay::~UdpRelay() {
impl_->stop.store(true); impl_->stop.store(true);
#ifdef _WIN32
timeEndPeriod(1);
#endif
if (impl_->thread.joinable()) if (impl_->thread.joinable())
impl_->thread.join(); impl_->thread.join();
if (impl_->client_side != invalid) if (impl_->client_side != invalid)
@@ -213,6 +218,7 @@ std::unique_ptr<UdpRelay> UdpRelay::start(std::uint16_t target_port, Impairment
Impairment downstream, std::uint64_t seed) { Impairment downstream, std::uint64_t seed) {
if (!startup() || target_port == 0) if (!startup() || target_port == 0)
return nullptr; return nullptr;
auto impl = std::make_unique<Impl>(); auto impl = std::make_unique<Impl>();
impl->client_side = bound_udp(0); impl->client_side = bound_udp(0);
impl->server_side = bound_udp(0); impl->server_side = bound_udp(0);
@@ -229,6 +235,11 @@ std::unique_ptr<UdpRelay> UdpRelay::start(std::uint16_t target_port, Impairment
impl->up = upstream; impl->up = upstream;
impl->down = downstream; impl->down = downstream;
impl->rng.state = seed; impl->rng.state = seed;
#ifdef _WIN32
// Delays are emulated with 1 ms waits; Windows' default timer tick (~15.6 ms) would
// add its own latency to every forwarded packet. Balanced by the destructor.
timeBeginPeriod(1);
#endif
std::unique_ptr<UdpRelay> relay{new UdpRelay{std::move(impl)}}; std::unique_ptr<UdpRelay> relay{new UdpRelay{std::move(impl)}};
auto* raw = relay->impl_.get(); auto* raw = relay->impl_.get();
raw->thread = std::thread{[raw] { raw->run(); }}; raw->thread = std::thread{[raw] { raw->run(); }};
+282
View File
@@ -0,0 +1,282 @@
// M10.2c head-of-line and loss measurement (ADR-0090): the same 20 Hz state stream sent
// on the QUIC DATAGRAM channel and on the single ordered reliable stream (the TCP-like
// case), through the owned impairment relay, across an RTT x loss matrix. Reliable
// 16 KiB messages once per second exercise multi-packet (fragmented) delivery. One
// process and one monotonic clock: latencies are one-way, staleness is the age of the
// newest state the client holds, sampled every 5 ms. Development reference only.
//
// evo-quic-hol-measure [--seconds 2..120] [--out FILE.csv]
#include "evo/network/dev_credentials.hpp"
#include "evo/network/quic_transport.hpp"
#include "udp_relay.hpp"
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <timeapi.h>
#include <windows.h>
#endif
#include <algorithm>
#include <charconv>
#include <chrono>
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <map>
#include <string>
#include <string_view>
#include <thread>
#include <vector>
namespace {
using namespace evo::network;
using namespace evo::network::quic;
using Clock = std::chrono::steady_clock;
struct Config {
int rtt_ms;
double loss;
};
struct Series {
std::vector<double> latency_ms, staleness_ms;
std::uint64_t sent{}, received{}, refused{};
};
double percentile(std::vector<double> v, double p) {
if (v.empty())
return -1;
std::sort(v.begin(), v.end());
const auto rank =
static_cast<std::size_t>(p / 100.0 * static_cast<double>(v.size()) + 0.999999);
return v[std::clamp<std::size_t>(rank, 1, v.size()) - 1];
}
std::vector<std::uint8_t> stamp(std::uint32_t seq, std::int64_t sent_us, std::size_t size) {
std::vector<std::uint8_t> v(size, 0);
const auto t = static_cast<std::uint64_t>(sent_us);
for (std::size_t i = 0; i < 4; ++i)
v[i] = static_cast<std::uint8_t>(seq >> (8U * i));
for (std::size_t i = 0; i < 8; ++i)
v[4 + i] = static_cast<std::uint8_t>(t >> (8U * i));
return v;
}
std::int64_t sent_at(const std::vector<std::uint8_t>& v) {
std::uint64_t t = 0;
for (std::size_t i = 0; i < 8; ++i)
t |= static_cast<std::uint64_t>(v[4 + i]) << (8U * i);
return static_cast<std::int64_t>(t);
}
std::uint32_t seq_of(const std::vector<std::uint8_t>& v) {
return static_cast<std::uint32_t>(v[0]) | (static_cast<std::uint32_t>(v[1]) << 8U) |
(static_cast<std::uint32_t>(v[2]) << 16U) | (static_cast<std::uint32_t>(v[3]) << 24U);
}
struct Result {
Config config{};
Series datagram, stream, bulk;
impair::RelayCounters relay{};
bool connected{};
};
Result run(const Config& config, int seconds, const std::filesystem::path& dir,
const std::string& ca_pem) {
Result r;
r.config = config;
ServerConfig sc;
sc.certificate_pem_file = (dir / "server.pem").string();
sc.key_pem_file = (dir / "server.key").string();
auto server = Endpoint::serve(sc);
if (!server)
return r;
impair::Impairment way;
way.delay = std::chrono::milliseconds{config.rtt_ms / 2};
way.jitter = std::chrono::milliseconds{std::max(1, config.rtt_ms / 20)};
way.loss = config.loss;
way.reorder = 0.02;
way.duplicate = 0.01;
auto relay = impair::UdpRelay::start((*server)->port(), way, way,
0xA11CE + static_cast<std::uint64_t>(config.rtt_ms));
if (!relay)
return r;
ClientConfig cc;
cc.port = relay->port();
cc.server_name = "dev-region.evolution.test";
cc.authority_pem = ca_pem;
cc.authority_pem_file = (dir / "ca.pem").string();
auto client = Endpoint::connect(cc);
if (!client)
return r;
ConnectionId server_id = 0;
bool client_ready = false;
const auto connect_end = Clock::now() + std::chrono::seconds{15};
while (Clock::now() < connect_end && (server_id == 0 || !client_ready)) {
for (const auto& e : (*server)->poll())
if (e.kind == EventKind::connected)
server_id = e.connection;
for (const auto& e : (*client)->poll())
if (e.kind == EventKind::connected)
client_ready = true;
std::this_thread::sleep_for(std::chrono::milliseconds{1});
}
if (server_id == 0 || !client_ready)
return r;
// Measure only once the datagram channel is negotiated (earlier sends would be refused).
while (Clock::now() < connect_end && (*server)->datagram_limit(server_id) == 0) {
(void)(*server)->poll();
(void)(*client)->poll();
std::this_thread::sleep_for(std::chrono::milliseconds{1});
}
if ((*server)->datagram_limit(server_id) == 0)
return r;
r.connected = true;
const auto origin = Clock::now();
const auto us = [&](Clock::time_point t) {
return std::chrono::duration_cast<std::chrono::microseconds>(t - origin).count();
};
const auto end = origin + std::chrono::seconds{seconds};
auto next_state = origin;
auto next_bulk = origin + std::chrono::milliseconds{500};
auto next_sample = origin;
std::uint32_t seq = 0, bulk_seq = 0;
std::int64_t newest_datagram = -1, newest_stream = -1;
std::uint32_t newest_datagram_seq = 0, newest_stream_seq = 0;
while (Clock::now() < end) {
const auto now = Clock::now();
if (now >= next_state) { // 20 Hz state on both channels (300 bytes).
const auto t = us(now);
++seq;
++r.datagram.sent;
++r.stream.sent;
if (!(*server)->send_datagram(server_id, stamp(seq, t, 300)))
++r.datagram.refused;
if (!(*server)->send_message(server_id, stamp(seq, t, 300)))
++r.stream.refused;
next_state += std::chrono::milliseconds{50};
}
if (now >= next_bulk) { // Once per second a multi-packet reliable message.
++r.bulk.sent;
if (!(*server)->send_message(
server_id, stamp(1000000 + ++bulk_seq, us(now), std::size_t{16} * 1024)))
++r.bulk.refused;
next_bulk += std::chrono::seconds{1};
}
(void)(*server)->poll();
for (const auto& e : (*client)->poll()) {
const double latency =
static_cast<double>(us(Clock::now()) - sent_at(e.bytes)) / 1000.0;
if (e.kind == EventKind::datagram) {
++r.datagram.received;
r.datagram.latency_ms.push_back(latency);
if (seq_of(e.bytes) > newest_datagram_seq) {
newest_datagram_seq = seq_of(e.bytes);
newest_datagram = sent_at(e.bytes);
}
} else if (e.kind == EventKind::message && e.bytes.size() > 1000) {
++r.bulk.received;
r.bulk.latency_ms.push_back(latency);
} else if (e.kind == EventKind::message) {
++r.stream.received;
r.stream.latency_ms.push_back(latency);
newest_stream_seq = std::max(newest_stream_seq, seq_of(e.bytes));
newest_stream = sent_at(e.bytes);
}
}
if (now >= next_sample) {
const auto t = static_cast<double>(us(now));
if (newest_datagram >= 0)
r.datagram.staleness_ms.push_back((t - static_cast<double>(newest_datagram)) /
1000.0);
if (newest_stream >= 0)
r.stream.staleness_ms.push_back((t - static_cast<double>(newest_stream)) / 1000.0);
next_sample += std::chrono::milliseconds{5};
}
std::this_thread::sleep_for(std::chrono::microseconds{200});
}
r.relay = relay->counters();
return r;
}
void print(const char* channel, const Result& r, const Series& s) {
std::printf(
"hol rtt=%dms loss=%.0f%% %-8s sent=%llu recv=%llu refused=%llu latency p50=%.1f p95=%.1f "
"p99=%.1f "
"max=%.1f staleness p50=%.1f p95=%.1f p99=%.1f\n",
r.config.rtt_ms, r.config.loss * 100, channel, static_cast<unsigned long long>(s.sent),
static_cast<unsigned long long>(s.received), static_cast<unsigned long long>(s.refused),
percentile(s.latency_ms, 50), percentile(s.latency_ms, 95), percentile(s.latency_ms, 99),
s.latency_ms.empty() ? -1.0 : *std::max_element(s.latency_ms.begin(), s.latency_ms.end()),
percentile(s.staleness_ms, 50), percentile(s.staleness_ms, 95),
percentile(s.staleness_ms, 99));
}
} // namespace
int main(int argc, char** argv) {
int seconds = 15;
std::string out;
for (int i = 1; i + 1 < argc; i += 2) {
const std::string_view flag{argv[i]};
const std::string_view value{argv[i + 1]};
if (flag == "--seconds") {
const auto [p, ec] =
std::from_chars(value.data(), value.data() + value.size(), seconds);
if (ec != std::errc{} || seconds < 2 || seconds > 120)
return 2;
} else if (flag == "--out") {
out = value;
} else {
std::fputs("usage: evo-quic-hol-measure [--seconds 2..120] [--out FILE.csv]\n", stderr);
return 2;
}
}
#ifdef _WIN32
timeBeginPeriod(1); // The measurement loop's short sleeps (see the relay).
#endif
const auto creds =
generate_dev_credentials(DeploymentEnvironment::dev, "dev-region.evolution.test", 1,
std::chrono::system_clock::now());
if (!creds)
return 1;
const auto dir = std::filesystem::temp_directory_path() / "evo-quic-hol";
std::filesystem::remove_all(dir);
std::filesystem::create_directories(dir);
for (const auto& [name, text] :
std::map<std::string, std::string>{{"ca.pem", creds->authority_pem},
{"server.pem", creds->server_certificate_pem},
{"server.key", creds->server_key_pem}}) {
std::ofstream f{dir / name, std::ios::binary | std::ios::trunc};
f << text;
}
std::ofstream csv;
if (!out.empty()) {
csv.open(out, std::ios::trunc);
csv << "rtt_ms,loss,channel,kind,value_ms\n";
}
int failures = 0;
for (const int rtt : {2, 50, 100})
for (const double loss : {0.0, 0.01, 0.05, 0.10}) {
const auto r = run({rtt, loss}, seconds, dir, creds->authority_pem);
if (!r.connected) {
std::printf("hol rtt=%dms loss=%.0f%% connection failed\n", rtt, loss * 100);
++failures;
continue;
}
print("datagram", r, r.datagram);
print("stream", r, r.stream);
print("bulk16k", r, r.bulk);
std::printf("hol rtt=%dms loss=%.0f%% relay forwarded=%llu dropped=%llu reordered=%llu "
"duplicated=%llu\n",
rtt, loss * 100, static_cast<unsigned long long>(r.relay.forwarded),
static_cast<unsigned long long>(r.relay.dropped),
static_cast<unsigned long long>(r.relay.reordered),
static_cast<unsigned long long>(r.relay.duplicated));
std::fflush(stdout);
if (csv)
for (const auto& [channel, series] :
{std::pair{"datagram", &r.datagram}, std::pair{"stream", &r.stream},
std::pair{"bulk16k", &r.bulk}}) {
for (const auto v : series->latency_ms)
csv << rtt << ',' << loss << ',' << channel << ",latency," << v << '\n';
for (const auto v : series->staleness_ms)
csv << rtt << ',' << loss << ',' << channel << ",staleness," << v << '\n';
}
}
std::filesystem::remove_all(dir);
return failures == 0 ? 0 : 1;
}