-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark-mcp-performance.js
More file actions
executable file
·154 lines (122 loc) · 4.94 KB
/
Copy pathbenchmark-mcp-performance.js
File metadata and controls
executable file
·154 lines (122 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bun
/**
* Benchmark script to compare performance between Docker-based and external MCP server connections
* Note: This is a demonstration script - actual measurement would require real MCP server setup
*/
import { performance } from "node:perf_hooks";
async function benchmarkDockerConnection() {
console.log("🐳 Benchmarking Docker-based MCP connection...");
const startTime = performance.now();
// Simulate Docker startup time (typical: 2-3 seconds)
await new Promise((resolve) => setTimeout(resolve, 2500));
const endTime = performance.now();
const connectionTime = endTime - startTime;
console.log(` Connection time: ${connectionTime.toFixed(2)}ms`);
console.log(" Memory overhead: ~150MB (Docker container)");
console.log(" CPU overhead: High (Docker daemon + container startup)");
return {
connectionTime,
memoryOverhead: 150, // MB
cpuOverhead: "high",
};
}
async function benchmarkExternalConnection() {
console.log("⚡ Benchmarking external MCP server connection...");
const startTime = performance.now();
// Simulate external server connection time (typical: 100-200ms)
await new Promise((resolve) => setTimeout(resolve, 150));
const endTime = performance.now();
const connectionTime = endTime - startTime;
console.log(` Connection time: ${connectionTime.toFixed(2)}ms`);
console.log(" Memory overhead: ~5MB (process connection)");
console.log(" CPU overhead: Low (stdio transport only)");
return {
connectionTime,
memoryOverhead: 5, // MB
cpuOverhead: "low",
};
}
async function simulateMultipleOperations(connectionFn, operationName) {
console.log(`\n📊 Simulating 10 ${operationName} operations...`);
const operationTimes = [];
for (let i = 0; i < 10; i++) {
const result = await connectionFn();
operationTimes.push(result.connectionTime);
}
const avgTime =
operationTimes.reduce((sum, time) => sum + time, 0) / operationTimes.length;
const totalTime = operationTimes.reduce((sum, time) => sum + time, 0);
console.log(` Average connection time: ${avgTime.toFixed(2)}ms`);
console.log(` Total time for 10 operations: ${totalTime.toFixed(2)}ms`);
return { avgTime, totalTime, operations: operationTimes };
}
async function main() {
console.log("🚀 MCP Server Performance Benchmark");
console.log("====================================\n");
// Single operation benchmarks
console.log("Single Operation Comparison:");
console.log("----------------------------");
const dockerResult = await benchmarkDockerConnection();
console.log("");
const externalResult = await benchmarkExternalConnection();
// Performance improvement calculation
const improvementRatio =
dockerResult.connectionTime / externalResult.connectionTime;
const timeSaved = dockerResult.connectionTime - externalResult.connectionTime;
console.log("\n📈 Performance Improvement:");
console.log("---------------------------");
console.log(` Speed improvement: ${improvementRatio.toFixed(1)}x faster`);
console.log(` Time saved per operation: ${timeSaved.toFixed(2)}ms`);
console.log(
` Memory saved: ${dockerResult.memoryOverhead - externalResult.memoryOverhead}MB`,
);
// Multiple operations comparison
const dockerBatch = await simulateMultipleOperations(
benchmarkDockerConnection,
"Docker",
);
const externalBatch = await simulateMultipleOperations(
benchmarkExternalConnection,
"External",
);
const batchTimeSaved = dockerBatch.totalTime - externalBatch.totalTime;
const batchImprovementRatio = dockerBatch.totalTime / externalBatch.totalTime;
console.log("\n🏆 Batch Operations Summary:");
console.log("----------------------------");
console.log(` Docker total time: ${dockerBatch.totalTime.toFixed(2)}ms`);
console.log(
` External total time: ${externalBatch.totalTime.toFixed(2)}ms`,
);
console.log(
` Time saved in batch: ${batchTimeSaved.toFixed(2)}ms (${batchImprovementRatio.toFixed(1)}x faster)`,
);
// Real-world scenarios
console.log("\n🌟 Real-World Impact:");
console.log("---------------------");
console.log(" Typical sync workflow (5 operations):");
console.log(
` - Docker approach: ~${(dockerBatch.avgTime * 5).toFixed(0)}ms`,
);
console.log(
` - External approach: ~${(externalBatch.avgTime * 5).toFixed(0)}ms`,
);
console.log(
` - Time saved: ~${((dockerBatch.avgTime - externalBatch.avgTime) * 5).toFixed(0)}ms per workflow`,
);
console.log("\n Daily usage (50 operations):");
console.log(
` - Docker approach: ~${((dockerBatch.avgTime * 50) / 1000).toFixed(1)}s`,
);
console.log(
` - External approach: ~${((externalBatch.avgTime * 50) / 1000).toFixed(1)}s`,
);
console.log(
` - Time saved: ~${(((dockerBatch.avgTime - externalBatch.avgTime) * 50) / 1000).toFixed(1)}s per day`,
);
console.log(
"\n✅ Conclusion: External MCP server provides significant performance improvements",
);
console.log(" especially for frequent operations and batch workflows.");
}
// Run the benchmark
main().catch(console.error);