#!/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('