#!/usr/bin/env python3 # Persistent-connection AUTH stress test for CUBELinux-2 cube-server. # # Server's REAL model: one signed-HELLO R4 handshake per connection # (auth-once), then unlimited ops over the open socket (no per-command # re-auth). Fair comparison vs etcd/Redis (auth once at connect). # # Wire: 4-byte little-endian length prefix + UTF-8 payload (cubesys/src/net.rs). # Handshake: server "CHALLENGE "; client "HELLO " # sig = HMAC-SHA256(psk, "nonce|tenant|owner_local|") hex (owner_remote absent). # # Socket has a 3s recv timeout so a WAL-stalled daemon cannot hang the test # forever; timed-out ops are counted as failures (revealing the sustainable # rate under load). ALL artifacts live on real disk (/root/cube-stress), never # tmpfs, because the WAL can exceed tmpfs capacity. import os, sys, socket, struct, time, threading, csv, hmac, hashlib, subprocess, tempfile, shutil from collections import defaultdict import statistics as st REPO = os.environ.get("REPO", "/home/CUBELinux/CUBELinux-2") SRV = os.path.join(REPO, "target/release/cube-server") if not os.path.exists(SRV): sys.exit("cube-server release binary missing; build first") USERS = int(os.environ.get("USERS", "8")) DURATION = int(os.environ.get("DURATION", "150")) PER_TENANT = os.environ.get("PER_TENANT", "0") == "1" PSK = b"lan-shared-key-1234" WORK = "/root/cube-stress" os.makedirs(WORK, exist_ok=True) TMPD = tempfile.mkdtemp(prefix=f"{WORK}/run-") STORE = os.path.join(TMPD, f"store-{os.getpid()}.json") PSK_FILE = os.path.join(TMPD, "psk.txt") open(PSK_FILE, "w").write(PSK.decode()) SOCK = os.path.join(TMPD, "cube.sock") RUN_LOG = os.path.join(TMPD, "run.log") DAEMON_LOG = os.path.join(TMPD, "daemon.log") STATS_LOG = os.path.join(TMPD, "stats-samples.log") ERR_LOG = os.path.join(TMPD, "run-errors.log") CSV = os.path.join(TMPD, "cmds.csv") TENANTS = ["alpha","bravo","charlie","delta","echo","foxtrot","golf","hotel","india","juliet"] OWNERS = ["alice","bob","carol","dave","erin","frank","grace","heidi","ivan","judy"] def log(*a): with open(RUN_LOG, "a") as f: f.write(" ".join(map(str,a)) + "\n") log(f"USERS={USERS} DURATION={DURATION}s PER_TENANT={PER_TENANT} MODE=persistent-connection") def write_frame(sock, payload): b = payload.encode(); sock.sendall(struct.pack("