MCPcopy Create free account
hub / github.com/erans/pgsqlite / benchmark_pooling_comparison

Function benchmark_pooling_comparison

tests/benchmark_pooling_comparison.rs:8–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6/// Compare performance with and without connection pooling
7#[tokio::test]
8async fn benchmark_pooling_comparison() {
9 println!("\n=== Connection Pooling Performance Comparison ===\n");
10
11 // Test parameters
12 let num_tasks = 8;
13 let queries_per_task = 1000;
14 let query = "SELECT id, name FROM users WHERE id = 1";
15
16 // Create and initialize database
17 let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos();
18 let db_path = format!("/tmp/benchmark_pooling_{timestamp}.db");
19 let db_handler = Arc::new(DbHandler::new(&db_path).unwrap());
20
21 // Initialize test data
22 db_handler.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)").await.unwrap();
23 for i in 1..=100 {
24 db_handler.execute(&format!("INSERT INTO users (id, name) VALUES ({i}, 'User{i}')")).await.unwrap();
25 }
26
27 // Benchmark without pooling (current implementation)
28 println!("Testing WITHOUT connection pooling:");
29 let start = Instant::now();
30 let mut tasks = JoinSet::new();
31
32 for task_id in 0..num_tasks {
33 let db = db_handler.clone();
34 let query_str = query.to_string();
35
36 tasks.spawn(async move {
37 let task_start = Instant::now();
38 for _ in 0..queries_per_task {
39 db.query(&query_str).await.unwrap();
40 }
41 let elapsed = task_start.elapsed();
42 (task_id, elapsed)
43 });
44 }
45
46 let mut total_queries = 0;
47 while let Some(result) = tasks.join_next().await {
48 let (task_id, elapsed) = result.unwrap();
49 let qps = queries_per_task as f64 / elapsed.as_secs_f64();
50 println!(" Task {}: {} queries in {:.3}s ({:.0} queries/sec)",
51 task_id, queries_per_task, elapsed.as_secs_f64(), qps);
52 total_queries += queries_per_task;
53 }
54
55 let total_elapsed = start.elapsed();
56 let total_qps = total_queries as f64 / total_elapsed.as_secs_f64();
57 println!(" Total: {} queries in {:.3}s ({:.0} queries/sec)\n",
58 total_queries, total_elapsed.as_secs_f64(), total_qps);
59
60 // TODO: Benchmark with pooling enabled
61 // This would require setting PGSQLITE_USE_POOLING=true and using
62 // the handle_test_connection_with_pool function with actual client connections
63 println!("Testing WITH connection pooling:");
64 println!(" (Not yet implemented - requires QueryExecutor integration)");
65 println!("\nNote: Connection pooling infrastructure is complete but not yet integrated");

Callers

nothing calls this directly

Calls 3

executeMethod · 0.45
cloneMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected