summaryrefslogtreecommitdiff
path: root/test/replicas.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/replicas.zig')
-rw-r--r--test/replicas.zig320
1 files changed, 268 insertions, 52 deletions
diff --git a/test/replicas.zig b/test/replicas.zig
index cdb161e8..f3618cf1 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -5,18 +5,30 @@
//! puts them all in one, where they clash at every key: a stress of
//! correctness, not a picture of a session.
//!
-//! zig build replicas -Dplatform=tty -- [--seeds N] [--steps M] [--clients C] [--rtt 30,80,207] [--first K] [--shared]
+//! Terminals cross as screen state (src/screen_state.zig): the session's
+//! shell pane runs a full-screen program and then a `yes` flood (`--flood`
+//! MB of it) while the clients type, its output stepped by the authority
+//! and sent to each replica as deltas, once a frame and before any input
+//! the authority steps, each replica acknowledging them over its link and
+//! asking for the rows it scrolls back into and does not hold.
+//!
+//! zig build replicas -Dplatform=tty -- [--seeds N] [--steps M] [--clients C] [--rtt 30,80,207] [--first K] [--flood MB] [--shared]
//!
//! Gates, per seed and RTT: no replica diverges (every confirmed unit's
//! digests agree as it is replayed), and at quiescence every replica's
-//! digest is the authority's. Reported per RTT: how inputs went (applied at
-//! once, stopped at a host call, left to the authority), how units were
-//! taken (fast path, rollback for a misprediction or another's input), and
-//! what a speculative apply, a copy and a rollback cost against a frame.
+//! digest is the authority's; every delta a replica applies leaves its
+//! terminal what the authority's was at that version, and at quiescence it
+//! is the authority's, cell for cell. Reported per RTT: how inputs went
+//! (applied at once, stopped at a host call, left to the authority), how
+//! units were taken (fast path, rollback for a misprediction or another's
+//! input), what a speculative apply, a copy and a rollback cost against a
+//! frame, and the terminals': deltas a second, wire bytes a second under
+//! the flood, encode a frame (every peer), apply a delta.
const std = @import("std");
const libc = std.c;
const pardes = @import("pardes");
const replica = pardes.replica;
+const screen_state = pardes.screen_state;
const Key = pardes.Key;
const gpa = std.heap.c_allocator;
@@ -46,7 +58,7 @@ const Host = struct {
}
};
-const Kind = enum { input, to_authority, to_replica, echo };
+const Kind = enum { input, to_authority, to_replica, echo, frame, output, screen_down, screen_up };
const Msg = struct {
at: u64,
@@ -89,6 +101,21 @@ const Totals = struct {
spec_ns: std.ArrayListUnmanaged(u64) = .empty,
copy_ns: std.ArrayListUnmanaged(u64) = .empty,
rollback_ns: std.ArrayListUnmanaged(u64) = .empty,
+ // Terminals.
+ apply_ns: std.ArrayListUnmanaged(u64) = .empty,
+ frame_ns: std.ArrayListUnmanaged(u64) = .empty,
+ deltas: u64 = 0,
+ delta_bytes: u64 = 0,
+ unit_bytes: u64 = 0,
+ /// Deltas the replicas applied while the flood ran.
+ flood_deltas: u64 = 0,
+ flood_us: u64 = 0,
+ flood_delta_bytes: u64 = 0,
+ flood_unit_bytes: u64 = 0,
+ fetched: u64 = 0,
+ resets: u64 = 0,
+ screens_wrong: u64 = 0,
+ screens_checked: u64 = 0,
fn add(t: *Totals, s: *const replica.Stats) !void {
t.inputs += s.inputs;
@@ -105,14 +132,16 @@ const Totals = struct {
try t.spec_ns.appendSlice(gpa, s.spec_ns.items);
try t.copy_ns.appendSlice(gpa, s.copy_ns.items);
try t.rollback_ns.appendSlice(gpa, s.rollback_ns.items);
+ try t.apply_ns.appendSlice(gpa, s.apply_ns.items);
}
};
-/// One client's next input: monkey.zig's mix, as events.
-fn nextEvent(random: std.Random, buf: *[64]u8) pardes.Event {
+/// One client's next input: monkey.zig's mix, as events, and now and then
+/// a wheel over the shell pane, which scrolls its history into view.
+fn nextEvent(random: std.Random, buf: *[64]u8, wheel_at: ?[2]u16) pardes.Event {
const typed = "abcdefghijklmnopqrstuvwxyz0123456789 -_=+,:;()";
const normal = "hjklwbe0$xpuyoOiaAIdcv.nN%sC";
- switch (random.uintLessThan(u8, 40)) {
+ switch (random.uintLessThan(u8, 42)) {
0...15 => {
buf[0] = typed[random.uintLessThan(usize, typed.len)];
return .{ .key = .{ .cp = buf[0], .text = buf[0..1] } };
@@ -143,7 +172,11 @@ fn nextEvent(random: std.Random, buf: *[64]u8) pardes.Event {
} },
37 => return .{ .resize = .{ .cols = @intCast(random.intRangeAtMost(u16, 60, 120)), .rows = @intCast(random.intRangeAtMost(u16, 16, 40)) } },
38 => return .{ .mouse = .{ .button = .left, .kind = .press, .col = random.uintLessThan(u16, 80), .row = random.uintLessThan(u16, 24) } },
- else => return .{ .mouse = .{ .button = .left, .kind = .release, .col = random.uintLessThan(u16, 80), .row = random.uintLessThan(u16, 24) } },
+ 39 => return .{ .mouse = .{ .button = .left, .kind = .release, .col = random.uintLessThan(u16, 80), .row = random.uintLessThan(u16, 24) } },
+ else => {
+ const at = wheel_at orelse return .{ .key = .{ .cp = Key.escape } };
+ return .{ .mouse = .{ .button = if (random.uintLessThan(u8, 3) == 0) .wheel_down else .wheel_up, .kind = .press, .col = at[0], .row = at[1] } };
+ },
}
}
@@ -158,7 +191,16 @@ fn writeFile(path: [:0]const u8, lines: usize) !void {
}
}
-const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, shared: bool };
+const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, shared: bool, flood_mb: u64 };
+
+/// The terminal pane's screen as a hash of screen_state's dump of it.
+fn screenHash(t: *pardes.panes.terminal.VtSlot) u64 {
+ var buf: [8192]u8 = undefined;
+ var h: std.Io.Writer.Hashing(std.hash.Wyhash) = .initHasher(.init(0), &buf);
+ screen_state.dumpScreen(t, &h.writer) catch {};
+ h.writer.flush() catch {};
+ return h.hasher.final();
+}
fn run(r: Run, dir: []const u8, totals: *Totals) !void {
if (trace) std.debug.print("seed {d} rtt {d} ms\n", .{ r.seed, r.rtt_ms });
@@ -176,13 +218,22 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
}
// The tty's own boot (a raw shell, a text pane under it), then three
// files looked at: keys go to the last, a pane's shell echoes.
- const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, host.host());
+ const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, host.host(), true);
defer a.deinit();
+ var screens: replica.Screens = .init(gpa);
+ defer screens.deinit(a.core);
const first = try gpa.dupe(u8, try a.unit(0, 0));
defer gpa.free(first);
var reps: [8]*replica.Replica = undefined;
- for (reps[0..r.clients], 1..) |*rp, id| rp.* = try replica.Replica.init(gpa, @intCast(id), first);
+ var peers: [8]u16 = undefined;
+ for (reps[0..r.clients], peers[0..r.clients], 1..) |*rp, *peer, id| {
+ rp.* = try replica.Replica.init(gpa, @intCast(id), first, true);
+ peer.* = try screens.addPeer();
+ }
defer for (reps[0..r.clients]) |rp| rp.deinit();
+ const shell: u8 = for (a.core.panes, 0..) |slot, id| {
+ if (slot) |pane| if (pane.isTerminal()) break @intCast(id);
+ } else return error.NoShell;
for (&paths) |*path| {
var line: [300]u8 = undefined;
const unit = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{std.mem.sliceTo(path, 0)}) });
@@ -195,26 +246,87 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
rp.view = opened.view;
for (reps[0..r.clients]) |each| each.confirm(opened.unit);
};
+ // Where a wheel over the shell lands in the session's view (the first
+ // client's); the others' views put it elsewhere, and their wheels hit
+ // whatever is there.
+ const sr = a.core.rects[shell];
+ const wheel_at: ?[2]u16 = if (sr.h > 2) .{ sr.x + sr.w / 2, sr.y + sr.h / 2 } else null;
+
+ // What the shell's program prints: a full-screen program, then a flood
+ // of `yes`, read 4 KB at a time as a pty gives it.
+ const tui = try screen_state.tuiStream(gpa);
+ defer gpa.free(tui);
+ const yes = try screen_state.yesStream(gpa, @intCast(r.flood_mb * (1 << 20) / 3));
+ defer gpa.free(yes);
+ const tui_at: u64 = 400_000;
+ const flood_at: u64 = 1_500_000;
+ var flood_end: u64 = 0;
+ var program: struct { bytes: []const u8 = &.{}, at: usize = 0 } = .{};
+ // The authority's version of each terminal, as its screen showed then.
+ var versions: std.AutoHashMapUnmanaged(u64, u64) = .empty;
+ defer versions.deinit(gpa);
+ var flood_deltas: [8]u64 = @splat(0);
+
var queue: std.PriorityQueue(Msg, void, Msg.order) = .empty;
- defer queue.deinit(gpa);
+ defer {
+ while (queue.pop()) |m| if (m.bytes.len > 0) gpa.free(m.bytes);
+ queue.deinit(gpa);
+ }
var n: u64 = 0;
const one_way = r.rtt_ms * 1000 / 2;
const jitter = one_way / 10;
var up: [8]Link = @splat(.{});
var down: [8]Link = @splat(.{});
var left: [8]usize = @splat(r.steps);
- // Each client's first input, soon.
- for (0..r.clients) |c| {
- try queue.push(gpa, .{ .at = random.uintLessThan(u64, 200_000), .n = n, .kind = .input, .who = @intCast(c + 1), .bytes = &.{} });
- n += 1;
- }
+ var typing: usize = r.clients;
+ const push = struct {
+ fn f(q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, m: Msg) !void {
+ var mm = m;
+ mm.n = nn.*;
+ nn.* += 1;
+ try q.push(gpa, mm);
+ }
+ }.f;
+ // Each client's first input, soon; the programs; the first frame.
+ for (0..r.clients) |c| try push(&queue, &n, .{ .at = random.uintLessThan(u64, 200_000), .n = 0, .kind = .input, .who = @intCast(c + 1), .bytes = &.{} });
+ try push(&queue, &n, .{ .at = tui_at, .n = 0, .kind = .output, .who = 0, .bytes = &.{} });
+ try push(&queue, &n, .{ .at = flood_at, .n = 0, .kind = .output, .who = 1, .bytes = &.{} });
+ try push(&queue, &n, .{ .at = frame_us, .n = 0, .kind = .frame, .who = 0, .bytes = &.{} });
+ var frames_left: u32 = 0;
+ var flood_units: u64 = 0;
+
+ // What each peer is owed of the terminals, onto its link: before the
+ // authority steps an input, and once a frame.
+ var owed: std.ArrayListUnmanaged([]u8) = .empty;
+ defer owed.deinit(gpa);
+ const flushAll = struct {
+ fn f(sc: *replica.Screens, core: *pardes.Pardes, ps: []const u16, list: *std.ArrayListUnmanaged([]u8), q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, now: u64, dl: []Link, rnd: std.Random, ow: u64, jt: u64, vs: *std.AutoHashMapUnmanaged(u64, u64), tot: *Totals) !void {
+ for (ps, 0..) |peer, c| {
+ list.clearRetainingCapacity();
+ try sc.flush(core, peer, list);
+ for (list.items) |bytes| {
+ tot.deltas += 1;
+ tot.delta_bytes += bytes.len;
+ try push(q, nn, .{ .at = dl[c].arrive(rnd, now, ow, jt), .n = 0, .kind = .screen_down, .who = @intCast(c + 1), .bytes = bytes });
+ }
+ }
+ // Each version as the authority's screen showed it.
+ for (&sc.tracks, 0..) |*slot, id| if (slot.*) |*tr| {
+ const key = @as(u64, tr.serial) << 32 | tr.track.version;
+ if (tr.track.version == 0 or vs.contains(key)) continue;
+ _ = core.panes[id] orelse continue;
+ try vs.put(gpa, key, screenHash(&tr.state.vt));
+ };
+ }
+ }.f;
+
while (queue.pop()) |m| {
defer if (m.bytes.len > 0) gpa.free(m.bytes);
switch (m.kind) {
.input => {
const c = m.who - 1;
var buf: [64]u8 = undefined;
- const ev = nextEvent(random, &buf);
+ const ev = nextEvent(random, &buf, if (c == 0) wheel_at else null);
const before = reps[c].stats;
const msg = try gpa.dupe(u8, try reps[c].input(ev));
if (trace) std.debug.print("{d} ms client {d}: {t} {s} -> {s}\n", .{ m.at / 1000, m.who, ev, switch (ev) {
@@ -223,39 +335,96 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
.command => |t| t,
else => "",
}, if (reps[c].stats.speculated > before.speculated) "applied" else if (reps[c].stats.stopped > before.stopped) "STOPPED" else if (reps[c].stats.unspeculated > before.unspeculated) "view" else "waits" });
- try queue.push(gpa, .{ .at = up[c].arrive(random, m.at, one_way, jitter), .n = n, .kind = .to_authority, .who = m.who, .bytes = msg });
- n += 1;
+ try push(&queue, &n, .{ .at = up[c].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .to_authority, .who = m.who, .bytes = msg });
left[c] -= 1;
if (left[c] > 0) {
// A typist: keys 50-200 ms apart, a pause now and then.
const gap: u64 = if (random.uintLessThan(u8, 12) == 0) random.intRangeAtMost(u64, 300_000, 1_500_000) else random.intRangeAtMost(u64, 50_000, 200_000);
- try queue.push(gpa, .{ .at = m.at + gap, .n = n, .kind = .input, .who = m.who, .bytes = &.{} });
- n += 1;
- }
+ try push(&queue, &n, .{ .at = m.at + gap, .n = 0, .kind = .input, .who = m.who, .bytes = &.{} });
+ } else typing -= 1;
},
- .to_authority, .echo => {
- const unit = if (m.kind == .echo)
- try a.local(.{ .output = .{ .pane = @intCast(m.who), .bytes = m.bytes } })
- else
- try a.take(m.bytes);
- for (0..r.clients) |c| {
- const copy = try gpa.dupe(u8, unit);
- try queue.push(gpa, .{ .at = down[c].arrive(random, m.at, one_way, jitter), .n = n, .kind = .to_replica, .who = @intCast(c + 1), .bytes = copy });
- n += 1;
- }
- for (host.echo.items) |e| {
- try queue.push(gpa, .{ .at = m.at + 2_000, .n = n, .kind = .echo, .who = e.pane, .bytes = e.bytes });
- n += 1;
- }
+ .to_authority, .echo, .output => {
+ const unit = switch (m.kind) {
+ .echo => echo: {
+ a.output(.{ .output = .{ .pane = @intCast(m.who), .bytes = m.bytes } });
+ break :echo null;
+ },
+ .output => out: {
+ // The program's next read, 4 KB, then the next a
+ // fraction of a millisecond on (ghostty's pace).
+ if (program.at == program.bytes.len) {
+ program = .{ .bytes = if (m.who == 0) tui else yes };
+ }
+ const k = @min(program.bytes.len - program.at, if (m.who == 0) @as(usize, 700) else 4096);
+ const chunk = program.bytes[program.at..][0..k];
+ program.at += k;
+ if (program.at < program.bytes.len)
+ try push(&queue, &n, .{ .at = m.at + if (m.who == 0) @as(u64, 3_000) else 450, .n = 0, .kind = .output, .who = m.who, .bytes = &.{} })
+ else if (m.who == 1) flood_end = m.at;
+ if (m.who == 1) flood_units += 1;
+ a.output(.{ .output = .{ .pane = shell, .bytes = chunk } });
+ break :out null;
+ },
+ else => in: {
+ // The authority's own steps since the last unit, and
+ // the terminals as they are: what the input's step
+ // reads, before it is stepped.
+ if (try a.pending()) |batch| try sendUnit(&queue, &n, batch, m.at, down[0..r.clients], random, one_way, jitter, totals, m.at >= flood_at and flood_end == 0);
+ try flushAll(&screens, a.core, peers[0..r.clients], &owed, &queue, &n, m.at, &down, random, one_way, jitter, &versions, totals);
+ break :in try a.take(m.bytes);
+ },
+ };
+ if (unit) |u| try sendUnit(&queue, &n, u, m.at, down[0..r.clients], random, one_way, jitter, totals, false);
+ for (host.echo.items) |e| try push(&queue, &n, .{ .at = m.at + 2_000, .n = 0, .kind = .echo, .who = e.pane, .bytes = e.bytes });
host.echo.clearRetainingCapacity();
},
- .to_replica => {
- const rp = reps[m.who - 1];
- rp.confirm(m.bytes);
- rp.settle();
+ .frame => {
+ if (try a.pending()) |batch| try sendUnit(&queue, &n, batch, m.at, down[0..r.clients], random, one_way, jitter, totals, m.at >= flood_at and flood_end == 0);
+ const t0 = screens.encode_ns;
+ const before = totals.delta_bytes;
+ try flushAll(&screens, a.core, peers[0..r.clients], &owed, &queue, &n, m.at, &down, random, one_way, jitter, &versions, totals);
+ if (screens.encode_ns > t0) try totals.frame_ns.append(gpa, screens.encode_ns - t0);
+ if (m.at >= flood_at and (flood_end == 0 or m.at <= flood_end)) totals.flood_delta_bytes += totals.delta_bytes - before;
+ // Frames go on while anything moves, and a second after.
+ const busy = typing > 0 or flood_end == 0 or queue.count() > 0;
+ frames_left = if (busy) 60 else frames_left -| 1;
+ if (frames_left > 0) try push(&queue, &n, .{ .at = m.at + frame_us, .n = 0, .kind = .frame, .who = 0, .bytes = &.{} });
+ },
+ .to_replica, .screen_down => {
+ const c = m.who - 1;
+ const rp = reps[c];
+ if (m.kind == .to_replica) {
+ rp.confirm(m.bytes);
+ rp.settle();
+ } else if (rp.screen(m.bytes)) |reply| {
+ const pane = m.bytes[0];
+ if (reply[5] == 1) {
+ // Applied: the screen is the authority's at that version.
+ const sc = rp.screens[pane].?;
+ const vt = &rp.core().panes[pane].?.terminal.?.vt;
+ totals.screens_checked += 1;
+ if (versions.get(@as(u64, sc.serial) << 32 | sc.rep.seq)) |want| {
+ if (want != screenHash(vt)) {
+ totals.screens_wrong += 1;
+ std.debug.print("seed {d} rtt {d} ms: replica {d}'s terminal {d} at version {d} is not the authority's\n", .{ r.seed, r.rtt_ms, m.who, pane, sc.rep.seq });
+ }
+ } else totals.screens_wrong += 1;
+ // Deltas while the flood runs (an RTT/2 behind it).
+ if (m.at >= flood_at + one_way and (flood_end == 0 or m.at <= flood_end + one_way)) flood_deltas[c] += 1;
+ } else totals.resets += 1;
+ try push(&queue, &n, .{ .at = up[c].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .screen_up, .who = m.who, .bytes = try gpa.dupe(u8, reply) });
+ }
+ if (rp.screenRequest()) |req| try push(&queue, &n, .{ .at = up[c].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .screen_up, .who = m.who, .bytes = try gpa.dupe(u8, req) });
+ },
+ .screen_up => {
+ const c = m.who - 1;
+ if (m.bytes[5] == 2) totals.fetched += std.mem.readInt(u64, m.bytes[14..22], .little) - std.mem.readInt(u64, m.bytes[6..14], .little);
+ if (try screens.take(a.core, peers[c], m.bytes)) |answer| try push(&queue, &n, .{ .at = down[c].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .screen_down, .who = m.who, .bytes = answer });
},
}
}
+ totals.flood_us += flood_end -| flood_at;
+ for (flood_deltas[0..r.clients]) |d| totals.flood_deltas += d;
const want = replica.digestOf(a);
for (reps[0..r.clients], 1..) |rp, id| {
try totals.add(&rp.stats);
@@ -266,6 +435,29 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
totals.unequal += 1;
std.debug.print("seed {d} rtt {d} ms: replica {d} at quiescence: {s}\n", .{ r.seed, r.rtt_ms, id, if (rp.quiet()) "another digest" else "inputs still pending" });
}
+ // At quiescence, every terminal the authority's, cell for cell.
+ for (a.core.panes, 0..) |slot, pid| {
+ const pane = slot orelse continue;
+ const state = pane.terminal orelse continue;
+ const mine = (rp.core().panes[pid] orelse {
+ totals.unequal += 1;
+ continue;
+ }).terminal orelse continue;
+ if (screenHash(&state.vt) != screenHash(&mine.vt)) {
+ totals.unequal += 1;
+ std.debug.print("seed {d} rtt {d} ms: replica {d}'s terminal {d} at quiescence is not the authority's\n", .{ r.seed, r.rtt_ms, id, pid });
+ }
+ }
+ }
+}
+
+/// A unit of the authority's to every replica, down its link.
+fn sendUnit(q: *std.PriorityQueue(Msg, void, Msg.order), n: *u64, unit: []const u8, now: u64, down: []Link, random: std.Random, one_way: u64, jitter: u64, totals: *Totals, flooding: bool) !void {
+ totals.unit_bytes += unit.len * down.len;
+ if (flooding) totals.flood_unit_bytes += unit.len * down.len;
+ for (down, 1..) |*l, who| {
+ try q.push(gpa, .{ .at = l.arrive(random, now, one_way, jitter), .n = n.*, .kind = .to_replica, .who = @intCast(who), .bytes = try gpa.dupe(u8, unit) });
+ n.* += 1;
}
}
@@ -283,15 +475,19 @@ pub fn main(init: std.process.Init) !void {
var clients: u16 = 3;
var rtts: []const u64 = &.{ 30, 80, 207 };
var shared = false;
+ var flood_mb: u64 = 8;
var rtt_buf: [8]u64 = undefined;
var i: usize = 1;
- while (i < args.len and std.mem.eql(u8, args[i], "--shared")) : (i += 1) shared = true;
- while (i + 1 < args.len) : (i += 2) {
- while (i < args.len and std.mem.eql(u8, args[i], "--shared")) : (i += 1) shared = true;
- if (i + 1 >= args.len) break;
+ while (i < args.len) : (i += 1) {
const name = args[i];
- const value = args[i + 1];
- if (std.mem.eql(u8, name, "--seeds")) seeds = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--first")) first = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--steps")) steps = try std.fmt.parseInt(usize, value, 10) else if (std.mem.eql(u8, name, "--clients")) clients = @min(8, try std.fmt.parseInt(u16, value, 10)) else if (std.mem.eql(u8, name, "--rtt")) {
+ if (std.mem.eql(u8, name, "--shared")) {
+ shared = true;
+ continue;
+ }
+ if (i + 1 >= args.len) return error.MissingValue;
+ i += 1;
+ const value = args[i];
+ if (std.mem.eql(u8, name, "--seeds")) seeds = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--first")) first = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--steps")) steps = try std.fmt.parseInt(usize, value, 10) else if (std.mem.eql(u8, name, "--clients")) clients = @min(8, try std.fmt.parseInt(u16, value, 10)) else if (std.mem.eql(u8, name, "--flood")) flood_mb = try std.fmt.parseInt(u64, value, 10) else if (std.mem.eql(u8, name, "--rtt")) {
var it = std.mem.tokenizeScalar(u8, value, ',');
var k: usize = 0;
while (it.next()) |v| : (k += 1) rtt_buf[k] = try std.fmt.parseInt(u64, v, 10);
@@ -306,11 +502,13 @@ pub fn main(init: std.process.Init) !void {
try std.Io.Dir.createDirAbsolute(init.io, dir, .default_dir);
defer std.Io.Dir.cwd().deleteTree(init.io, dir) catch {};
var failed = false;
- std.debug.print("{d} seeds x {d} inputs from each of {d} clients, {s}; costs in us (frame {d})\n", .{ seeds, steps, clients, if (shared) "sharing one view" else "a view each", frame_us });
+ std.debug.print("{d} seeds x {d} inputs from each of {d} clients, {s}, a TUI then {d} MB of yes in the shell; costs in us (frame {d})\n", .{ seeds, steps, clients, if (shared) "sharing one view" else "a view each", flood_mb, frame_us });
std.debug.print(" rtt inputs at-once stopped view units fast rollback(mis+foreign) rate rebase spec p50/p99 copy p50/p99 (KB) rollback p50/p99 diverged unequal\n", .{});
+ var term_lines: std.ArrayList(u8) = .empty;
+ defer term_lines.deinit(gpa);
for (rtts) |rtt| {
var t: Totals = .{};
- for (first..first + seeds) |seed| try run(.{ .seed = seed, .rtt_ms = rtt, .steps = steps, .clients = clients, .shared = shared }, dir, &t);
+ for (first..first + seeds) |seed| try run(.{ .seed = seed, .rtt_ms = rtt, .steps = steps, .clients = clients, .shared = shared, .flood_mb = flood_mb }, dir, &t);
const rollbacks = t.mispredicted + t.foreign;
std.debug.print("{d:>4} {d:>6} {d:>7} {d:>7} {d:>4} {d:>6} {d:>6} {d:>6} ({d}+{d}) {d:>5.1}% {d:>6} {d:>5}/{d:<6} {d:>5}/{d:<5} ({d}) {d:>7}/{d:<7} {d:>8} {d:>7}\n", .{
rtt, t.inputs, t.speculated,
@@ -321,7 +519,25 @@ pub fn main(init: std.process.Init) !void {
pct(t.copy_ns.items, 99) / 1000, t.copy_bytes / @max(t.copies, 1) / 1024, pct(t.rollback_ns.items, 50) / 1000,
pct(t.rollback_ns.items, 99) / 1000, t.divergences, t.unequal,
});
- if (t.divergences > 0 or t.unequal > 0) failed = true;
+ const flood_s = @as(f64, @floatFromInt(@max(1, t.flood_us))) / 1e6;
+
+ try term_lines.print(gpa, "{d:>4} {d:>7.1} {d:>9.0} {d:>9.0} {d:>5}/{d:<5} {d:>5}/{d:<5} {d:>7} {d:>6} {d:>6}/{d:<6}\n", .{
+ rtt,
+ @as(f64, @floatFromInt(t.flood_deltas)) / flood_s / @as(f64, @floatFromInt(clients)),
+ @as(f64, @floatFromInt(t.flood_delta_bytes)) / flood_s / @as(f64, @floatFromInt(clients)),
+ @as(f64, @floatFromInt(t.flood_unit_bytes)) / flood_s / @as(f64, @floatFromInt(clients)),
+ pct(t.frame_ns.items, 50) / 1000,
+ pct(t.frame_ns.items, 99) / 1000,
+ pct(t.apply_ns.items, 50) / 1000,
+ pct(t.apply_ns.items, 99) / 1000,
+ t.fetched,
+ t.resets,
+ t.screens_checked,
+ t.screens_wrong,
+ });
+ if (t.divergences > 0 or t.unequal > 0 or t.screens_wrong > 0) failed = true;
}
+ std.debug.print("terminals: deltas a replica applied a second under the flood; a peer's bytes a second under the flood (deltas, units); encode a frame for every peer, apply a delta (us); rows fetched; resets; deltas checked/wrong\n", .{});
+ std.debug.print(" rtt deltas/s delta B/s unit B/s encode p50/p99 apply p50/p99 fetched resets checked/wrong\n{s}", .{term_lines.items});
if (failed) std.process.exit(1);
}