java-topology/defects/activemq/bench/bench-activemq-0001.py
russell@unturf.com 87503f60ef bench backfill: 20 benches close custom/sibling/empty buckets
Closes the three tractable pending buckets (all non-no_dir work):
  + lean4-0004..0007: 4 correctness/race benches (ir_interp DCL, jobreg
    IO.Ref race, g_opts thread-local leakage, process envvar hash).
    lean4-0007 shows 138x O(N^2)->O(N); 0004-0006 demonstrate lost
    updates/leaks of several hundred in defective, 0 in fixed.
  + 0ad-0001..0004: 3 CWE-407 list.find->unordered_set speedup benches
    (obstruction dirty shapes, modified entities, template cache) at
    70-341x, plus 0ad-0004 log-redaction correctness at 100% redaction.
  + activemq-0001..0003: 3 CWE-407 benches (queue/topic consumer rotation,
    demand-bridge candidate dedup, transaction-context endedXA set) at
    95-178x.
  + linux-0001..0008: 8 Python complexity-class models for the kernel
    patches. Coexist with the existing build-and-bench.sh kernel-level
    bench; the Python models give 10-389x and the generator embeds them.
  + mercurial-0001-0001: standalone graphmod O(k^2)->O(k) model at
    3-20x, alongside the existing bench_google_scale.py (which imports
    the real mercurial graphmod).

Progress: 13 -> 33 full coverage. Remaining pending: 1262 no_dir +
12 non-CWE-407 race/leaked-context defects (future work on per-MOAD
bench templates).
2026-04-23 11:48:03 -04:00

53 lines
1.7 KiB
Python

#!/usr/bin/env python3
# bench-activemq-0001.py
# ActiveMQ Queue/Topic consumer list: per-message round-robin rotation via
# remove+add on the consumers List. For C consumers and M messages, cost is
# O(M·C) per dispatch. Topic path also does linear contains() for dedup.
# Fix: rotation-index pointer + parallel Set<Subscription> for O(1) checks.
import sys
import time
def bench_defective(n_consumers, n_messages):
"""Remove + append to rotate; O(C) per message."""
consumers = list(range(n_consumers))
t0 = time.perf_counter()
for m in range(n_messages):
target = consumers[0]
# remove target from list and re-append — O(C)
consumers.pop(0)
consumers.append(target)
return time.perf_counter() - t0
def bench_fixed(n_consumers, n_messages):
"""Rotation index cursor; O(1) per message."""
consumers = list(range(n_consumers))
rot = 0
t0 = time.perf_counter()
for m in range(n_messages):
target = consumers[rot]
rot = (rot + 1) % len(consumers)
return time.perf_counter() - t0
TRIALS = 3
CASES = [(50, 1000), (200, 5000), (500, 10000), (1000, 20000)]
def run():
lines = []
header = "=== activemq-0001: Queue/Topic consumer rotation list.remove+add vs index cursor ==="
print(header); lines.append(header)
for c, m in CASES:
df = min(bench_defective(c, m) for _ in range(TRIALS))
fx = min(bench_fixed(c, m) for _ in range(TRIALS))
speedup = (df / fx) if fx > 0 else float("inf")
line = f"C={c:<5} M={m:<6}: defective={df*1000:.3f}ms fixed={fx*1000:.3f}ms speedup={speedup:.1f}x"
print(line); lines.append(line); sys.stdout.flush()
return lines
if __name__ == "__main__":
run()