gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit4177382841773828Records: statusmre41773828/plugins/mpackdb/bench_open.zig

4.0 KB

  1. // Mission 436 bench: open/close timing and index dump of an mpackdb store.
  2. // bench_open gen <dbfile> <n> write a synthetic store (pk '@id' 24-hex, '!oldId' 24-hex), no index files
  3. // bench_open open <dbfile> time open + close (schema @id, !oldId, compact=false)
  4. // bench_open dump <dbfile> <out> open and write every index entry (field,key,off,len) to <out>
  5. const std = @import("std");
  6. const msgpack = @import("msgpack.zig");
  7. const engine = @import("engine.zig");
  8. const linux = std.os.linux;
  9. fn nowNs() i128 {
  10. var ts: linux.timespec = undefined;
  11. _ = linux.clock_gettime(linux.CLOCK.MONOTONIC, &ts);
  12. return @as(i128, ts.sec) * 1_000_000_000 + ts.nsec;
  13. }
  14. pub fn main(init: std.process.Init) !void {
  15. const gpa = init.gpa;
  16. var iter = std.process.Args.Iterator.init(init.minimal.args);
  17. _ = iter.next();
  18. const cmd = iter.next() orelse return;
  19. const dbfile = iter.next() orelse return;
  20. if (std.mem.eql(u8, cmd, "gen")) {
  21. const n = try std.fmt.parseInt(usize, iter.next().?, 10);
  22. var base: []const u8 = dbfile;
  23. if (std.mem.endsWith(u8, base, ".db")) base = base[0 .. base.len - 3];
  24. const path = try std.fmt.allocPrintSentinel(gpa, "{s}.mpack", .{base}, 0);
  25. const fd: i32 = @bitCast(@as(u32, @truncate(linux.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, 0o644))));
  26. var out: std.ArrayList(u8) = .empty;
  27. var prng = std.Random.DefaultPrng.init(42);
  28. const r = prng.random();
  29. var arena_state = std.heap.ArenaAllocator.init(gpa);
  30. var i: usize = 0;
  31. while (i < n) : (i += 1) {
  32. _ = arena_state.reset(.retain_capacity);
  33. const a = arena_state.allocator();
  34. const id = try std.fmt.allocPrint(a, "{x:0>16}", .{r.int(u64)});
  35. const old = try std.fmt.allocPrint(a, "60f2{x:0>8}{x:0>12}", .{ r.int(u32), i });
  36. const entries = try a.alloc(msgpack.Entry, 4);
  37. entries[0] = .{ .key = .{ .str = "id" }, .value = .{ .str = id } };
  38. entries[1] = .{ .key = .{ .str = "oldId" }, .value = .{ .str = old } };
  39. entries[2] = .{ .key = .{ .str = "name" }, .value = .{ .str = "Some Person Name" } };
  40. entries[3] = .{ .key = .{ .str = "n" }, .value = .{ .number = @floatFromInt(i) } };
  41. const framed = try msgpack.serialize(a, .{ .map = entries });
  42. try out.appendSlice(gpa, framed);
  43. if (out.items.len > 1 << 20) {
  44. _ = linux.write(fd, out.items.ptr, out.items.len);
  45. out.clearRetainingCapacity();
  46. }
  47. }
  48. _ = linux.write(fd, out.items.ptr, out.items.len);
  49. _ = linux.close(fd);
  50. return;
  51. }
  52. const t0 = nowNs();
  53. const db = try engine.Db.open(gpa, dbfile, .{ .primary_key = "@id", .indexes = &.{"!oldId"}, .compact = false });
  54. const t1 = nowNs();
  55. if (std.mem.eql(u8, cmd, "dump")) {
  56. const outp = try std.fmt.allocPrintSentinel(gpa, "{s}", .{iter.next().?}, 0);
  57. var buf: std.ArrayList(u8) = .empty;
  58. var it = db.idx.iterator();
  59. while (it.next()) |kv| {
  60. for (kv.value_ptr.entries.items) |e| {
  61. var kb: [40]u8 = undefined;
  62. const ks = switch (e.key) {
  63. .num => |x| engine.jsNumFmt(&kb, x),
  64. .str => |s| s,
  65. };
  66. const line = try std.fmt.allocPrint(gpa, "{s}\t{s}\t{d}\t{d}\n", .{ kv.key_ptr.*, ks, e.off, e.len });
  67. defer gpa.free(line);
  68. try buf.appendSlice(gpa, line);
  69. }
  70. }
  71. const fd: i32 = @bitCast(@as(u32, @truncate(linux.open(outp, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, 0o644))));
  72. var off: usize = 0;
  73. while (off < buf.items.len) {
  74. const rc = linux.write(fd, buf.items.ptr + off, buf.items.len - off);
  75. off += rc;
  76. }
  77. _ = linux.close(fd);
  78. }
  79. const t2 = nowNs();
  80. db.close();
  81. const t3 = nowNs();
  82. std.debug.print("open {d} ms, close {d} ms\n", .{ @divTrunc(t1 - t0, 1_000_000), @divTrunc(t3 - t2, 1_000_000) });
  83. }

Branches

Latest commits

  • 41773828Records: statusmre
  • a82c0805Records: mission 001 brief (Style form)mre
  • a4bce6d1Records: ticket push subscriptionmre
  • 14abde3bjukebox: records: Atlas's records moved to worldapi-conductor/archivemre
  • 0433e9a8jukebox: records: gitoria remote added and pushedmre
  • 1722d707jukebox: records: repo creation handed to Gitoriamre
  • b42e7dfbjukebox: conductor records (CONDUCTOR.md, STATUS.md), old STATUS archivedmre
  • 1b0d0bc1jukebox: a startup error prints its message before exit 1 (hybriel#247)mre
  • b19c478bjukebox JB18 (jukebox#17): onto Hybriel set-day31 (b287cd82, contains the SIGPIPE fix 6d2ca454): plugins/core and plugins/web re-vendored, bin/ from the set; a client that closes /stream while it is written no longer kills the server (90 aborted streams survived, the old bin died with exit 141 on the first)mre
  • 73867a2ejukebox#2: Style blocks in the language's nested form (rules named after the View's own elements, pseudo-classes nested, merged duplicates); the same CSS rules, the pages look the samemre
  • 06c548d6jukebox JB15: report, log linemre
  • 980859cbjukebox JB15 (jukebox#15): the now-playing overlay on a short screen (tablet or phone on its side) gave the queue 12 to 100 px because the big cover took the room; the cover now shrinks with the screen height and goes away under 41rem, the queue keeps 3+ rows; gate tests/jb15.mjs at 8 sizesmre
  • 9efc40ffjukebox#12 #14: Grok session 1793246574527-181160mre
  • 7d58b36ejukebox JB13 (jukebox#13): Next and Previous ask for the songs after / before the current song's id in the current order, not for place + 1; gate tests/jb13.mjs checks Next with the queue down to one song after the order changedmre
  • 51358794jukebox JB14 (jukebox#14): the Songs screen opens sorted the way it was left (kept on the server in storage/ui.json), the sort control shows the sort the rows really have (selected options, autocomplete off); gate tests/jb14.mjsmre
  • cc68a063jukebox JB13 (jukebox#13): a tapped song plays the song that was tapped, found by its id in the list as it is now (not by its row number, which counted plays move); the queue goes on from its place there, the rows refresh on the tap; gate tests/jb13.mjs (songs by plays, favourites)mre
  • 88d3d5c1jukebox JB12b (jukebox#12): the scroll handle is big (2.75rem x 4rem, accent colour, grip) and drawn on every device, no media query; native bar hidden; gate tests/touch.mjs checks the drawn width with and without touchmre
  • b58e4495jukebox JB11 (jukebox#11): the next song starts in the ended event on the same audio element, so it also starts with the screen locked; gate tests/jb11.mjs (hidden tab, no frames)mre
  • 12a26233jukebox JB12 (jukebox#12): the long lists get a scroll handle a finger can use on touch screens (44 px tap area, slim look, drag through all rows), gate tests/touch.mjsmre
  • 0f2157a9jukebox JV1: onto Hybriel set-day27b: readBytes and stat for /stream and the mp3 tags (no dd, head or tail), startup fault exits 1, fs and mpackdb plugins re-vendored; songs with a comma in the title are indexed againmre