diff options
Diffstat (limited to 'test/rollback_bench.zig')
| -rw-r--r-- | test/rollback_bench.zig | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/test/rollback_bench.zig b/test/rollback_bench.zig index 659a73d3..fa40e0cc 100644 --- a/test/rollback_bench.zig +++ b/test/rollback_bench.zig @@ -7,7 +7,9 @@ //! - a key that edits a file (`x`) applied on top, as a speculation, and //! the copy put back: the apply's time and the restore's. //! Then a fork of the big one, child gone at once, and the authority's -//! copy-on-write after it. +//! copy-on-write after it. Last, a session's authority with a 100 MB file +//! open (src/replica.zig): a key into it, a unit as a replica is sent it, +//! and a digest, its blobs hashed whole and hashed once (src/walk.zig). //! //! zig build rollback-bench -Dplatform=tui -Doptimize=ReleaseFast const std = @import("std"); @@ -122,6 +124,45 @@ fn rssKb() usize { const reps = 15; +/// The `p`th percentile of `samples`, sorted in place. +fn pct(samples: []u64, p: usize) u64 { + std.mem.sort(u64, samples, {}, std.sort.asc(u64)); + return samples[@min(samples.len - 1, samples.len * p / 100)]; +} + +/// A unit of a key into a big file, and a digest, with its blobs hashed +/// whole and hashed once. +fn digestBench(dir: []const u8, mb: usize) !void { + var path_buf: [512]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/big-file.txt", .{dir}); + try writeFile(path, (mb << 20) / 60); + const NoHost = struct { + fn watched(_: ?*anyopaque) bool { + return false; + } + const vtable: pardes.Host.VTable = .{ .watched = watched }; + }; + const a = try pardes.replica.Authority.init(gpa, .{ .cols = 120, .rows = 40, .file = path }, .{ .vtable = &NoHost.vtable }, true); + defer a.deinit(); + _ = try a.unit(0, 0); + var unit_ns: [40]u64 = undefined; + var digest_ns: [40]u64 = undefined; + for ([_]bool{ false, true }) |on| { + walk.blob_words_on = on; + defer walk.blob_words_on = true; + walk.forgetAll(); + for (&unit_ns, &digest_ns, 0..) |*u, *d, k| { + const t0 = nowNs(); + _ = try a.local(.{ .key = .{ .cp = if (k % 2 == 0) 'j' else 'k', .text = if (k % 2 == 0) "j" else "k" } }); + u.* = nowNs() - t0; + const t1 = nowNs(); + _ = pardes.replica.digestOf(a); + d.* = nowNs() - t1; + } + std.debug.print("{d} MB file, blobs {s}: a unit p50 {d} us p99 {d} us; a digest p50 {d} us p99 {d} us\n", .{ mb, if (on) "hashed once" else "hashed whole", pct(&unit_ns, 50) / 1000, pct(&unit_ns, 99) / 1000, pct(&digest_ns, 50) / 1000, pct(&digest_ns, 99) / 1000 }); + } +} + pub fn main(init: std.process.Init) !void { var dir_buf: [256]u8 = undefined; const tmp = std.mem.span(libc.getenv("TMPDIR") orelse "/tmp"); @@ -223,4 +264,5 @@ pub fn main(init: std.process.Init) !void { std.debug.print("fork of the big session (max RSS {d} MB): {d:.3} ms; then 64 MB written under the child: {d:.3} ms\n", .{ rssKb() / 1024, @as(f64, @floatFromInt(median(&t))) / 1e6, @as(f64, @floatFromInt(median(&cow))) / 1e6, }); + try digestBench(dir, 100); } |
