diff options
| author | eunhhu <[email protected]> | 2026-09-26 23:24:31 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-26 23:24:31 +0100 |
| commit | 2e7ad9f8488d4f02c688ec24d6d0b571b3fa61ec (patch) | |
| tree | 789183f42e3b68b797e7a09ef2b037e55d34ebfa /research/experiments/012-tail-records/run.py | |
| parent | a51232af741cb952d7deb72f238c583919ababc0 (diff) | |
| download | pure-2e7ad9f8488d4f02c688ec24d6d0b571b3fa61ec.tar.gz pure-2e7ad9f8488d4f02c688ec24d6d0b571b3fa61ec.zip | |
Write each commit's head just before its bytes: one range per sync (081)
A tree store commit wrote its bytes over the written zeros of the tail
and its head into a slot at the start of the file: two ranges, and on
the Pi's SD card a sync of two ranges costs about twice one (2.4 ms
against 1.2 ms). A commit now writes a 128-byte record (its head) at
the published end and its bytes right after it, then syncs once. Every
16 commits the head also goes into the older slot. The newest commit
is found from the newer slot's head, or from the newest head this
process has seen in the file while its record is still there, along
the records whose bytes are whole; a torn record or bytes end the walk
at the commit before, which the next writer overwrites. Slots of this
format are PURETRE3; files of the earlier one are read and continued.
Store commits went from 220-233/s to 371-396/s (p50 2.5 to 1.3 ms),
and the scoreboard's durable posts from 13-16k/s to 21-26k/s with 64
connections and from 2.2-2.4k/s to 2.9-3.9k/s with 8, measured
alternately with the previous build. The torn head check now tears a
slot (the walk goes on from the other) and the newest record (a new
process sees the commit before); a new check walks 42 commits from the
slots, in a fresh process too, and stops at a damaged record.
Diffstat (limited to 'research/experiments/012-tail-records/run.py')
| -rwxr-xr-x | research/experiments/012-tail-records/run.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/research/experiments/012-tail-records/run.py b/research/experiments/012-tail-records/run.py new file mode 100755 index 0000000..7fc342e --- /dev/null +++ b/research/experiments/012-tail-records/run.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +"""Commit cost by where the head goes (see docs/research/081-tail-records.md). + +Runs probe.c (a small commit's sync with its head in a slot at the start, or +just before its bytes) for 2 KiB and 8 KiB commits, and ../010-one-sync-commit +/commits.c (tree store commit latency) built against the store of --before +(heads in slots) and the current one (heads as records before the bytes), +alternating their order per round so device drift reaches both alike. Prints +one JSON document. +""" +import argparse +import json +import shutil +import subprocess +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[2] +PURE = ROOT / 'prototypes' / 'connections' +COMMITS = HERE.parent / '010-one-sync-commit' / 'commits.c' + + +def build(output, sources): + subprocess.run(['cc', '-O2', '-std=c17', f'-I{PURE}', '-o', str(output)] + [str(s) for s in sources] + ['-lpthread'], + check=True) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--directory', type=Path, default=Path('/var/tmp'), help='on the device to measure') + parser.add_argument('--before', default='2ef0d40', help='a revision with heads in slots') + parser.add_argument('--rounds', type=int, default=3) + parser.add_argument('--commits', type=int, default=400) + args = parser.parse_args() + with tempfile.TemporaryDirectory() as work: + work = Path(work) + before = work / 'store-tree-before.c' + before.write_text(subprocess.run(['git', '-C', str(ROOT), 'show', f'{args.before}:prototypes/connections/store-tree.c'], + capture_output=True, text=True, check=True).stdout) + build(work / 'probe', [HERE / 'probe.c']) + builds = {'heads in slots': work / 'commits-before', 'heads as records': work / 'commits-after'} + build(builds['heads in slots'], [COMMITS, before]) + build(builds['heads as records'], [COMMITS, PURE / 'store-tree.c']) + results = {'rounds': []} + for round_ in range(args.rounds): + measured = {'probe': [], 'commits': {}} + for size in (2048, 8192): + probe = subprocess.run([str(work / 'probe'), str(args.directory), str(size)], capture_output=True, + text=True, check=True) + measured['probe'] += [json.loads(line) for line in probe.stdout.splitlines()] + names = list(builds) if round_ % 2 == 0 else list(builds)[::-1] + for name in names: + store = Path(tempfile.mkdtemp(dir=args.directory, prefix='pure-commit-cost-')) + shutil.rmtree(store) + try: + run = subprocess.run([str(builds[name]), str(store), str(args.commits)], capture_output=True, text=True, + check=True) + measured['commits'][name] = json.loads(run.stdout) + finally: + shutil.rmtree(store, ignore_errors=True) + results['rounds'].append(measured) + print(json.dumps(measured), file=sys.stderr, flush=True) + print(json.dumps(results, indent=1)) + + +if __name__ == '__main__': + sys.exit(main()) |
