Files
foxhunt/services/api/src/grpc/backtesting_proxy_bench.rs
jgrusewski e50ea55064 feat: create services/api/ — unified gRPC gateway with tonic-web
Copied from api_gateway, removed REST handlers (port 8080),
added tonic-web + CORS for grpc-web browser access.
Binary renamed: api-gateway → api

Changes:
- Package name: api-gateway → api
- Deleted src/handlers/ (REST ML endpoints on port 8080)
- Added tonic-web 0.13 + tower-http CORS layer
- Server::builder().accept_http1(true) for grpc-web
- CORS_ORIGINS env var (default http://localhost:5173)
- Metrics server on port 9091 (axum) preserved
- All 95 lib tests pass, 0 clippy warnings
- Added services/api to workspace members

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 23:32:46 +01:00

42 lines
1.3 KiB
Rust

//! Backtesting proxy latency benchmark
//!
//! Measures routing overhead to confirm <10μs target
#[cfg(test)]
mod benchmarks {
use super::super::BacktestingServiceProxy;
use std::time::Instant;
#[tokio::test]
#[ignore = "Only run when backend is available"]
async fn benchmark_routing_latency() {
// This test requires a running backtesting service at localhost:50052
let proxy = BacktestingServiceProxy::new("http://localhost:50052", None, None, None)
.await
.expect("Failed to create proxy");
// Warmup
for _ in 0..100 {
let _health = proxy.health_checker.is_healthy().await;
}
// Measure
let iterations = 10000;
let start = Instant::now();
for _ in 0..iterations {
let _health = proxy.health_checker.is_healthy().await;
}
let elapsed = start.elapsed();
let avg_us = elapsed.as_micros() as f64 / iterations as f64;
println!("Average routing overhead: {:.2}μs", avg_us);
println!("Target: <10μs");
// This is just health checking, actual routing will be slightly higher
// but should still be well under 10μs
assert!(avg_us < 1.0, "Health check overhead too high: {:.2}μs", avg_us);
}
}