|
| 1 | +""" |
| 2 | +Analyze and visualize MCP server benchmark results. |
| 3 | +Analyzer generated by Claude 4.5 Sonnet. |
| 4 | +""" |
| 5 | + |
| 6 | +import json |
| 7 | +import sys |
| 8 | +from pathlib import Path |
| 9 | +from typing import Any |
| 10 | + |
| 11 | +LOAD_INFO = { |
| 12 | + "sequential_load": ("Sequential Load", "1 concurrent request"), |
| 13 | + "light_load": ("Light Load", "20 concurrent requests"), |
| 14 | + "medium_load": ("Medium Load", "100 concurrent requests"), |
| 15 | + "heavy_load": ("Heavy Load", "300 concurrent requests"), |
| 16 | +} |
| 17 | + |
| 18 | + |
| 19 | +def load_results(json_path: Path) -> dict[str, Any]: |
| 20 | + """Load benchmark results from JSON file.""" |
| 21 | + |
| 22 | + if not json_path.exists(): |
| 23 | + print(f"Error: File not found: {json_path}") |
| 24 | + sys.exit(1) |
| 25 | + |
| 26 | + with open(json_path) as f: |
| 27 | + return json.load(f) |
| 28 | + |
| 29 | + |
| 30 | +def calculate_improvement(minimcp_val: float, fastmcp_val: float, lower_is_better: bool = True) -> float: |
| 31 | + """Calculate percentage improvement.""" |
| 32 | + if lower_is_better: |
| 33 | + return ((fastmcp_val - minimcp_val) / fastmcp_val) * 100 |
| 34 | + else: |
| 35 | + return ((minimcp_val - fastmcp_val) / fastmcp_val) * 100 |
| 36 | + |
| 37 | + |
| 38 | +def print_title(title: str) -> None: |
| 39 | + # Bold + Underline |
| 40 | + print("\033[1m\033[4m" + title + "\033[0m\n") |
| 41 | + |
| 42 | + |
| 43 | +def organize_results(results: dict[str, Any]) -> tuple[dict[str, Any], dict[str, Any]]: |
| 44 | + """Organize results by server and load.""" |
| 45 | + data: dict[str, dict[str, Any]] = {} |
| 46 | + for result in results["results"]: |
| 47 | + server = result["server_name"] |
| 48 | + load = result["load_name"] |
| 49 | + if server not in data: |
| 50 | + data[server] = {} |
| 51 | + data[server][load] = result["metrics"] |
| 52 | + |
| 53 | + return data["minimcp"], data["fastmcp"] |
| 54 | + |
| 55 | + |
| 56 | +def print_metadata(results: dict[str, Any]) -> None: |
| 57 | + """Print metadata.""" |
| 58 | + min, sec = divmod(results["metadata"]["duration_seconds"], 60) |
| 59 | + print(f"Date: {results['metadata']['timestamp']}") |
| 60 | + print(f"Duration: {min:.0f}m {sec:.0f}s\n") |
| 61 | + |
| 62 | + |
| 63 | +def print_key_findings(results: dict[str, Any]) -> None: |
| 64 | + """Print key findings section.""" |
| 65 | + print_title("Key Findings") |
| 66 | + |
| 67 | + minimcp, fastmcp = organize_results(results) |
| 68 | + |
| 69 | + # Response time improvements (excluding sequential) |
| 70 | + response_improvements: list[float] = [] |
| 71 | + for load in ["light_load", "medium_load", "heavy_load"]: |
| 72 | + min_rt = minimcp[load]["response_time"]["mean"] |
| 73 | + fast_rt = fastmcp[load]["response_time"]["mean"] |
| 74 | + improvement = calculate_improvement(min_rt, fast_rt, lower_is_better=True) |
| 75 | + response_improvements.append(improvement) |
| 76 | + |
| 77 | + rt_min = min(response_improvements) |
| 78 | + rt_max = max(response_improvements) |
| 79 | + |
| 80 | + # Throughput improvements |
| 81 | + throughput_improvements: list[float] = [] |
| 82 | + for load in ["light_load", "medium_load", "heavy_load"]: |
| 83 | + min_tp = minimcp[load]["throughput_rps"]["mean"] |
| 84 | + fast_tp = fastmcp[load]["throughput_rps"]["mean"] |
| 85 | + improvement = calculate_improvement(min_tp, fast_tp, lower_is_better=False) |
| 86 | + throughput_improvements.append(improvement) |
| 87 | + |
| 88 | + tp_min = min(throughput_improvements) |
| 89 | + tp_max = max(throughput_improvements) |
| 90 | + |
| 91 | + # Memory improvements |
| 92 | + memory_improvements: list[float] = [] |
| 93 | + for load in ["medium_load", "heavy_load"]: |
| 94 | + min_mem = minimcp[load]["max_memory_usage"]["mean"] |
| 95 | + fast_mem = fastmcp[load]["max_memory_usage"]["mean"] |
| 96 | + improvement = calculate_improvement(min_mem, fast_mem, lower_is_better=True) |
| 97 | + memory_improvements.append(improvement) |
| 98 | + |
| 99 | + mem_min = min(memory_improvements) |
| 100 | + mem_max = max(memory_improvements) |
| 101 | + |
| 102 | + print( |
| 103 | + f"- MiniMCP outperforms FastMCP by ~{rt_min:.0f}-{rt_max:.0f}% in response time across " |
| 104 | + "all concurrent load scenarios" |
| 105 | + ) |
| 106 | + print(f"- MiniMCP achieves ~{tp_min:.0f}-{tp_max:.0f}% higher throughput than FastMCP") |
| 107 | + |
| 108 | + # Handle memory improvements (can be positive or negative) |
| 109 | + if mem_min >= 0 and mem_max >= 0: |
| 110 | + print(f"- MiniMCP uses ~{mem_min:.0f}-{mem_max:.0f}% less memory under medium to heavy loads") |
| 111 | + elif mem_min < 0 and mem_max < 0: |
| 112 | + print(f"- MiniMCP uses ~{abs(mem_max):.0f}-{abs(mem_min):.0f}% more memory under medium to heavy loads") |
| 113 | + else: |
| 114 | + print( |
| 115 | + f"- MiniMCP memory usage varies from {mem_min:.0f}% to {mem_max:.0f}% compared to FastMCP under medium " |
| 116 | + "to heavy loads" |
| 117 | + ) |
| 118 | + print() |
| 119 | + |
| 120 | + |
| 121 | +def print_response_time_visualization(results: dict[str, Any]) -> None: |
| 122 | + """Print response time visualization.""" |
| 123 | + print_title("Response Time Visualization (smaller is better)") |
| 124 | + |
| 125 | + minimcp, fastmcp = organize_results(results) |
| 126 | + |
| 127 | + for load_key, (title, subtitle) in LOAD_INFO.items(): |
| 128 | + min_rt = minimcp[load_key]["response_time"]["mean"] * 1000 # to ms |
| 129 | + fast_rt = fastmcp[load_key]["response_time"]["mean"] * 1000 |
| 130 | + improvement = calculate_improvement(min_rt, fast_rt, lower_is_better=True) |
| 131 | + |
| 132 | + # Scale bars (max 50 chars for fastmcp) |
| 133 | + max_val = max(min_rt, fast_rt) |
| 134 | + fast_bars = int((fast_rt / max_val) * 50) |
| 135 | + min_bars = int((min_rt / max_val) * 50) |
| 136 | + |
| 137 | + # Determine if minimcp is better or worse |
| 138 | + if improvement > 0: |
| 139 | + status = f"✓ {improvement:.1f}% faster" |
| 140 | + else: |
| 141 | + status = f"✗ {abs(improvement):.1f}% slower" |
| 142 | + |
| 143 | + print(f"{title} ({subtitle})") |
| 144 | + print(f"minimcp {'▓' * min_bars} {min_rt:.2f}ms {status}") |
| 145 | + print(f"fastmcp {'▓' * fast_bars} {fast_rt:.2f}ms") |
| 146 | + print() |
| 147 | + print() |
| 148 | + |
| 149 | + |
| 150 | +def print_memory_visualization(results: dict[str, Any]) -> None: |
| 151 | + """Print maximum memory usage visualization.""" |
| 152 | + print_title("Maximum Memory Usage Visualization (smaller is better)") |
| 153 | + |
| 154 | + minimcp, fastmcp = organize_results(results) |
| 155 | + |
| 156 | + for load_key, (title, subtitle) in LOAD_INFO.items(): |
| 157 | + min_mem = minimcp[load_key]["max_memory_usage"]["mean"] |
| 158 | + fast_mem = fastmcp[load_key]["max_memory_usage"]["mean"] |
| 159 | + improvement = calculate_improvement(min_mem, fast_mem, lower_is_better=True) |
| 160 | + |
| 161 | + # Scale bars (max 50 chars for the higher value) |
| 162 | + max_val = max(min_mem, fast_mem) |
| 163 | + min_bars = int((min_mem / max_val) * 50) |
| 164 | + fast_bars = int((fast_mem / max_val) * 50) |
| 165 | + |
| 166 | + # Determine if minimcp is better or worse |
| 167 | + if improvement > 0: |
| 168 | + status = f"✓ {improvement:.1f}% lower" |
| 169 | + else: |
| 170 | + status = f"✗ {abs(improvement):.1f}% higher" |
| 171 | + |
| 172 | + print(f"{title} ({subtitle})") |
| 173 | + print(f"minimcp {'▓' * min_bars} {min_mem:,.0f} KB {status}") |
| 174 | + print(f"fastmcp {'▓' * fast_bars} {fast_mem:,.0f} KB") |
| 175 | + print() |
| 176 | + print() |
| 177 | + |
| 178 | + |
| 179 | +def main() -> None: |
| 180 | + """Main entry point.""" |
| 181 | + if len(sys.argv) != 2: |
| 182 | + print("Usage: python analyze_results.py <results.json>") |
| 183 | + sys.exit(1) |
| 184 | + |
| 185 | + json_path = Path(sys.argv[1]) |
| 186 | + results = load_results(json_path) |
| 187 | + |
| 188 | + print() |
| 189 | + print_title("Benchmark Analysis") |
| 190 | + |
| 191 | + print_metadata(results) |
| 192 | + print_key_findings(results) |
| 193 | + print_response_time_visualization(results) |
| 194 | + print_memory_visualization(results) |
| 195 | + |
| 196 | + |
| 197 | +if __name__ == "__main__": |
| 198 | + main() |
0 commit comments