@@ -344,36 +344,39 @@ async function runBenchmark(
344344 const eluMonitor = new ELUMonitor ( ) ;
345345 eluMonitor . start ( 100 ) ;
346346
347- // Run producer in separate process
348- console . log ( "\n[Benchmark] Starting producer..." ) ;
349- const producerStats = await runProducer ( {
350- postgresUrl : postgresContainer . getConnectionUri ( ) ,
351- organizationId : organization . id ,
352- projectId : project . id ,
353- environmentId : runtimeEnvironment . id ,
354- numRuns : BENCHMARK_CONFIG . NUM_RUNS ,
355- errorRate : BENCHMARK_CONFIG . ERROR_RATE ,
356- batchSize : BENCHMARK_CONFIG . PRODUCER_BATCH_SIZE ,
357- } ) ;
358-
359- console . log ( "\n[Benchmark] Waiting for replication to complete..." ) ;
360- const replicationResult = await waitForReplication (
361- clickhouse ,
362- organization . id ,
363- producerStats . created ,
364- BENCHMARK_CONFIG . REPLICATION_TIMEOUT_MS
365- ) ;
366-
367- // Stop ELU monitoring
368- const eluStats = eluMonitor . stop ( ) ;
369-
370- // Get metrics
371- const metrics = await metricsHelper . getMetrics ( ) ;
372- const metricsStats = extractMetrics ( metrics ) ;
347+ let producerStats ! : BenchmarkResult [ "producerStats" ] ;
348+ let replicationResult ! : { duration : number ; replicatedRuns : number } ;
349+ let metricsStats ! : BenchmarkResult [ "metricsStats" ] ;
350+ let eluStats ! : BenchmarkResult [ "eluStats" ] ;
351+
352+ try {
353+ // Run producer in separate process
354+ console . log ( "\n[Benchmark] Starting producer..." ) ;
355+ producerStats = await runProducer ( {
356+ postgresUrl : postgresContainer . getConnectionUri ( ) ,
357+ organizationId : organization . id ,
358+ projectId : project . id ,
359+ environmentId : runtimeEnvironment . id ,
360+ numRuns : BENCHMARK_CONFIG . NUM_RUNS ,
361+ errorRate : BENCHMARK_CONFIG . ERROR_RATE ,
362+ batchSize : BENCHMARK_CONFIG . PRODUCER_BATCH_SIZE ,
363+ } ) ;
373364
374- // Cleanup
375- await runsReplicationService . stop ( ) ;
376- await metricsHelper . shutdown ( ) ;
365+ console . log ( "\n[Benchmark] Waiting for replication to complete..." ) ;
366+ replicationResult = await waitForReplication (
367+ clickhouse ,
368+ organization . id ,
369+ producerStats . created ,
370+ BENCHMARK_CONFIG . REPLICATION_TIMEOUT_MS
371+ ) ;
372+
373+ const metrics = await metricsHelper . getMetrics ( ) ;
374+ metricsStats = extractMetrics ( metrics ) ;
375+ } finally {
376+ eluStats = eluMonitor . stop ( ) ;
377+ await runsReplicationService . stop ( ) ;
378+ await metricsHelper . shutdown ( ) ;
379+ }
377380
378381 const throughput = ( replicationResult . replicatedRuns / replicationResult . duration ) * 1000 ;
379382
0 commit comments