Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Replay a synthetic workload through the scheduler on a virtual clock.
|
|
|
|
python3 run_sim.py --jobs 50000 --seed 3
|
|
python3 run_sim.py --jobs 2000 --log /tmp/sim.log
|
|
|
|
Prints a one-line JSON summary; the exit status is 1 when jobs were lost or ran twice.
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
|
|
from sched.sim import Sim, SimConfig
|
|
|
|
|
|
def main(argv=None):
|
|
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
|
ap.add_argument("--jobs", type=int, default=30000, help="number of client requests (default 30000)")
|
|
ap.add_argument("--seed", type=int, default=1)
|
|
ap.add_argument("--workers", type=int, default=3)
|
|
ap.add_argument("--slow-workers", type=int, default=1, help="workers that only serve the export lane")
|
|
ap.add_argument("--rate", type=float, default=1.0, help="new jobs per second")
|
|
ap.add_argument("--export-prob", type=float, default=1 / 6000)
|
|
ap.add_argument("--log", metavar="FILE", help="also write the service log to FILE")
|
|
args = ap.parse_args(argv)
|
|
|
|
cfg = SimConfig(
|
|
jobs=args.jobs,
|
|
seed=args.seed,
|
|
workers=args.workers,
|
|
slow_workers=args.slow_workers,
|
|
rate=args.rate,
|
|
export_prob=args.export_prob,
|
|
keep_log=bool(args.log),
|
|
)
|
|
sim = Sim(cfg)
|
|
summary = sim.run()
|
|
if args.log:
|
|
with open(args.log, "w") as fh:
|
|
fh.write("\n".join(sim.log.lines) + "\n")
|
|
print(json.dumps(summary, sort_keys=True))
|
|
return 1 if summary["lost"] or summary["duplicated"] else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|