diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 14:44:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 19:37:50 -0300 |
| commit | 484baaf3d237c91a6ba5f7e2016c988e8aee00d3 (patch) | |
| tree | 4a8b6a3301b482bbf44da4ce7bd1623b5e117f71 /test/delay_relay.py | |
| parent | 9f84ac9f0d715d7717dc1d732299bdc586422392 (diff) | |
| download | pardes-484baaf3d237c91a6ba5f7e2016c988e8aee00d3.tar.gz pardes-484baaf3d237c91a6ba5f7e2016c988e8aee00d3.zip | |
test/soak.py: a soak of replica clients, what a person does in them through each link, measured: a session on a directory and two shells (here, or on the FreeBSD box over ssh), terminal clients in a pty kept by pyte and offscreen window clients through their test feed, each a seeded monkey of moves, edits, undo, saves, Looks, pickers, shells with programs, panes and columns, clicks, the wheel, the pointer resting, pastes and idle gaps, beside resizes, detaches and attaches, an Upgrade and a script's 9P edits; its table a client (rejoins, checks that differ, exits and cores, freezes at quiet points, a terminal client's screen and cursor against the session's render of its view, visible rollbacks, keystroke to output or frame p50/p99) and the session's worst boundary, exit 1 on any breach; test/delay_relay.py takes --jitter (order kept)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test/delay_relay.py')
| -rw-r--r-- | test/delay_relay.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/test/delay_relay.py b/test/delay_relay.py index 9d57095f..c600a3aa 100644 --- a/test/delay_relay.py +++ b/test/delay_relay.py @@ -4,9 +4,11 @@ it accepts on one socket, connects each client on to another, and holds every chunk `delay` ms each way, timed from its arrival, so a stream's throughput is not serialised behind the delay and its bytes stay in order. An optional rate cap makes the link a bottleneck too: a chunk leaves once -the ones before it have crossed at that rate, then waits out the delay. +the ones before it have crossed at that rate, then waits out the delay. An +optional jitter adds up to that many ms more to each chunk's delay, at +random, its order kept (a chunk never overtakes the one before it). - python3 -B test/delay_relay.py LISTEN TARGET --delay MS [--rate MB/s] + python3 -B test/delay_relay.py LISTEN TARGET --delay MS [--rate MB/s] [--jitter MS] python3 -B test/delay_relay.py --self-check An address is a path (a Unix socket) or host:port (TCP). The one-way @@ -17,6 +19,7 @@ adds at each, and with a cap. import argparse import os import queue +import random import socket import statistics import sys @@ -58,13 +61,15 @@ def listen(address): return s -def pump(src, dst, delay, rate, done): +def pump(src, dst, delay, rate, done, jitter=0.0): """src -> dst, each chunk due `delay` s after it arrived (and after the - ones before it crossed at `rate` bytes/s), in order; its end a shutdown.""" + ones before it crossed at `rate` bytes/s), plus up to `jitter` s at + random but never before the chunk ahead of it; its end a shutdown.""" due_q = queue.SimpleQueue() def reader(): free = 0.0 # when the capped link has sent what it holds + last = 0.0 # when the chunk before is due: order is kept while True: try: data = src.recv(CHUNK) @@ -74,7 +79,8 @@ def pump(src, dst, delay, rate, done): if rate: free = max(free, now) + len(data) / rate now = free - due_q.put((now + delay, data)) + last = max(last, now + delay + (random.uniform(0, jitter) if jitter else 0)) + due_q.put((last, data)) if not data: return @@ -98,9 +104,10 @@ def pump(src, dst, delay, rate, done): threading.Thread(target=writer, daemon=True).start() -def serve(listener, target, delay_ms, rate_mbs=None): +def serve(listener, target, delay_ms, rate_mbs=None, jitter_ms=0): """Relays every connection `listener` accepts until it is closed.""" delay = delay_ms / 1000 + jitter = jitter_ms / 1000 rate = rate_mbs * 1e6 if rate_mbs else None while True: try: @@ -124,8 +131,8 @@ def serve(listener, target, delay_ms, rate_mbs=None): a.close() b.close() - pump(client, upstream, delay, rate, done) - pump(upstream, client, delay, rate, done) + pump(client, upstream, delay, rate, done, jitter) + pump(upstream, client, delay, rate, done, jitter) # ---- the self-check ---- @@ -252,12 +259,13 @@ def main(): ap.add_argument('target') ap.add_argument('--delay', type=float, required=True, help='one-way delay, ms') ap.add_argument('--rate', type=float, help='a bandwidth cap, MB/s') + ap.add_argument('--jitter', type=float, default=0, help='up to this many ms more a chunk, at random') a = ap.parse_args() listener = listen(a.listen) print(f'relaying {a.listen} -> {a.target}, {a.delay} ms each way' - + (f', {a.rate} MB/s' if a.rate else ''), flush=True) + + (f', {a.rate} MB/s' if a.rate else '') + (f', jitter {a.jitter} ms' if a.jitter else ''), flush=True) try: - serve(listener, a.target, a.delay, a.rate) + serve(listener, a.target, a.delay, a.rate, a.jitter) except KeyboardInterrupt: pass |
