askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
seed_tsv.py · 1.7 KB · 45 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """Seed a throwaway data dir and request-URL lists for the HTTP benchmark. |
| 3 | |
| 4 | python seed_tsv.py DATA_DIR URL_DIR BASE_URL ROWS |
| 5 | |
| 6 | Creates, directly on disk (plain TSV + schema JSON, like the repo's tests): |
| 7 | bench classic, ROWS rows -- read and update targets |
| 8 | bench_log append, ROWS rows -- create target (append mode) |
| 9 | bench_small classic, 1000 rows -- create target (classic mode) |
| 10 | |
| 11 | and writes URL files (one URL per line) that oha cycles through, so the |
| 12 | requests hit random ids/offsets instead of one hot row. A fixed seed means |
| 13 | every server variant sees the identical request sequence. |
| 14 | """ |
| 15 | from __future__ import annotations |
| 16 | |
| 17 | import random |
| 18 | import sys |
| 19 | from pathlib import Path |
| 20 | |
| 21 | sys.path.insert(0, str(Path(__file__).resolve().parent)) |
| 22 | from storage_bench import seed # noqa: E402 |
| 23 | |
| 24 | |
| 25 | def main() -> int: |
| 26 | data_dir, url_dir, base, rows = Path(sys.argv[1]), Path(sys.argv[2]), sys.argv[3].rstrip("/"), int(sys.argv[4]) |
| 27 | url_dir.mkdir(parents=True, exist_ok=True) |
| 28 | seed(data_dir, "bench", rows, "classic") |
| 29 | seed(data_dir, "bench_log", rows, "append") |
| 30 | seed(data_dir, "bench_small", 1000, "classic") |
| 31 | |
| 32 | rng = random.Random(777) |
| 33 | n = 2000 |
| 34 | (url_dir / "get_one.txt").write_text( |
| 35 | "\n".join(f"{base}/collections/bench/records/r{rng.randrange(rows)}" for _ in range(n)) + "\n") |
| 36 | (url_dir / "list_page.txt").write_text( |
| 37 | "\n".join(f"{base}/collections/bench/records?limit=50&offset={rng.randrange(max(1, rows - 50))}" |
| 38 | for _ in range(n)) + "\n") |
| 39 | (url_dir / "update_one.txt").write_text( |
| 40 | "\n".join(f"{base}/collections/bench/records/r{rng.randrange(rows)}" for _ in range(n)) + "\n") |
| 41 | return 0 |
| 42 | |
| 43 | |
| 44 | if __name__ == "__main__": |
| 45 | raise SystemExit(main()) |