Repository: LMCache/LMCache
File: lmcache/tools/controller_benchmark/__main__.py (Python)

Code before:
    for op_name in operations.keys():
        op_stats_list = [
            r.operations[op_name] for r in results_list if op_name in r.operations
        ]
        if op_stats_list:
            # Sum QPS and RPS
            total_qps = sum(s.qps for s in op_stats_list)
            total_rps = sum(s.rps for s in op_stats_list)

            # Average latencies (weighted by RPS would be more accurate,
            # but simple average is acceptable)
            min_latencies = [s.min_latency for s in op_stats_list if s.min_latency > 0]
            max_latencies = [s.max_latency for s in op_stats_list if s.max_latency > 0]
            p95_latencies = [s.p95_latency for s in op_stats_list if s.p95_latency > 0]

            aggregated.operations[op_name] = OperationStats(
                qps=total_qps,
                rps=total_rps,
                avg_latency=(
                    sum(s.avg_latency * s.rps for s in op_stats_list) / total_rps
                    if total_rps > 0
                    else 0.0
                ),
                min_latency=min(min_latencies) if min_latencies else 0.0,
                max_latency=max(max_latencies) if max_latencies else 0.0,
                p95_latency=max(p95_latencies) if p95_latencies else 0.0,
                errors=sum(s.errors for s in op_stats_list),
            )

    return aggregated


def print_aggregated_results(
    results: BenchmarkResults,
    config: ZMQBenchmarkConfig,
    num_processes: int,
):
    """Print aggregated benchmark results from all processes"""
    print("\n" + "=" * 80)
    print(
        "LMCache Controller ZMQ Benchmark - AGGREGATED RESULTS (%d processes)"
        % num_processes
    )
    print("=" * 80)

    print("\nConfiguration:")
    print("  Controller URL: %s" % config.controller_pull_url)
    print("  Duration: %d seconds" % config.duration)
    print("  Batch Size: %d" % config.batch_size)
    print("  Operations: %s" % config.operations)
    print(

Review comment (performance):
possibility: 
```python
p95_latency=(
    sum(s.p95_latency * s.rps for s in op_stats_list) / total_rps
    if total_rps > 0 and p95_latencies else 0.0
),
```
approximates a global P95 weighted by request volume



Code after:
    for op_name in operations.keys():
        op_stats_list = [
            r.operations[op_name] for r in results_list if op_name in r.operations
        ]
        if op_stats_list:
            # Sum QPS and RPS
            total_qps = sum(s.qps for s in op_stats_list)
            total_rps = sum(s.rps for s in op_stats_list)

            # Average latencies (weighted by RPS would be more accurate,
            # but simple average is acceptable)
            min_latencies = [s.min_latency for s in op_stats_list if s.min_latency > 0]
            max_latencies = [s.max_latency for s in op_stats_list if s.max_latency > 0]
            p95_latencies = [s.p95_latency for s in op_stats_list if s.p95_latency > 0]

            aggregated.operations[op_name] = OperationStats(
                qps=total_qps,
                rps=total_rps,
                avg_latency=(
                    sum(s.avg_latency * s.rps for s in op_stats_list) / total_rps
                    if total_rps > 0
                    else 0.0
                ),
                min_latency=min(min_latencies) if min_latencies else 0.0,
                max_latency=max(max_latencies) if max_latencies else 0.0,
                p95_latency=(
                    sum(s.p95_latency * s.rps for s in op_stats_list) / total_rps
                    if total_rps > 0 and p95_latencies
                    else 0.0
                ),
                errors=sum(s.errors for s in op_stats_list),
            )

    return aggregated


def print_aggregated_results(
    results: BenchmarkResults,
    config: ZMQBenchmarkConfig,
    num_processes: int,
):
    """Print aggregated benchmark results from all processes"""
    print("\n" + "=" * 80)
    print(
        "LMCache Controller ZMQ Benchmark - AGGREGATED RESULTS (%d processes)"
        % num_processes
    )
    print("=" * 80)

    print("\nConfiguration:")
    print("  Controller URL: %s" % config.controller_pull_url)