perf: prioritize audio preroll after paused network previews
This commit is contained in:
@@ -59,9 +59,11 @@ class BenchmarkServer(StreamingServer):
|
||||
"connections": len(self.connections)}
|
||||
|
||||
|
||||
def sample(binary: Path, cast: bool, source: str, server: BenchmarkServer):
|
||||
def sample(binary: Path, cast: bool, source: str, server: BenchmarkServer, *, seek_work: bool = False):
|
||||
command = [str(binary.resolve())] + (["--playback-benchmark"] if cast else [])
|
||||
command += [server.base_url, source]
|
||||
if seek_work:
|
||||
command.append("--seek-work")
|
||||
rows = []
|
||||
# A process deadline is infrastructure protection, never a measured playback clock.
|
||||
with subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
@@ -102,8 +104,10 @@ def sample(binary: Path, cast: bool, source: str, server: BenchmarkServer):
|
||||
if process.poll() is None:
|
||||
process.kill()
|
||||
process.wait()
|
||||
if sorted(row["phase"] for row in rows) != ["cached_seek", "cold_start", "sustained", "uncached_seek"]:
|
||||
raise RuntimeError("benchmark must report all four phases exactly once")
|
||||
expected_phases = (["cold_start", "uncached_seek"] if seek_work else
|
||||
["cached_seek", "cold_start", "sustained", "uncached_seek"])
|
||||
if sorted(row["phase"] for row in rows) != expected_phases:
|
||||
raise RuntimeError(f"benchmark must report each expected phase exactly once: {expected_phases}")
|
||||
return rows
|
||||
|
||||
|
||||
@@ -114,13 +118,52 @@ def main():
|
||||
parser.add_argument("fixtures", type=Path)
|
||||
parser.add_argument("--runs", type=int, default=3)
|
||||
parser.add_argument("--request-delay-ms", type=float, nargs="+", default=[0, 25])
|
||||
parser.add_argument("--compare-native", type=Path, metavar="BASELINE_BINARY")
|
||||
parser.add_argument("--seek-work", action="store_true")
|
||||
args = parser.parse_args()
|
||||
if args.runs < 1 or any(value < 0 for value in args.request_delay_ms):
|
||||
parser.error("runs must be positive and delays nonnegative")
|
||||
if args.seek_work and not args.compare_native:
|
||||
parser.error("--seek-work requires --compare-native")
|
||||
fixtures(args.fixtures)
|
||||
print(json.dumps({"environment": platform.platform(), "machine": platform.machine(),
|
||||
"runs": args.runs, "request_delay_ms": args.request_delay_ms}), flush=True)
|
||||
"runs": args.runs, "request_delay_ms": args.request_delay_ms,
|
||||
**({"baseline": str(args.compare_native), "candidate": str(args.native),
|
||||
"seek_work": args.seek_work} if args.compare_native else {})}), flush=True)
|
||||
results = []
|
||||
if args.compare_native:
|
||||
for delay in args.request_delay_ms:
|
||||
for run in range(1, args.runs + 1):
|
||||
variants = [("baseline", args.compare_native), ("candidate", args.native)]
|
||||
if run % 2 == 0:
|
||||
variants.reverse()
|
||||
for source in ("split", "hls"):
|
||||
for variant, binary in variants:
|
||||
with BenchmarkServer(args.fixtures, delay) as server:
|
||||
for row in sample(binary, False, source, server, seek_work=args.seek_work):
|
||||
row.update(engine="native", variant=variant, source=source,
|
||||
request_delay_ms=delay, run=run)
|
||||
results.append(row)
|
||||
print(json.dumps(row, sort_keys=True), flush=True)
|
||||
print("\nMedians [min, max]; CPU is process CPU; peak RSS is process-lifetime high water; "
|
||||
"upstream counts include concurrent read-ahead.")
|
||||
print("| Delay ms | Variant | Source | Phase | Wall ms | CPU ms | Peak MiB | Requests | Upstream bytes |")
|
||||
print("| --- | --- | --- | --- | ---: | ---: | ---: | ---: | ---: |")
|
||||
for delay in args.request_delay_ms:
|
||||
for variant in ("baseline", "candidate"):
|
||||
for source in ("split", "hls"):
|
||||
phases = dict.fromkeys(row["phase"] for row in results)
|
||||
for phase in phases:
|
||||
group = [row for row in results if
|
||||
(row["request_delay_ms"], row["variant"], row["source"], row["phase"]) ==
|
||||
(delay, variant, source, phase)]
|
||||
def summary(key):
|
||||
values = [row[key] for row in group]
|
||||
return f"{statistics.median(values):.2f} [{min(values):.2f}, {max(values):.2f}]"
|
||||
print(f"| {delay:g} | {variant} | {source} | {phase} | "
|
||||
f"{summary('wall_ms')} | {summary('cpu_ms')} | {summary('peak_rss_mib')} | "
|
||||
f"{summary('upstream_requests')} | {summary('upstream_bytes')} |")
|
||||
return
|
||||
for delay in args.request_delay_ms:
|
||||
for run in range(1, args.runs + 1):
|
||||
for source in ("split", "hls"):
|
||||
|
||||
Reference in New Issue
Block a user