first commit
This commit is contained in:
133
bin/oversdb.rs
Normal file
133
bin/oversdb.rs
Normal file
@ -0,0 +1,133 @@
|
||||
use benchmark_oversdb::{StressTester, OversDBClient};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), String> {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
|
||||
if args.len() < 2 {
|
||||
println!("OversDB Stress Test & Benchmark Tool");
|
||||
println!("====================================");
|
||||
println!();
|
||||
println!("Usage: {} <test_type> [options]", args[0]);
|
||||
println!();
|
||||
println!("Test types:");
|
||||
println!(" quick - Quick test (1000 ops, 10 clients)");
|
||||
println!(" standard - Standard test (10000 ops, 50 clients)");
|
||||
println!(" intensive - Intensive test (100000 ops, 100 clients)");
|
||||
println!(" extreme - Extreme test (1000000 ops, 200 clients)");
|
||||
println!(" debug - Debug test (100 ops, 5 clients)");
|
||||
println!(" custom <ops> <clients> <value_size> - Custom parameters");
|
||||
println!();
|
||||
println!("Examples:");
|
||||
println!(" {} quick", args[0]);
|
||||
println!(" {} custom 50000 75 1024", args[0]);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let tester = StressTester::new("167.99.33.194:6601".to_string());
|
||||
|
||||
println!("🔧 Connecting to OversDB server at 167.99.33.194:6601...");
|
||||
match OversDBClient::connect("167.99.33.194:6601").await {
|
||||
Ok(_) => println!("✓ Connection successful!"),
|
||||
Err(e) => {
|
||||
println!("✗ Failed to connect: {}", e);
|
||||
println!("Make sure the OversDB server is running on 167.99.33.194:6601");
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
println!();
|
||||
|
||||
let (ops, clients, value_size) = match args[1].as_str() {
|
||||
"quick" => (1_000, 10, 256),
|
||||
"standard" => (10_000, 50, 256),
|
||||
"intensive" => (100_000, 100, 256),
|
||||
"extreme" => (1_000_000, 200, 256),
|
||||
"debug" => (100, 5, 64), // Small debug test
|
||||
"custom" => {
|
||||
if args.len() < 5 {
|
||||
return Err("Custom test requires: custom <ops> <clients> <value_size>".to_string());
|
||||
}
|
||||
let ops = args[2].parse().map_err(|_| "Invalid operations count")?;
|
||||
let clients = args[3].parse().map_err(|_| "Invalid client count")?;
|
||||
let value_size = args[4].parse().map_err(|_| "Invalid value size")?;
|
||||
(ops, clients, value_size)
|
||||
},
|
||||
_ => return Err("Unknown test type. Use: quick, standard, intensive, extreme, debug, or custom".to_string()),
|
||||
};
|
||||
|
||||
println!("🎯 Test Configuration:");
|
||||
println!(" Total operations: {}", ops);
|
||||
println!(" Concurrent clients: {}", clients);
|
||||
println!(" Value size: {} bytes", value_size);
|
||||
println!();
|
||||
|
||||
// Prepare some data for read tests
|
||||
println!("📝 Preparing test data...");
|
||||
let mut prep_client = OversDBClient::connect("167.99.33.194:6601").await?;
|
||||
let prep_value = vec![0x42u8; value_size];
|
||||
|
||||
for i in 0..10 {
|
||||
for j in 0..100 {
|
||||
let key = format!("worker{}:key{}", i, j);
|
||||
let _ = prep_client.create("benchmark", "test", key.as_bytes(), &prep_value, 0).await;
|
||||
}
|
||||
}
|
||||
println!("✓ Test data prepared");
|
||||
println!();
|
||||
|
||||
// Run benchmarks
|
||||
let mut results = Vec::new();
|
||||
|
||||
// CREATE benchmark
|
||||
match tester.benchmark_create(ops, clients, value_size).await {
|
||||
Ok(result) => {
|
||||
result.print();
|
||||
results.push(result);
|
||||
},
|
||||
Err(e) => println!("CREATE benchmark failed: {}", e),
|
||||
}
|
||||
|
||||
// READ benchmark
|
||||
match tester.benchmark_read(ops, clients).await {
|
||||
Ok(result) => {
|
||||
result.print();
|
||||
results.push(result);
|
||||
},
|
||||
Err(e) => println!("READ benchmark failed: {}", e),
|
||||
}
|
||||
|
||||
// MIXED benchmark
|
||||
match tester.benchmark_mixed(ops, clients, value_size).await {
|
||||
Ok(result) => {
|
||||
result.print();
|
||||
results.push(result);
|
||||
},
|
||||
Err(e) => println!("MIXED benchmark failed: {}", e),
|
||||
}
|
||||
|
||||
// Summary
|
||||
println!("📈 SUMMARY");
|
||||
println!("==========");
|
||||
for result in &results {
|
||||
let error_rate = if result.total_operations + result.errors > 0 {
|
||||
format!("{:.1}%", (result.errors as f64 / (result.total_operations + result.errors) as f64) * 100.0)
|
||||
} else {
|
||||
"0.0%".to_string()
|
||||
};
|
||||
|
||||
println!("{:8} | {:>10.0} ops/sec | {:>8.2}μs avg latency | {} errors ({})",
|
||||
result.operation,
|
||||
result.ops_per_second,
|
||||
result.avg_latency_us,
|
||||
result.errors,
|
||||
error_rate
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(best) = results.iter().filter(|r| r.ops_per_second > 0.0).max_by(|a, b| a.ops_per_second.partial_cmp(&b.ops_per_second).unwrap()) {
|
||||
println!();
|
||||
println!("🏆 Best performance: {} with {:.0} ops/sec", best.operation, best.ops_per_second);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user