Skip to content

Commit 87e2a97

Browse files
Copilot0xrinegade
andcommitted
Optimize benchmark performance - reduce sample counts and measurement times for CI compatibility
Co-authored-by: 0xrinegade <[email protected]>
1 parent 8d01e9d commit 87e2a97

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

benches/http_api_bench.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,18 @@ fn bench_mcp_initialization(c: &mut Criterion) {
6161
}
6262
});
6363

64-
c.bench_function("mcp_initialize", |b| {
64+
let mut group = c.benchmark_group("mcp_protocol");
65+
group.sample_size(15);
66+
group.measurement_time(Duration::from_secs(15));
67+
68+
group.bench_function("initialize", |b| {
6569
b.to_async(&rt).iter(|| async {
6670
let result = make_benchmark_request(black_box(initialize_request.clone()), port).await;
6771
black_box(result)
6872
})
6973
});
74+
75+
group.finish();
7076
}
7177

7278
/// Benchmark tools list retrieval
@@ -99,12 +105,18 @@ fn bench_tools_list(c: &mut Criterion) {
99105
"method": "tools/list"
100106
});
101107

102-
c.bench_function("tools_list", |b| {
108+
let mut group = c.benchmark_group("mcp_tools");
109+
group.sample_size(15);
110+
group.measurement_time(Duration::from_secs(15));
111+
112+
group.bench_function("list", |b| {
103113
b.to_async(&rt).iter(|| async {
104114
let result = make_benchmark_request(black_box(tools_request.clone()), port).await;
105115
black_box(result)
106116
})
107117
});
118+
119+
group.finish();
108120
}
109121

110122
/// Benchmark different RPC tool calls
@@ -132,6 +144,8 @@ fn bench_rpc_tool_calls(c: &mut Criterion) {
132144
});
133145

134146
let mut group = c.benchmark_group("rpc_tool_calls");
147+
group.sample_size(10);
148+
group.measurement_time(Duration::from_secs(20));
135149

136150
// Benchmark simple methods
137151
let simple_methods = vec![
@@ -214,6 +228,8 @@ fn bench_concurrent_requests(c: &mut Criterion) {
214228
});
215229

216230
let mut group = c.benchmark_group("concurrent_requests");
231+
group.sample_size(10);
232+
group.measurement_time(Duration::from_secs(15));
217233

218234
for concurrency in [1, 5, 10, 20].iter() {
219235
group.bench_with_input(BenchmarkId::new("getHealth", concurrency), concurrency, |b, &concurrency| {
@@ -254,7 +270,11 @@ fn bench_health_endpoint(c: &mut Criterion) {
254270
setup_benchmark_server().await.expect("Failed to setup server")
255271
});
256272

257-
c.bench_function("health_endpoint", |b| {
273+
let mut group = c.benchmark_group("endpoints");
274+
group.sample_size(15);
275+
group.measurement_time(Duration::from_secs(10));
276+
277+
group.bench_function("health", |b| {
258278
b.to_async(&rt).iter(|| async {
259279
let client = reqwest::Client::new();
260280
let response = client
@@ -265,6 +285,8 @@ fn bench_health_endpoint(c: &mut Criterion) {
265285
black_box(response.text().await)
266286
})
267287
});
288+
289+
group.finish();
268290
}
269291

270292
/// Benchmark metrics endpoint
@@ -275,7 +297,11 @@ fn bench_metrics_endpoint(c: &mut Criterion) {
275297
setup_benchmark_server().await.expect("Failed to setup server")
276298
});
277299

278-
c.bench_function("metrics_endpoint", |b| {
300+
let mut group = c.benchmark_group("endpoints");
301+
group.sample_size(15);
302+
group.measurement_time(Duration::from_secs(10));
303+
304+
group.bench_function("metrics", |b| {
279305
b.to_async(&rt).iter(|| async {
280306
let client = reqwest::Client::new();
281307
let response = client
@@ -286,6 +312,8 @@ fn bench_metrics_endpoint(c: &mut Criterion) {
286312
black_box(response.text().await)
287313
})
288314
});
315+
316+
group.finish();
289317
}
290318

291319
criterion_group!(

benches/rpc_methods_bench.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ fn bench_system_methods(c: &mut Criterion) {
5858
});
5959

6060
let mut group = c.benchmark_group("system_methods");
61+
group.sample_size(10);
62+
group.measurement_time(Duration::from_secs(20));
6163

6264
let system_methods = vec![
6365
"getHealth",
@@ -119,6 +121,8 @@ fn bench_account_methods(c: &mut Criterion) {
119121
});
120122

121123
let mut group = c.benchmark_group("account_methods");
124+
group.sample_size(10);
125+
group.measurement_time(Duration::from_secs(20));
122126

123127
let test_pubkey = "11111111111111111111111111111112"; // System program
124128

@@ -178,6 +182,8 @@ fn bench_block_transaction_methods(c: &mut Criterion) {
178182
});
179183

180184
let mut group = c.benchmark_group("block_transaction_methods");
185+
group.sample_size(10);
186+
group.measurement_time(Duration::from_secs(20));
181187

182188
let block_tx_methods = vec![
183189
("getLatestBlockhash", json!({})),
@@ -236,6 +242,8 @@ fn bench_token_methods(c: &mut Criterion) {
236242
});
237243

238244
let mut group = c.benchmark_group("token_methods");
245+
group.sample_size(10);
246+
group.measurement_time(Duration::from_secs(20));
239247

240248
let token_program = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"; // SPL Token program
241249

@@ -293,6 +301,8 @@ fn bench_error_handling(c: &mut Criterion) {
293301
});
294302

295303
let mut group = c.benchmark_group("error_handling");
304+
group.sample_size(10);
305+
group.measurement_time(Duration::from_secs(15));
296306

297307
// Test invalid method names
298308
let invalid_method_request = json!({

benches/websocket_bench.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ static WS_BENCHMARK_SERVER: OnceLock<u16> = OnceLock::new();
1414
async fn setup_shared_websocket_benchmark_server() -> Result<(tokio::task::JoinHandle<()>, u16), Box<dyn std::error::Error + Send + Sync>> {
1515
let port = 9003;
1616

17-
let mut config = Config::load().map_err(|e| format!("Failed to load config: {e}"))?;
18-
// Use mock RPC endpoint for benchmarks
19-
config.rpc_url = "http://localhost:8899".to_string();
20-
config.timeouts.websocket_connection_seconds = 5;
21-
config.timeouts.websocket_message_seconds = 5;
17+
let config = Config::load().map_err(|e| format!("Failed to load config: {e}"))?;
2218

2319
let config_arc = Arc::new(config);
2420

@@ -54,12 +50,18 @@ fn bench_websocket_connection(c: &mut Criterion) {
5450
let rt = Runtime::new().unwrap();
5551
let port = get_websocket_benchmark_server_port();
5652

57-
c.bench_function("websocket_connection", |b| {
53+
let mut group = c.benchmark_group("websocket_connection");
54+
group.sample_size(15);
55+
group.measurement_time(Duration::from_secs(10));
56+
57+
group.bench_function("establish", |b| {
5858
b.to_async(&rt).iter(|| async {
5959
let result = connect_websocket(port).await;
6060
black_box(result)
6161
})
6262
});
63+
64+
group.finish();
6365
}
6466

6567
/// Benchmark basic WebSocket subscription (simplified)
@@ -68,6 +70,8 @@ fn bench_websocket_subscriptions(c: &mut Criterion) {
6870
let port = get_websocket_benchmark_server_port();
6971

7072
let mut group = c.benchmark_group("websocket_subscriptions");
73+
group.sample_size(10);
74+
group.measurement_time(Duration::from_secs(15));
7175

7276
// Only test one simple subscription method to avoid timeouts
7377
let subscription_methods = vec![
@@ -110,6 +114,8 @@ fn bench_websocket_error_handling(c: &mut Criterion) {
110114
let port = get_websocket_benchmark_server_port();
111115

112116
let mut group = c.benchmark_group("websocket_error_handling");
117+
group.sample_size(10);
118+
group.measurement_time(Duration::from_secs(10));
113119

114120
// Test invalid method
115121
let invalid_method_request = json!({

0 commit comments

Comments
 (0)