gitoria
All repositories: gitoria
4.0 KB
// Mission 436 bench: open/close timing and index dump of an mpackdb store.// bench_open gen <dbfile> <n> write a synthetic store (pk '@id' 24-hex, '!oldId' 24-hex), no index files// bench_open open <dbfile> time open + close (schema @id, !oldId, compact=false)// bench_open dump <dbfile> <out> open and write every index entry (field,key,off,len) to <out>const std = @import("std");const msgpack = @import("msgpack.zig");const engine = @import("engine.zig");const linux = std.os.linux;fn nowNs() i128 {var ts: linux.timespec = undefined;_ = linux.clock_gettime(linux.CLOCK.MONOTONIC, &ts);return @as(i128, ts.sec) * 1_000_000_000 + ts.nsec;}pub fn main(init: std.process.Init) !void {const gpa = init.gpa;var iter = std.process.Args.Iterator.init(init.minimal.args);_ = iter.next();const cmd = iter.next() orelse return;const dbfile = iter.next() orelse return;if (std.mem.eql(u8, cmd, "gen")) {const n = try std.fmt.parseInt(usize, iter.next().?, 10);var base: []const u8 = dbfile;if (std.mem.endsWith(u8, base, ".db")) base = base[0 .. base.len - 3];const path = try std.fmt.allocPrintSentinel(gpa, "{s}.mpack", .{base}, 0);const fd: i32 = @bitCast(@as(u32, @truncate(linux.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, 0o644))));var out: std.ArrayList(u8) = .empty;var prng = std.Random.DefaultPrng.init(42);const r = prng.random();var arena_state = std.heap.ArenaAllocator.init(gpa);var i: usize = 0;while (i < n) : (i += 1) {_ = arena_state.reset(.retain_capacity);const a = arena_state.allocator();const id = try std.fmt.allocPrint(a, "{x:0>16}", .{r.int(u64)});const old = try std.fmt.allocPrint(a, "60f2{x:0>8}{x:0>12}", .{ r.int(u32), i });const entries = try a.alloc(msgpack.Entry, 4);entries[0] = .{ .key = .{ .str = "id" }, .value = .{ .str = id } };entries[1] = .{ .key = .{ .str = "oldId" }, .value = .{ .str = old } };entries[2] = .{ .key = .{ .str = "name" }, .value = .{ .str = "Some Person Name" } };entries[3] = .{ .key = .{ .str = "n" }, .value = .{ .number = @floatFromInt(i) } };const framed = try msgpack.serialize(a, .{ .map = entries });try out.appendSlice(gpa, framed);if (out.items.len > 1 << 20) {_ = linux.write(fd, out.items.ptr, out.items.len);out.clearRetainingCapacity();}}_ = linux.write(fd, out.items.ptr, out.items.len);_ = linux.close(fd);return;}const t0 = nowNs();const db = try engine.Db.open(gpa, dbfile, .{ .primary_key = "@id", .indexes = &.{"!oldId"}, .compact = false });const t1 = nowNs();if (std.mem.eql(u8, cmd, "dump")) {const outp = try std.fmt.allocPrintSentinel(gpa, "{s}", .{iter.next().?}, 0);var buf: std.ArrayList(u8) = .empty;var it = db.idx.iterator();while (it.next()) |kv| {for (kv.value_ptr.entries.items) |e| {var kb: [40]u8 = undefined;const ks = switch (e.key) {.num => |x| engine.jsNumFmt(&kb, x),.str => |s| s,};const line = try std.fmt.allocPrint(gpa, "{s}\t{s}\t{d}\t{d}\n", .{ kv.key_ptr.*, ks, e.off, e.len });defer gpa.free(line);try buf.appendSlice(gpa, line);}}const fd: i32 = @bitCast(@as(u32, @truncate(linux.open(outp, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, 0o644))));var off: usize = 0;while (off < buf.items.len) {const rc = linux.write(fd, buf.items.ptr + off, buf.items.len - off);off += rc;}_ = linux.close(fd);}const t2 = nowNs();db.close();const t3 = nowNs();std.debug.print("open {d} ms, close {d} ms\n", .{ @divTrunc(t1 - t0, 1_000_000), @divTrunc(t3 - t2, 1_000_000) });}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- cce7b785|||PR No session for cookieless login errorsmre
- 678d6303Merge branch 'v59' into mainGitoria
- 5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre
- 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
- 26117255|||PR apps API: review comments on files with spaces in their namemre
- b8796cecMerge branch 'f1-broken-json' into mainGitoria
- 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
- f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
- 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
- 16a3530fMerge branch 'heap-revert' into mainGitoria
- 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
- 13f0c342Merge branch 'hl25-records' into mainGitoria
- a002ecb7|||PR records: HL25 report, heap helper, logmre
- 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
- fefaedd2log: tracker PR-only, HL25 startedmre
- 21aa57calog: parkmre
- e9f950a8reports: G25c soakmre
- a7783686log: deploy 9f41ffcmre
- 9f41ffc1log: W30b mergedmre
- bef635c1Merge branch 'w30b'mre