From 40094a08394fc0ecba2876e4e934e2158b17bdab Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 22 Nov 2026 02:45:04 -0300 Subject: soak: ONE soak, the pty's bytes' (the old road's deletion, piece 1 of 8, the user's ruling of 2026-11-22): test/replicas.zig loses its screen-state mode and `--bytes` stops being a flag (its clients' terminals are always their own emulators fed the units' bytes, the session's Peers.bytes set): gone are the screen_down/screen_up messages, the `deltas wrong` check (screens_checked/screens_wrong/resets and the session's version-to-screen record, `flushed`, `versions`), the delta and fill counters (deltas, delta and filled bytes, rows fetched, encode and apply times: the terminals' table is now a peer's unit bytes a second under the flood), `flushAll` and the delta half of `sendUnit` (the old in-process rig), and the `--screen-state ` encoder soak (`screenState`, `encodeBench`, `floods`); kept on the one road: the quiescence check that every client's terminal is the session's cell for cell and its kitty images pixel for pixel, the witness (it never held screen messages), the image and kitty-answer checks (unconditional now), the join in the middle of the flood (client 4 at the flood's start + 100 ms, always), and `--echo`, rewired to the bytes road (Authority and Replica of the bytes kind, the echo armed by hand as a joined client's is; a key's echo seen when the client has fed the authority's unit after the one before its echo: `unit_before`, `fed`), its gates the same (diverged, unequal, secret frames, vim predicted, drawn wrong) less `screens-wrong`; the diff, plumb and corpus cases made on the bytes road too; the one soak is `zig build replicas -Dplatform=tui ... -- --clients 5`; checked: `--echo --seeds 1 --rtt 80` (rc 0, 0 diverged 0 unequal, 7.3 ms p50 with prediction against 105 ms without) and `--seeds 1 --steps 30 --clients 3 --rtt 80` (rc 0, diverged 0, unequal 0, unlisted 0, corpus 22 scenes, diff and plumb the same); core-test and shell-test do not build this file (the base's 911/1075 and 1117/1120); -424 +71 lines Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/replicas.zig | 495 ++++++++---------------------------------------------- 1 file changed, 71 insertions(+), 424 deletions(-) (limited to 'test') diff --git a/test/replicas.zig b/test/replicas.zig index 48eaa857..f1d5c478 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -12,32 +12,27 @@ //! and joins again for its view, and those past the views a session has //! are refused until one is let go. //! -//! Terminals cross as screen state (core/term/screen_state.zig): the session's -//! shell pane runs a full-screen program and then a flood (`--flood` MB of -//! `yes`, then as much of a `cat` of source text) 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. +//! Terminals cross as the pty's bytes in the session's units: the +//! session's shell pane runs a full-screen program and then a flood +//! (`--flood` MB of `yes`, then as much of a `cat` of source text) while the +//! clients type, and each client feeds its own emulators what its units +//! carry, in the tape's order. //! //! zig build replicas -Dplatform=tui -- [--seeds N] [--steps M] [--clients C] [--rtt 30,80,207] [--first K] [--flood MB] //! zig build replicas -Dplatform=tui -- --echo [--seeds N] [--rtt 30,80,207] [--first K] -//! zig build replicas -Dplatform=tui -Doptimize=ReleaseFast -- --screen-state //! //! `--echo` types a corpus into a shell instead, with and without the //! predicted echo (core/term/echo.zig), and gates what it draws: below, at -//! "predicted echo". `--screen-state` runs recorded pty streams through -//! screen_state's soak and measures its encoder: below, at screenState. +//! "predicted echo". //! //! 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 and every file's text are 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 +//! digest and every file's text are the authority's, and every terminal +//! 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. +//! frame, and a peer's unit bytes a second under the flood. const std = @import("std"); const libc = std.c; const pardes = @import("pardes"); @@ -53,10 +48,6 @@ const gpa = std.heap.c_allocator; pub const std_options: std.Options = .{ .log_level = .warn }; extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int; var trace = false; -/// `--bytes`: its clients are replicas of the bytes kind, each terminal fed -/// the pty's bytes its units carry into an emulator of its own, joined from -/// a dump with every emulator whole (core/replica.zig `Peers.bytes`). -var bytes_kind = false; /// `--witness`: the witness judged at every run's end, not only after a /// divergence (`Witness`). var witness_always = false; @@ -157,8 +148,6 @@ const Kind = enum { echo, frame, output, - screen_down, - screen_up, client_frame, /// The session's own frontend's input, in its own view. own, @@ -247,25 +236,12 @@ const Totals = struct { 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, /// Kitty images a client held at quiescence, the session's pixels /// (`--bytes`, `images`). images_equal: u64 = 0, - flood_delta_bytes: u64 = 0, flood_unit_bytes: u64 = 0, - fetched: u64 = 0, - /// Bytes of rows sent before a step's unit, the step having read them. - filled_bytes: u64 = 0, - resets: u64 = 0, - screens_wrong: u64 = 0, - screens_checked: u64 = 0, /// Joins from a dump, refused, again after a divergence put on it /// (PARDES_TEST_DIVERGE's), and clients that left; quiet checks. joins: u64 = 0, @@ -322,7 +298,6 @@ 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); } }; @@ -464,17 +439,7 @@ fn writeText(path: [:0]const u8, text: []const u8) !void { const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, flood_mb: u64 }; -/// The terminal pane's screen as a hash of screen_state's dump of it. -/// The module's own replica behind the core's handle (Replica.screens). -fn replicaOf(r: *pardes.Term.Replica) *screen_state.Replica { - return @ptrCast(@alignCast(r)); -} - -/// The module's own track behind the core's handle (Screens.tracks). -fn trackOf(t: *pardes.Term.Track) *screen_state.Track { - return @ptrCast(@alignCast(t)); -} - +/// The terminal pane's screen as a hash of a dump of its cells. fn screenHash(t: *screen_state.Terminal) u64 { var buf: [8192]u8 = undefined; var h: std.Io.Writer.Hashing(std.hash.Wyhash) = .initHasher(.init(0), &buf); @@ -1019,10 +984,8 @@ const Witness = struct { // No client's id: every unit is another's. const rp = try replica.Replica.initDump(gpa, std.math.maxInt(u16), d.view, d.bytes, .{ .cols = d.cols, .rows = d.rows, .distrusted = &distrusted }); rp.guess = false; - if (bytes_kind) { - rp.t.screen_state = false; - rp.core().echo = null; - } + rp.t.screen_state = false; + rp.core().echo = null; rp.t.local_files = true; return rp; } @@ -1225,19 +1188,12 @@ const Soak = struct { frames_left: u32 = 0, flood_end: u64 = 0, program: struct { bytes: []const u8 = &.{}, at: usize = 0 } = .{}, - /// The session's version of each terminal, as its screen showed then. - versions: std.AutoHashMapUnmanaged(u64, u64) = .empty, - flood_deltas: [8]u64 = @splat(0), kinds_seen: u32 = 0, /// Each client's link made (its first join), and its replica's. has_link: [8]bool = @splat(false), /// An input of its own frontend's held for the next wait, a pty's /// output taken in this one (tui.zig `split`). held: ?Msg = null, - /// The step boundary after a frame's wake under the flood: what its - /// encoding cost. - framed: bool = false, - encode_ns: u64 = 0, /// The session's pty told the answers to the program's kitty query and /// its four images (`questions`, `images`, `kitty_oks`): each once, whatever the /// clients. @@ -1340,8 +1296,7 @@ const Soak = struct { pub fn open(s: *Soak, l: *SessionLoop) !pardes.Host { s.l = l; l.peers.threads = false; - l.peers.bytes = bytes_kind; - l.peers.flushed = .{ .ctx = s, .f = flushed }; + l.peers.bytes = true; const host: pardes.Host = .{ .ctx = s, .vtable = &vtable }; l.core.host = host; return host; @@ -1368,7 +1323,6 @@ const Soak = struct { if (s.held) |m| if (m.bytes.len > 0) gpa.free(m.bytes); for (s.echo.items) |e| gpa.free(e.bytes); s.echo.deinit(gpa); - s.versions.deinit(gpa); } /// The tty's own boot (a raw shell, a text pane under it), then three @@ -1409,7 +1363,7 @@ const Soak = struct { 2 => 1_200_000, // One joins in the middle of the flood, its emulators loaded // whole and every other side's reloaded. - 3 => if (bytes_kind) flood_at + 100_000 else 2_300_000, + 3 => flood_at + 100_000, else => 2_000_000 + c * 100_000, }; try net.send(.{ .at = at, .n = 0, .kind = .dial, .who = @intCast(c + 1), .bytes = &.{} }); @@ -1511,7 +1465,7 @@ const Soak = struct { cl.view = welcome.view.index(); cl.digest = welcome.digest; s.totals.joins += 1; - if (bytes_kind) Witness.joined(c, cl, try gpa.dupe(u8, whole.items), cl.join_seq); // never given the screen deltas, it checks no screen-state run + Witness.joined(c, cl, try gpa.dupe(u8, whole.items), cl.join_seq); try net.toClient(c, now, .dump, cl.gen, try whole.toOwnedSlice(gpa)); }; // A Detach typed in a client's view, or one cut off for its lag: its @@ -1542,10 +1496,6 @@ const Soak = struct { }; for (s.echo.items) |e| try net.send(.{ .at = now + 2_000, .n = 0, .kind = .echo, .who = e.pane, .bytes = e.bytes }); s.echo.clearRetainingCapacity(); - if (s.framed) { - s.framed = false; - if (now >= flood_at and (s.flood_end == 0 or now <= s.flood_end)) try s.totals.frame_ns.append(gpa, ps.screens.encode_ns - s.encode_ns); - } } /// The units the session queued for client `cl` since, their heads @@ -1610,14 +1560,6 @@ const Soak = struct { if (flooding) s.totals.flood_unit_bytes += f.payload.len; try net.toClient(c, now, .to_replica, cl.gen, try gpa.dupe(u8, f.payload)); }, - .screen => { - if (f.payload[5] == 1) { - s.totals.deltas += 1; - s.totals.delta_bytes += f.payload.len; - if (flooding) s.totals.flood_delta_bytes += f.payload.len; - } else s.totals.filled_bytes += f.payload.len; - try net.toClient(c, now, .screen_down, cl.gen, try gpa.dupe(u8, f.payload)); - }, .check => { const d = try gpa.alloc(u8, 8); std.mem.writeInt(u64, d[0..8], (try pardes.wire.decodeServer(f.tag, f.payload)).check, .little); @@ -1644,20 +1586,6 @@ const Soak = struct { try s.net.toClient(c, s.now, .gone, cl.gen, &.{}); } - /// Each terminal at its version as the session's screen shows it now - /// (after a flush: `Peers.flushed`). - fn flushed(ctx: *anyopaque, core: *pardes.Pardes, screens: *replica.Screens) void { - const s: *Soak = @ptrCast(@alignCast(ctx)); - for (&screens.tracks, 0..) |*slot, id| if (slot.*) |*tr| { - const key = @as(u64, tr.serial) << 32 | trackOf(tr.track).version; - if (trackOf(tr.track).version == 0 or s.versions.contains(key)) continue; - _ = core.panes[id] orelse continue; - s.versions.put(gpa, key, screenHash(&pardes.Term.emulatorOf(tr.state).vt)) catch |err| { - s.err = err; - }; - }; - } - pub fn upgradeAsked(_: *Soak) void {} pub fn restoring(_: *Soak, _: *pardes.Pardes) void {} pub fn restored(_: *Soak, _: *SessionLoop) void {} @@ -1672,8 +1600,8 @@ const Soak = struct { fn wait(s: *Soak, timeout_ms: u32) !bool { const core = s.l.core; const net = s.net; - // An input of its own held while a pty's output was taken: the step - // after reads the terminal as the clients' deltas bring it. + // An input of its own held while a pty's output was taken: its step + // comes after that output's. if (s.held) |m| { s.held = null; try s.own(m); @@ -1713,7 +1641,7 @@ const Soak = struct { // tape is stepped in it between its steps (tape.enter's check), // and no rollback epoch's trees are held. const in_client = switch (m.kind) { - .refused, .dump, .input, .to_replica, .screen_down, .checked, .blob, .wake, .quit, .gone, .word => true, + .refused, .dump, .input, .to_replica, .checked, .blob, .wake, .quit, .gone, .word => true, .draw => Draws.jobs.items.len > 0 and Draws.jobs.items[0].draw != null and Draws.jobs.items[0].draw != @as(?*const pardes.Pardes, core), else => false, }; @@ -1777,11 +1705,7 @@ const Soak = struct { const busy = s.typing > 0 or s.flood_end == 0; s.frames_left = if (busy) 120 else s.frames_left -| 1; if (s.frames_left > 0) try net.send(.{ .at = m.at + frame_us, .n = 0, .kind = .frame, .who = 0, .bytes = &.{} }); - if (took_output or core.needs_frame or (core.nextWake() orelse std.math.maxInt(u64)) <= s.now_ns) { - s.framed = true; - s.encode_ns = s.l.peers.screens.encode_ns; - return false; - } + if (took_output or core.needs_frame or (core.nextWake() orelse std.math.maxInt(u64)) <= s.now_ns) return false; }, // Room in the far link: its Peer's writer goes on. .drain => { @@ -1812,8 +1736,6 @@ const Soak = struct { if (m.gen != cl.gen or cl.read_done or cl.shut) continue; const f = (try pardes.wire.framed(m.bytes)) orelse return error.BadFrame; if (ending and f.tag == @backingInt(pardes.wire.ClientTag.check)) continue; - if (f.tag == @backingInt(pardes.wire.ClientTag.screen_ack) and f.payload.len >= 22 and f.payload[5] == 2) - s.totals.fetched += std.mem.readInt(u64, f.payload[14..22], .little) - std.mem.readInt(u64, f.payload[6..14], .little); if (!peer.take(f.tag, f.payload)) { cl.read_done = true; s.l.peers.post(.{ .gone = peer }); @@ -1884,7 +1806,7 @@ const Soak = struct { } }, .dump => try s.joined(cl, c, m), - .input, .to_replica, .screen_down, .checked, .blob, .wake, .quit, .gone, .word => { + .input, .to_replica, .checked, .blob, .wake, .quit, .gone, .word => { if (m.kind == .input and cl.left == 0) continue; const rp = cl.r orelse if (m.kind == .input and cl.dialling) { try net.send(.{ .at = m.at + 50_000, .n = 0, .kind = .input, .who = m.who, .bytes = &.{} }); @@ -1931,26 +1853,6 @@ const Soak = struct { }, .word => cl.loop.take(.{ .refused = try std.heap.c_allocator.dupe(u8, m.bytes) }), .blob => cl.loop.take(.{ .blob = try std.heap.c_allocator.dupe(u8, m.bytes) }), - .screen_down => { - const pane = m.bytes[0]; - const was = if (rp.screens[pane]) |sc| replicaOf(sc.rep).seq else 0; - cl.loop.take(.{ .screen = try std.heap.c_allocator.dupe(u8, m.bytes) }); - if (m.bytes[5] == 1) if (rp.screens[pane]) |sc| { - const now_seq = replicaOf(sc.rep).seq; - if (now_seq == was) s.totals.resets += 1 else { - // Applied: the screen is the session's at that version. - s.totals.screens_checked += 1; - const want = s.versions.get(@as(u64, sc.serial) << 32 | now_seq); - const vt = &pardes.Term.emulatorOf(rp.core().panes[pane].?.terminal.?).vt; - if (want == null or want.? != screenHash(vt)) { - s.totals.screens_wrong += 1; - std.debug.print("seed {d} rtt {d} ms: client {d}'s terminal {d} at version {d} is not the session's\n", .{ s.r.seed, s.r.rtt_ms, m.who, pane, now_seq }); - } - // Deltas while the flood runs (an RTT/2 behind it). - if (m.at >= flood_at + net.one_way and (s.flood_end == 0 or m.at <= s.flood_end + net.one_way)) s.flood_deltas[c] += 1; - } - }; - }, .checked => cl.loop.take(.{ .checked = std.mem.readInt(u64, m.bytes[0..8], .little) }), .wake => { // One the next replaced is no wake. @@ -1967,7 +1869,7 @@ const Soak = struct { try woke(cl, c, net, m.at, s.totals, s.r); if (cl.loop.link.quit) try ended(cl, c, net, m.at, s.totals, s.r, &s.typing); }, - .to_authority, .screen_up, .client_frame, .check_up, .bye_up => unreachable, + .to_authority, .client_frame, .check_up, .bye_up => unreachable, } } } @@ -2049,10 +1951,8 @@ const Soak = struct { } } // Its terminals its own emulators, fed what the units carry. - if (bytes_kind) { - rp.t.screen_state = false; - rp.core().echo = null; - } + rp.t.screen_state = false; + rp.core().echo = null; rp.stats.samples = true; rp.t.local_files = true; rp.echo.now = m.at * 1000; @@ -2089,21 +1989,20 @@ const Soak = struct { const totals = s.totals; const core = s.l.core; totals.flood_us += s.flood_end -| flood_at; - for (s.flood_deltas[0..s.clients.len]) |d| totals.flood_deltas += d; const want = pardes.tape.digestOf(core); totals.cut += s.l.peers.cut; - if (bytes_kind) std.debug.print("seed {d} rtt {d} ms: a join's step at worst {d} us (the session's reloads and its dump), the last dump {d} KB ({d} KB of state)\n", .{ s.r.seed, s.r.rtt_ms, s.join_worst / 1000, s.l.peers.dump_bytes >> 10, s.l.peers.state_bytes >> 10 }); + std.debug.print("seed {d} rtt {d} ms: a join's step at worst {d} us (the session's reloads and its dump), the last dump {d} KB ({d} KB of state)\n", .{ s.r.seed, s.r.rtt_ms, s.join_worst / 1000, s.l.peers.dump_bytes >> 10, s.l.peers.state_bytes >> 10 }); if (s.net.throttled) |c| if (!s.far_final) std.debug.print("seed {d} rtt {d} ms: the far client never showed the screen after the flood ({s})\n", .{ s.r.seed, s.r.rtt_ms, if (s.clients[c].r == null) "it left" else "it is joined" }); - if (bytes_kind) for (kitty_oks, s.kitty_answers) |ok, n| if (n != 1) { + for (kitty_oks, s.kitty_answers) |ok, n| if (n != 1) { totals.unequal += 1; std.debug.print("seed {d} rtt {d} ms: the program's kitty {f} was answered {d} times on the session's pty\n", .{ s.r.seed, s.r.rtt_ms, std.ascii.hexEscape(ok, .lower), n }); }; - if (bytes_kind) for (&s.media.temp, &s.media.object) |*temp, *object| { + for (&s.media.temp, &s.media.object) |*temp, *object| { for ([_][:0]const u8{ temp, object }, [_]bool{ libc.access(temp, libc.F_OK) == 0, shm.shm_open(object, @bitCast(libc.O{ .ACCMODE = .RDONLY }), 0) >= 0 }) |name, left| if (left) { totals.unequal += 1; std.debug.print("seed {d} rtt {d} ms: {s}, an image's medium, is still there\n", .{ s.r.seed, s.r.rtt_ms, name }); }; - }; + } for (s.clients, 1..) |*cl, id| { totals.resizes += cl.resizes; totals.wakes += cl.wakes; @@ -2231,17 +2130,17 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void { defer gpa.free(tui); const session_only = try screen_state.shellStream(gpa); defer gpa.free(session_only); - const shell_session = try std.mem.concat(gpa, u8, &.{ session_only, if (bytes_kind) questions else "" }); + const shell_session = try std.mem.concat(gpa, u8, &.{ session_only, questions }); defer gpa.free(shell_session); var media: Media = undefined; - const shown = if (bytes_kind) try images(dir, r.seed, &media) else ""; - defer if (bytes_kind) { + const shown = try images(dir, r.seed, &media); + defer { gpa.free(shown); for (&media.temp, &media.object) |*temp, *object| { _ = libc.unlink(temp); _ = shm.shm_unlink(object); } - }; + } const yes_only = try screen_state.yesStream(gpa, @intCast(r.flood_mb * (1 << 20) / 3)); defer gpa.free(yes_only); const yes = try std.mem.concat(gpa, u8, &.{ yes_only, shown }); @@ -2426,11 +2325,11 @@ fn diffCase(dir: []const u8) !bool { const look = try std.fmt.bufPrint(&lbuf, "Look {s}", .{patch}); var ok = true; for ([_]bool{ false, true }) |own| { - const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, host.host(), true); + const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, host.host(), false); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const rp = try replica.Replica.init(gpa, 1, first, true); + const rp = try replica.Replica.init(gpa, 1, first, false); defer rp.deinit(); if (own) { const msg = try gpa.dupe(u8, try rp.input(.{ .command = look })); @@ -2491,11 +2390,11 @@ fn plumbCase(dir: []const u8) !bool { const open = try std.fmt.bufPrint(&obuf, "Look {s}", .{notes}); var ok = true; for ([_][]const u8{ "Look https://ziglang.org", "Look 3f2a9c1" }) |look| for ([_]bool{ false, true }) |own| { - const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, host.host(), true); + const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, host.host(), false); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const rp = try replica.Replica.init(gpa, 1, first, true); + const rp = try replica.Replica.init(gpa, 1, first, false); defer rp.deinit(); rp.confirm(try a.local(.{ .command = open })); rp.settle(); @@ -2543,11 +2442,11 @@ fn plumbCase(dir: []const u8) !bool { // The rule from the session's plumbing file, read at boot. var pbuf: [256]u8 = undefined; try writeText(try std.fmt.bufPrintSentinel(&pbuf, "{s}/plumbing", .{dir}, 0), "type is text\ndata matches 'https://letters/.*'\nplumb to seemail\n\ninclude basic\n"); - const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty, .config_dir = dir }, host.host(), true); + const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty, .config_dir = dir }, host.host(), false); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const rp = try replica.Replica.init(gpa, 1, first, true); + const rp = try replica.Replica.init(gpa, 1, first, false); defer rp.deinit(); rp.confirm(try a.local(.{ .command = open })); rp.settle(); @@ -2590,48 +2489,8 @@ fn push(q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, m: Msg) !void { try q.push(gpa, mm); } -/// What each peer is owed of the terminals, onto its link (before the -/// authority steps an input, and once a frame); each version as the -/// authority's screen showed it. -fn flushAll(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(); - // Terminals alone cross: the view is not read. - 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 | trackOf(tr.track).version; - if (trackOf(tr.track).version == 0 or vs.contains(key)) continue; - _ = core.panes[id] orelse continue; - try vs.put(gpa, key, screenHash(&pardes.Term.emulatorOf(tr.state).vt)); - }; -} - -/// A unit of the authority's to every replica, down its link: first the -/// rows of its terminals its step read that a replica holds as holes. -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, screens: *replica.Screens, core: *pardes.Pardes, peers: []const u16) !void { - var rows: std.ArrayListUnmanaged([]u8) = .empty; - defer rows.deinit(gpa); - for (down, peers, 1..) |*l, peer, who| { - rows.clearRetainingCapacity(); - try screens.fill(core, peer, &rows); - for (rows.items) |bytes| { - totals.filled_bytes += bytes.len; - try q.push(gpa, .{ .at = l.arrive(random, now, one_way, jitter), .n = n.*, .kind = .screen_down, .who = @intCast(who), .bytes = bytes }); - n.* += 1; - } - } - screens.filled(core); - // The sizes its steps gave terminals, after their rows (Peers.unit). - pardes.panes.resizeDeferred(core); - totals.unit_bytes += unit.len * down.len; - if (flooding) totals.flood_unit_bytes += unit.len * down.len; +/// 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) !void { 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; @@ -2647,8 +2506,8 @@ fn sendUnit(q: *std.PriorityQueue(Msg, void, Msg.order), n: *u64, unit: []const // plain echo, no marks). Each key's echo comes back 2 ms after the authority // writes it, as a shell's. The client types at a typist's pace and in bursts; // each of its frames (60 Hz, a phase of its own) is what its screen shows: -// the predicted echo where it is drawn (core/term/echo.zig), the screen state -// under it. Per key the shell echoed at a prompt or in cat: the time from +// the predicted echo where it is drawn (core/term/echo.zig), its own +// emulator under it, fed the units' bytes. Per key the shell echoed at a prompt or in cat: the time from // the key to its character on that screen, with prediction and without. Per // key predicted: whether the authority's screen, right after its echo, // shows what was predicted where it was. Per key drawn wrong: its frames. @@ -2961,10 +2820,10 @@ const Typed = struct { pred: ?struct { x: u16, y: u16, cp: u21 } = null, pcur: ?struct { x: u16, y: u16 } = null, /// The shell's mode as it took the key; whether it printed anything for - /// it; the authority's version of the screen before that. + /// it; the authority's last unit before that (its echo is in a later one). mode: ?FakeShell.Mode = null, echoed: bool = false, - version_before: u32 = 0, + unit_before: u32 = 0, /// The authority's screen right after its echo: its cursor and the /// cursor's row; whether that is what was predicted. after: ?struct { x: u16, y: u16, row: [128]u21 } = null, @@ -2972,7 +2831,7 @@ const Typed = struct { /// Its prediction drawn: first, and in how many frames. first_visible: ?u64 = null, visible_frames: u32 = 0, - /// The screen state showing its echo, first. + /// The client's emulator showing its echo, first. seen: ?u64 = null, }; @@ -2994,7 +2853,6 @@ const EchoTotals = struct { alt_predicted: u64 = 0, divergences: u64 = 0, unequal: u64 = 0, - screens_wrong: u64 = 0, /// The replica's frame drawn while it shows a prediction (its core's /// render, the tty's and the GUI's), and the overlay's part of it (ns); /// cells drawn otherwise than predicted. @@ -3043,14 +2901,11 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { } var sh: FakeShell = .{}; defer sh.out.deinit(gpa); - const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty_shell }, host.host(), true); + const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty_shell }, host.host(), false); defer a.deinit(); - var screens: replica.Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const peers = [_]u16{peer}; - const rp = try replica.Replica.init(gpa, 1, try a.unit(0, 0), true); + const rp = try replica.Replica.init(gpa, 1, try a.unit(0, 0), false); defer rp.deinit(); + rp.core().echo = &rp.echo; rp.echo.on = on; const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); @@ -3065,11 +2920,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { t.spec_ns.deinit(gpa); t.copy_ns.deinit(gpa); t.rollback_ns.deinit(gpa); - t.apply_ns.deinit(gpa); - t.frame_ns.deinit(gpa); } - var versions: std.AutoHashMapUnmanaged(u64, u64) = .empty; - defer versions.deinit(gpa); var queue: std.PriorityQueue(Msg, void, Msg.order) = .empty; defer { while (queue.pop()) |m| if (m.bytes.len > 0) gpa.free(m.bytes); @@ -3080,8 +2931,8 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { const jitter = one_way / 10; var up: [1]Link = @splat(.{}); var down: [1]Link = @splat(.{}); - var owed: std.ArrayListUnmanaged([]u8) = .empty; - defer owed.deinit(gpa); + // The last of the authority's own units the replica fed its emulator. + var fed: u32 = 0; // The shell's first prompt. sh.put(prompt_bytes); @@ -3131,12 +2982,11 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { if (next_step < corpus.steps.items.len) try push(&queue, &n, .{ .at = m.at + corpus.steps.items[next_step].gap, .n = 0, .kind = .input, .who = 1, .bytes = &.{} }); }, .to_authority => { - if (try a.pending()) |batch| try sendUnit(&queue, &n, batch, m.at, &down, random, one_way, jitter, &t, false, &screens, a.core, &peers); - try flushAll(&screens, a.core, &peers, &owed, &queue, &n, m.at, &down, random, one_way, jitter, &versions, &t); + if (try a.pending()) |batch| try sendUnit(&queue, &n, batch, m.at, &down, random, one_way, jitter); host.current = (replica.parseInput(m.bytes) orelse return error.BadInput).seq; const unit = try a.take(m.bytes); host.current = 0; - try sendUnit(&queue, &n, unit, m.at, &down, random, one_way, jitter, &t, false, &screens, a.core, &peers); + try sendUnit(&queue, &n, unit, m.at, &down, random, one_way, jitter); for (host.writes.items) |w| try push(&queue, &n, .{ .at = m.at + 2_000, .n = 0, .kind = .echo, .who = shell, .bytes = w.bytes, .seq = w.seq }); host.writes.clearRetainingCapacity(); }, @@ -3145,7 +2995,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { const state = a.core.panes[shell].?.terminal.?; if (ty) |k| { k.mode = sh.mode; - k.version_before = if (screens.tracks[shell]) |*tr| trackOf(tr.track).version else 0; + k.unit_before = a.seq; } sh.key(m.bytes); if (sh.out.items.len > 0) { @@ -3161,8 +3011,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { } }, .frame => { - if (try a.pending()) |batch| try sendUnit(&queue, &n, batch, m.at, &down, random, one_way, jitter, &t, false, &screens, a.core, &peers); - try flushAll(&screens, a.core, &peers, &owed, &queue, &n, m.at, &down, random, one_way, jitter, &versions, &t); + if (try a.pending()) |batch| try sendUnit(&queue, &n, batch, m.at, &down, random, one_way, jitter); const busy = next_step < corpus.steps.items.len or queue.count() + 1 > periodic; left[0] = if (busy) 60 else left[0] -| 1; if (left[0] > 0) try push(&queue, &n, .{ .at = m.at + frame_us, .n = 0, .kind = .frame, .who = 0, .bytes = &.{} }) else periodic -= 1; @@ -3200,8 +3049,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { } } }; - const applied = if (rp.screens[shell]) |sc| replicaOf(sc.rep).seq else 0; - for (typed.items) |*k| if (k.echoed and k.seen == null and applied > k.version_before) { + for (typed.items) |*k| if (k.echoed and k.seen == null and fed > k.unit_before) { k.seen = m.at; }; const busy = next_step < corpus.steps.items.len or queue.count() + 1 > periodic; @@ -3211,22 +3059,9 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { .to_replica => { rp.confirm(m.bytes); rp.settle(); - }, - .screen_down => { - if (rp.screen(m.bytes)) |reply| { - const pane = m.bytes[0]; - if (reply[5] == 1) { - const sc = rp.screens[pane].?; - if (versions.get(@as(u64, sc.serial) << 32 | replicaOf(sc.rep).seq)) |want| { - if (want != screenHash(&pardes.Term.emulatorOf(rp.core().panes[pane].?.terminal.?).vt)) t.screens_wrong += 1; - } else t.screens_wrong += 1; - } - try push(&queue, &n, .{ .at = up[0].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .screen_up, .who = 1, .bytes = try gpa.dupe(u8, reply) }); - } - if (rp.screenRequest()) |req| try push(&queue, &n, .{ .at = up[0].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .screen_up, .who = 1, .bytes = try gpa.dupe(u8, req) }); - }, - .screen_up => { - if (try screens.take(a.core, peer, m.bytes)) |answer| try push(&queue, &n, .{ .at = down[0].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .screen_down, .who = 1, .bytes = answer }); + if (replica.parseUnit(m.bytes)) |u| if (u.origin == 0) { + fed = u.seq; + }; }, .output, .own, .dial, .dump, .refused, .check_up, .checked, .bye_up, .wake, .quit, .gone, .draw, .up, .blob, .word, .drain => {}, } @@ -3237,7 +3072,6 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void { et.confirmed += s.confirmed; et.mispredicted += s.mispredicted; et.cursor_missed += s.cursor_missed; - et.screens_wrong += t.screens_wrong; for (typed.items) |k| { et.keys += 1; const sec = &et.sec[k.section]; @@ -3288,7 +3122,7 @@ fn echoMain(seeds: u64, first: u64, rtts: []const u64) !bool { var draw_lines: std.ArrayList(u8) = .empty; defer draw_lines.deinit(gpa); std.debug.print("predicted echo: one client typing the corpus into a shell, {d} seeds a cell; from a key to its character on the client's screen (ms, frames at 60 Hz)\n", .{seeds}); - std.debug.print(" rtt echo keys echoed p50 p90 max predicted unpredicted right/wrong confirmed mispredicted cursor-missed drawn-wrong keys/frames/max secret-frames vim-predicted diverged unequal screens-wrong\n", .{}); + std.debug.print(" rtt echo keys echoed p50 p90 max predicted unpredicted right/wrong confirmed mispredicted cursor-missed drawn-wrong keys/frames/max secret-frames vim-predicted diverged unequal\n", .{}); var by_section: std.ArrayList(u8) = .empty; defer by_section.deinit(gpa); var off: [sections.len][2]u64 = undefined; @@ -3301,13 +3135,13 @@ fn echoMain(seeds: u64, first: u64, rtts: []const u64) !bool { return @as(f64, @floatFromInt(us)) / 1000; } }.f; - std.debug.print("{d:>4} {s:>4} {d:>4} {d:>6} {d:>5.1} {d:>5.1} {d:>5.1} {d:>9} {d:>11} {d:>5}/{d:<5} {d:>9} {d:>12} {d:>13} {d:>5}/{d:>5}/{d:<5} {d:>13} {d:>13} {d:>8} {d:>7} {d:>13}\n", .{ + std.debug.print("{d:>4} {s:>4} {d:>4} {d:>6} {d:>5.1} {d:>5.1} {d:>5.1} {d:>9} {d:>11} {d:>5}/{d:<5} {d:>9} {d:>12} {d:>13} {d:>5}/{d:>5}/{d:<5} {d:>13} {d:>13} {d:>8} {d:>7}\n", .{ rtt, if (on) "on" else "off", et.keys, et.echo_keys, ms(pct(et.latency.items, 50)), ms(pct(et.latency.items, 90)), ms(pct(et.latency.items, 100)), et.predicted, et.unpredicted, et.right, et.wrong, et.confirmed, et.mispredicted, et.cursor_missed, et.wrong_shown, et.wrong_frames, et.wrong_max, et.secret_frames, et.alt_predicted, et.divergences, - et.unequal, et.screens_wrong, + et.unequal, }); for (&et.sec, &off, sections) |*x, *o, name| { const p50 = pct(x.latency.items, 50) / 1000; @@ -3319,7 +3153,7 @@ fn echoMain(seeds: u64, first: u64, rtts: []const u64) !bool { try by_section.print(gpa, "{d:>4} {s:<14} {d:>5} {d:>9} {d:>7} {d:>4} -> {d:<4} {d:>4} -> {d:<4} {d:>12}\n", .{ rtt, name, x.keys, x.predicted, x.latency.items.len, o[0], p50, o[1], p90, x.wrong_frames }); } if (on) try draw_lines.print(gpa, "{d:>4} {d:>12} {d:>6}/{d:<6} {d:>5}/{d:<5} {d:>10}\n", .{ rtt, et.drawn_frames, pct(et.render_ns.items, 50) / 1000, pct(et.render_ns.items, 99) / 1000, pct(et.paint_ns.items, 50), pct(et.paint_ns.items, 99), et.paint_wrong }); - if (et.divergences > 0 or et.unequal > 0 or et.screens_wrong > 0 or et.secret_frames > 0 or et.alt_predicted > 0 or et.paint_wrong > 0) failed = true; + if (et.divergences > 0 or et.unequal > 0 or et.secret_frames > 0 or et.alt_predicted > 0 or et.paint_wrong > 0) failed = true; }; std.debug.print("by part of the corpus (all seeds): keys typed, predicted, echoed (the latency sample); key to its character on the screen, ms, without -> with; frames a wrong prediction was drawn\n rtt part keys predicted echoed p50 off/on p90 off/on drawn-wrong\n{s}", .{by_section.items}); std.debug.print("the client's frames drawn with a prediction shown: its render (us) and the overlay's part (ns); cells drawn otherwise than predicted\n rtt frames-drawn render p50/p99 paint p50/p99 drawn-wrong\n{s}", .{draw_lines.items}); @@ -3341,174 +3175,6 @@ fn pct(samples: []u64, p: usize) u64 { return samples[@min(samples.len - 1, samples.len * p / 100)]; } -/// `--screen-state `: every recorded pty stream in `dir` (a -/// `-x` in its name sizes it, 80x24 otherwise) through -/// screen_state's soak at three seeds, then the encode's cost and the bytes -/// floods put on the wire (numbers from a ReleaseFast build). -fn screenState(io: std.Io, dir_path: []const u8, w: *std.Io.Writer) !void { - var dir = try std.Io.Dir.cwd().openDir(io, dir_path, .{ .iterate = true }); - defer dir.close(io); - var it = dir.iterate(); - var files: usize = 0; - var failed: usize = 0; - while (try it.next(io)) |entry| { - if (entry.kind != .file) continue; - const bytes = try dir.readFileAlloc(io, entry.name, gpa, .unlimited); - defer gpa.free(bytes); - var cols: u16 = 80; - var rows: u16 = 24; - if (std.mem.lastIndexOfScalar(u8, entry.name, '-')) |dash| { - const size = std.mem.sliceTo(entry.name[dash + 1 ..], '.'); - if (std.mem.indexOfScalar(u8, size, 'x')) |x| { - cols = std.fmt.parseInt(u16, size[0..x], 10) catch cols; - rows = std.fmt.parseInt(u16, size[x + 1 ..], 10) catch rows; - } - } - files += 1; - for (0..3) |seed| { - const st = screen_state.soak(gpa, io, bytes, cols, rows, 128 * 1024, seed, seed != 0) catch |err| { - try w.print("screen-state {s} seed {d}: {s}\n", .{ entry.name, seed, @errorName(err) }); - failed += 1; - continue; - }; - if (seed == 0) try w.print("screen-state {s} {d}x{d}: {d} bytes, {d} deltas ({d} lost, {d} refused, {d} in flight at most), {d} wire bytes, {d} history rows checked, {d} fetched\n", .{ entry.name, cols, rows, bytes.len, st.deltas, st.lost, st.refused, st.most_in_flight, st.bytes, st.history_checked, st.fetched }); - } - } - try w.print("screen-state corpus: {d} streams x 3 seeds, {d} failed\n", .{ files, failed }); - try w.flush(); - try encodeBench(io, w); -} - -fn encodeBench(io: std.Io, w: *std.Io.Writer) !void { - const t = try gpa.create(screen_state.Terminal); - defer gpa.destroy(t); - t.* = try screen_state.Terminal.init(io, gpa, .{ .cols = 200, .rows = 60, .max_scrollback_bytes = 16 << 20 }); - defer t.deinit(gpa); - var stream = t.vtStream(); - defer stream.deinit(); - var enc: screen_state.Encoder = .init(gpa); - defer enc.deinit(); - var out: std.Io.Writer.Allocating = .init(gpa); - defer out.deinit(); - var line: [1024]u8 = undefined; - // A full 200x60 screen, every row new to the peer: each a blob. - var full: [200]u64 = undefined; - var same: [200]u64 = undefined; - var full_bytes: usize = 0; - var same_bytes: usize = 0; - var changes: u32 = 0; - for (&full, &same, 0..) |*f, *u, rep| { - for (0..60) |y| { - var lw: std.Io.Writer = .fixed(&line); - try lw.print("\x1b[{d};1H\x1b[0;3{d};4{d}m{d} {d} ", .{ y + 1, rep % 8, y % 8, rep, y }); - while (lw.end < 190) try lw.writeAll("\x1b[1mbold\x1b[22m text "); - stream.nextSlice(lw.buffered()); - } - changes += 1; - var tr: screen_state.Track = .init(gpa); - defer tr.deinit(gpa, t); - var peer: screen_state.Peer = .{}; - defer peer.deinit(gpa); - out.clearRetainingCapacity(); - var t0 = std.Io.Clock.awake.now(io).nanoseconds; - _ = try screen_state.encode(&enc, &tr, &peer, t, changes, "", &out.writer); - f.* = @intCast(std.Io.Clock.awake.now(io).nanoseconds - t0); - full_bytes = out.written().len; - // The same screen again as a new version: every row held. - out.clearRetainingCapacity(); - t0 = std.Io.Clock.awake.now(io).nanoseconds; - _ = try screen_state.encode(&enc, &tr, &peer, t, changes + 1, "", &out.writer); - u.* = @intCast(std.Io.Clock.awake.now(io).nanoseconds - t0); - same_bytes = out.written().len; - } - std.mem.sort(u64, &full, {}, std.sort.asc(u64)); - std.mem.sort(u64, &same, {}, std.sort.asc(u64)); - try w.print("screen-state encode 200x60, every row new: p50 {d} us p99 {d} us, {d} bytes\n", .{ full[100] / 1000, full[198] / 1000, full_bytes }); - try w.print("screen-state encode 200x60, nothing new: p50 {d} us p99 {d} us, {d} bytes\n", .{ same[100] / 1000, same[198] / 1000, same_bytes }); - try w.flush(); - - // Floods: a second of output as fast as ghostty takes it, a frame every - // 16 ms: one version, a delta for each peer (the same bytes for peers - // at the same base), each replica applying its own at once. Under the C - // allocator, as a replica's. - try floods(io, w); -} - -fn floods(io: std.Io, w: *std.Io.Writer) !void { - var enc: screen_state.Encoder = .init(gpa); - defer enc.deinit(); - var out: std.Io.Writer.Allocating = .init(gpa); - defer out.deinit(); - const yes = try screen_state.yesStream(gpa, 1 << 16); - defer gpa.free(yes); - const shell = try screen_state.shellStream(gpa); - defer gpa.free(shell); - for ([_]struct { name: []const u8, bytes: []const u8 }{ .{ .name = "yes", .bytes = yes }, .{ .name = "varied text", .bytes = shell } }) |flood| for ([_]usize{ 1, 3 }) |npeers| { - const a = try gpa.create(screen_state.Terminal); - defer gpa.destroy(a); - a.* = try screen_state.Terminal.init(io, gpa, .{ .cols = 200, .rows = 60, .max_scrollback_bytes = 16 << 20 }); - defer a.deinit(gpa); - var as = a.vtStream(); - defer as.deinit(); - var tr: screen_state.Track = .init(gpa); - defer tr.deinit(gpa, a); - var peers: [3]screen_state.Peer = @splat(.{}); - var reps: [3]screen_state.Replica = @splat(.{}); - var bs: [3]screen_state.Terminal = undefined; - for (bs[0..npeers]) |*b| b.* = try screen_state.Terminal.init(io, gpa, .{ .cols = 2, .rows = 2, .max_scrollback_bytes = 32 << 20 }); - defer for (bs[0..npeers], reps[0..npeers], peers[0..npeers]) |*b, *r, *peer| { - b.deinit(gpa); - r.deinit(gpa); - peer.deinit(gpa); - }; - var applies: std.ArrayList(u64) = .empty; - defer applies.deinit(gpa); - var frames: std.ArrayList(u64) = .empty; - defer frames.deinit(gpa); - const start = std.Io.Clock.awake.now(io).nanoseconds; - var next = start; - var fed: u64 = 0; - var deltas: u64 = 0; - var wire: u64 = 0; - var version: u32 = 0; - while (true) { - const now = std.Io.Clock.awake.now(io).nanoseconds; - if (now - start >= std.time.ns_per_s) break; - as.nextSlice(flood.bytes); - version += 1; - fed += flood.bytes.len; - if (now < next) continue; - next += 16 * std.time.ns_per_ms; - var frame_ns: u64 = 0; - for (peers[0..npeers], reps[0..npeers], bs[0..npeers]) |*peer, *rep, *b| { - out.clearRetainingCapacity(); - const e0 = std.Io.Clock.awake.now(io).nanoseconds; - if (!try screen_state.encode(&enc, &tr, peer, a, version, "", &out.writer)) continue; - frame_ns += @intCast(std.Io.Clock.awake.now(io).nanoseconds - e0); - const a0 = std.Io.Clock.awake.now(io).nanoseconds; - peer.ack((try rep.apply(gpa, io, b, out.written())).seq); - try applies.append(gpa, @intCast(std.Io.Clock.awake.now(io).nanoseconds - a0)); - deltas += 1; - wire += out.written().len; - } - try frames.append(gpa, frame_ns); - } - std.mem.sort(u64, applies.items, {}, std.sort.asc(u64)); - std.mem.sort(u64, frames.items, {}, std.sort.asc(u64)); - const p = struct { - fn at(s: []const u64, q: usize) u64 { - return if (s.len == 0) 0 else s[@min(s.len - 1, s.len * q / 100)] / 1000; - } - }.at; - try w.print("screen-state flood of {s}, {d} peer(s): {d} MB/s of output, {d} deltas/s a peer, {d} wire bytes/s a peer ({d} a delta); encode a frame, all peers: p50 {d} us p99 {d} us; apply a delta p50 {d} us p99 {d} us\n", .{ - flood.name, npeers, fed / 1_000_000, deltas / npeers, wire / npeers, - wire / @max(1, deltas), p(frames.items, 50), p(frames.items, 99), p(applies.items, 50), - p(applies.items, 99), - }); - }; - try w.flush(); -} - pub fn main(init: std.process.Init) !void { const args = try init.minimal.args.toSlice(init.arena.allocator()); // A loop that does not end names itself (`Watchdog`): its gdb, a child, @@ -3522,7 +3188,6 @@ pub fn main(init: std.process.Init) !void { var rtts: []const u64 = &.{ 30, 80, 207 }; var echo_mode = false; var flood_mb: u64 = 8; - var screen_dir: ?[]const u8 = null; var rtt_buf: [8]u64 = undefined; var addons: std.ArrayListUnmanaged([]const u8) = .empty; defer addons.deinit(gpa); @@ -3533,10 +3198,6 @@ pub fn main(init: std.process.Init) !void { echo_mode = true; continue; } - if (std.mem.eql(u8, name, "--bytes")) { - bytes_kind = true; - continue; - } if (std.mem.eql(u8, name, "--witness")) { witness_always = true; continue; @@ -3544,7 +3205,7 @@ pub fn main(init: std.process.Init) !void { 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, "--screen-state")) screen_dir = value else if (std.mem.eql(u8, name, "--addon")) try addons.append(gpa, value) else if (std.mem.eql(u8, name, "--pdf")) { + 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, "--addon")) try addons.append(gpa, value) else if (std.mem.eql(u8, name, "--pdf")) { var whole: [libc.PATH_MAX]u8 = undefined; pdf_path = try init.arena.allocator().dupe(u8, std.mem.span(libc.realpath(try init.arena.allocator().dupeSentinel(u8, value, 0), &whole) orelse return error.NoPdf)); } else if (std.mem.eql(u8, name, "--rtt")) { @@ -3554,11 +3215,6 @@ pub fn main(init: std.process.Init) !void { rtts = rtt_buf[0..k]; } else return error.UnknownOption; } - if (screen_dir) |d| { - var buf: [4096]u8 = undefined; - var out = std.Io.File.stderr().writer(init.io, &buf); - return screenState(init.io, d, &out.interface); - } trace = libc.getenv("PARDES_REPLICA_TRACE") != null; if (libc.getenv("PARDES_REPLICA_FILL")) |b| pardes.rollback.Epoch.fill = std.fmt.parseInt(u8, std.mem.span(b), 0) catch 0xff; var dir_buf: [256]u8 = undefined; @@ -3610,7 +3266,7 @@ pub fn main(init: std.process.Init) !void { var t: Totals = .{}; pardes.Term.reloads = .{}; for (first..first + seeds) |seed| try run(init, .{ .seed = seed, .rtt_ms = rtt, .steps = steps, .clients = clients, .flood_mb = flood_mb }, dir, &t); - if (bytes_kind) std.debug.print("rtt {d}: {d} reloads of a terminal at joins, every side (the session's own too), {d} us each, {d} us at worst; {d} kitty images in clients at quiescence, each the session's pixels\n", .{ rtt, pardes.Term.reloads.n, pardes.Term.reloads.ns / @max(1, pardes.Term.reloads.n) / 1000, pardes.Term.reloads.worst_ns / 1000, t.images_equal }); + std.debug.print("rtt {d}: {d} reloads of a terminal at joins, every side (the session's own too), {d} us each, {d} us at worst; {d} kitty images in clients at quiescence, each the session's pixels\n", .{ rtt, pardes.Term.reloads.n, pardes.Term.reloads.ns / @max(1, pardes.Term.reloads.n) / 1000, pardes.Term.reloads.worst_ns / 1000, t.images_equal }); const rollbacks = t.mispredicted + t.foreign; std.debug.print("{d:>4} {d:>6} {d:>7} {d:>7} {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, @@ -3623,20 +3279,10 @@ pub fn main(init: std.process.Init) !void { }); 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:>9} {d:>6} {d:>6}/{d:<6}\n", .{ + try term_lines.print(gpa, "{d:>4} {d:>9.0} {d:>9}\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.filled_bytes / 1024, - t.resets, - t.screens_checked, - t.screens_wrong, + t.unit_bytes >> 10, }); try stop_lines.print(gpa, "{d:>4} {d:>8} {d:>6} {d:>6} {d:>3}/{d}/{d} ", .{ rtt, t.unlisted, t.wakes, t.draws, t.asked[0], t.asked[1], t.asked[2] }); for (t.stops) |st| if (st.n > 0) try stop_lines.print(gpa, "{s}:{d} ", .{ st.name, st.n }); @@ -3656,10 +3302,10 @@ pub fn main(init: std.process.Init) !void { // The far client shows the final screen in every run, and the near // ones never fall behind with it. if ((t.far_final.items.len < seeds and clients >= 3) or t.near_lags > 0) failed = true; - if (t.divergences > 0 or t.unequal > 0 or t.screens_wrong > 0 or t.differ > 0 or t.unlisted > 0) failed = true; + if (t.divergences > 0 or t.unequal > 0 or t.differ > 0 or t.unlisted > 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 of the flood for every peer, apply a delta (us); rows fetched, KB of rows sent before the step that read them; resets; deltas checked/wrong\n", .{}); - std.debug.print(" rtt deltas/s delta B/s unit B/s encode p50/p99 apply p50/p99 fetched filled KB resets checked/wrong\n{s}", .{term_lines.items}); + std.debug.print("terminals: a peer's unit bytes a second under the flood (the pty's bytes ride in them); KB of units sent to the peers in all\n", .{}); + std.debug.print(" rtt unit B/s units KB\n{s}", .{term_lines.items}); std.debug.print("clients: joins from a dump, refused (every view taken), joined again after a divergence put on them, left (of them by a Detach); quiet checks of the session's digest agreed/differed; the digests the clients compared (units and quiet), of the units they took; resizes the windows posted; the kinds' panes the session opened (image/life/pdf)\n", .{}); std.debug.print(" rtt joins refused rejoined detached detach agree/differ checks/units resizes kinds\n{s}", .{join_lines.items}); std.debug.print("stops: the wakes the clients' loops asked, the frames they drew, the yanks, pastes and links their frontends did (y/p/l), and what stopped their inputs (a stop counted again as its input is applied again), by name; those at a name replica.may_wait does not list fail the run\n", .{}); @@ -3828,9 +3474,9 @@ fn corpusCase(dir: []const u8) !bool { defer own_host.shown.deinit(); var noop: Host = .{}; const options: pardes.Options = .{ .cols = 100, .rows = 22, .file = shapes }; - const a = try replica.Authority.init(gpa, options, own_host.host(), true); + const a = try replica.Authority.init(gpa, options, own_host.host(), false); defer a.deinit(); - const b = try replica.Authority.init(gpa, options, noop.host(), true); + const b = try replica.Authority.init(gpa, options, noop.host(), false); defer b.deinit(); noop.core = b.core; _ = try b.unit(0, 0); @@ -3838,6 +3484,7 @@ fn corpusCase(dir: []const u8) !bool { defer gpa.free(j.dump); const rp = try replica.Replica.initDump(gpa, 1, j.view, j.dump, .{ .cols = 100, .rows = 22 }); defer rp.deinit(); + rp.t.screen_state = false; var fds: [2]c_int = undefined; if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &fds) != 0) return error.NoSocket; defer for (fds) |fd| { -- cgit v1.3