From 608221c21edb345e4eeeca85385d2e149c3baa30 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sun, 4 Oct 2026 14:24:12 +0100 Subject: Measure 018 stage 2: a graph search in one event, the pairs, and runs to compare across machines (033) --- research/experiments/033-computing/bfs.py | 113 ++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 research/experiments/033-computing/bfs.py (limited to 'research/experiments/033-computing/bfs.py') diff --git a/research/experiments/033-computing/bfs.py b/research/experiments/033-computing/bfs.py new file mode 100755 index 0000000..8df19a8 --- /dev/null +++ b/research/experiments/033-computing/bfs.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +"""A breadth first search in one event (docs/design/018 stage 2, research +118). A random graph of NODES nodes and EDGES edges (from and to uniform, +no loops, each pair once; seed 118) goes into graph.aup on pure-serve +(store in RAM, cores 0-2) as rows; then SEARCHES searches from random +nodes, each one event (POST /inputs/route), timed by the client (the +request on a kept connection; the event is nearly all of it), ROUNDS +times each. The same searches run in C (bfs.c, adjacency as offsets) and +in CPython (lists and a deque). All three must find the same hops and +reach the same nodes. + +bfs.py PURE_SERVE AUP NODES EDGES SEARCHES ROUNDS a JSON line per search and system, then medians +""" +import collections +import http.client +import json +import random +import shutil +import statistics +import struct +import subprocess +import sys +import tempfile +import time +from pathlib import Path + +HERE = Path(__file__).resolve().parent + + +def main(): + serve, aup = Path(sys.argv[1]).resolve(), Path(sys.argv[2]).resolve() + nodes, edges_wanted, searches, rounds = (int(a) for a in sys.argv[3:7]) + rng = random.Random(118) + pairs = set() + while len(pairs) < edges_wanted: + a, b = rng.randrange(nodes), rng.randrange(nodes) + if a != b: + pairs.add((a, b)) + edges = sorted(pairs) + out = [[] for _ in range(nodes)] + for a, b in edges: + out[a].append(b) + queries = [(rng.randrange(nodes), rng.randrange(nodes)) for _ in range(searches)] + work = Path(tempfile.mkdtemp(prefix='pure-033-', dir='/dev/shm')) + try: + with open(work / 'graph.bin', 'wb') as f: + f.write(struct.pack('