@@ -114,6 +114,7 @@ void InsertDataAction::execute() {
114114 const size_t consumer_thread_count = config_.insert_threads ;
115115 const size_t queue_capacity = config_.queue_capacity ;
116116 const double queue_warmup_ratio = config_.queue_warmup_ratio ;
117+ const bool shared_queue = config_.shared_queue ;
117118 const size_t per_request_rows = config_.schema .generation .per_batch_rows ;
118119 const size_t interlace_rows = config_.schema .generation .interlace_mode .rows ;
119120 const int64_t per_table_rows = config_.schema .generation .per_table_rows ;
@@ -133,7 +134,7 @@ void InsertDataAction::execute() {
133134 MemoryPool pool (block_count, max_tables_per_block, max_rows_per_table, col_instances_);
134135
135136 // Create data pipeline
136- DataPipeline<FormatResult> pipeline (block_count );
137+ DataPipeline<FormatResult> pipeline (shared_queue, producer_thread_count, consumer_thread_count, queue_capacity );
137138 Barrier sync_barrier (consumer_thread_count + 1 );
138139
139140 // Start consumer threads
@@ -189,8 +190,12 @@ void InsertDataAction::execute() {
189190
190191 producer_threads.emplace_back ([this , i, &split_names, &pipeline, data_manager, &active_producers, &producer_finished] {
191192 try {
192- set_thread_affinity (i, false , " Producer" );
193- set_realtime_priority ();
193+ if (config_.thread_affinity ) {
194+ set_thread_affinity (i, false , " Producer" );
195+ }
196+ if (config_.thread_realtime ) {
197+ set_realtime_priority ();
198+ }
194199 producer_thread_function (i, split_names[i], pipeline, data_manager);
195200 producer_finished[i].store (true );
196201 } catch (const std::exception& e) {
@@ -201,7 +206,8 @@ void InsertDataAction::execute() {
201206 }
202207
203208 (void )ProcessUtils::get_cpu_usage_percent ();
204- std::this_thread::sleep_for (std::chrono::seconds (2 ));
209+ int64_t wait_seconds = std::min (static_cast <int64_t >(5 ), static_cast <int64_t >(producer_thread_count));
210+ std::this_thread::sleep_for (std::chrono::seconds (wait_seconds));
205211
206212 while (true ) {
207213 size_t total_queued = pipeline.total_queued ();
@@ -270,7 +276,7 @@ void InsertDataAction::execute() {
270276 << " Queue: " << std::setw (3 ) << std::setfill (' ' ) << pipeline.total_queued () << " items | "
271277 << " CPU Usage: " << std::setw (7 ) << std::fixed << std::setprecision (2 ) << ProcessUtils::get_cpu_usage_percent () << " % | "
272278 << " Memory Usage: " << ProcessUtils::get_memory_usage_human_readable () << " | "
273- << " Thread Count: " << std::setw (3 ) << std::setfill (' ' ) << ProcessUtils::get_thread_count () << " \n " ;
279+ << " Thread Count: " << std::setw (3 ) << std::setfill (' ' ) << ProcessUtils::get_thread_count () << std::endl ;
274280 }
275281
276282 std::cout << " All producer threads have finished." << std::endl;
@@ -294,7 +300,7 @@ void InsertDataAction::execute() {
294300 << " Processing Rate: " << std::setw (6 ) << std::fixed << std::setprecision (2 ) << process_rate << " items/s | "
295301 << " CPU Usage: " << std::setw (7 ) << std::fixed << std::setprecision (2 ) << ProcessUtils::get_cpu_usage_percent () << " % | "
296302 << " Memory Usage: " << ProcessUtils::get_memory_usage_human_readable () << " | "
297- << " Thread Count: " << std::setw (3 ) << std::setfill (' ' ) << ProcessUtils::get_thread_count () << " \n " ;
303+ << " Thread Count: " << std::setw (3 ) << std::setfill (' ' ) << ProcessUtils::get_thread_count () << std::endl ;
298304
299305 last_queue_size = current_queue_size;
300306 last_check_time = current_time;
@@ -360,7 +366,7 @@ void InsertDataAction::execute() {
360366 double avg_wait_time = total_wait_time / consumer_thread_count; // average per thread
361367
362368 // Calculate total duration (seconds)
363- const auto total_duration = std::chrono::duration<double >(max_end_write_time - min_start_write_time).count ();
369+ const auto total_duration = std::chrono::duration<double >(max_end_write_time - min_start_write_time).count () - avg_wait_time ;
364370
365371 // Calculate average insert rate
366372 const double avg_rows_per_sec = total_duration > 0 ?
@@ -391,7 +397,7 @@ void InsertDataAction::execute() {
391397 // Print performance statistics
392398 double thread_latency = global_write_metrics.get_sum () / consumer_thread_count / 1000 ;
393399 double effective_ratio = thread_latency / total_duration * 100.0 ;
394- double framework_ratio = (1 - ( thread_latency + avg_wait_time) / total_duration) * 100.0 ;
400+ double framework_ratio = (1 - thread_latency / total_duration) * 100.0 ;
395401 TimeIntervalStrategy time_strategy (config_.time_interval , config_.timestamp_precision );
396402 std::cout << " \n =============================================== Insert Latency & Efficiency Metrics ==========================================\n "
397403 << " Total Operations: " << global_write_metrics.get_samples ().size () << " \n "
@@ -485,7 +491,7 @@ void InsertDataAction::producer_thread_function(
485491 // }, formatted_result);
486492
487493 // Push data to pipeline
488- pipeline.push_data (std::move (formatted_result));
494+ pipeline.push_data (producer_id, std::move (formatted_result));
489495
490496 // std::cout << "Producer " << producer_id << ": Pushed batch for table(s): "
491497 // << batch_size << ", total rows: " << total_rows
@@ -531,7 +537,7 @@ void InsertDataAction::consumer_thread_function(
531537 // Data processing loop
532538 (void )running;
533539 while (true ) {
534- auto result = pipeline.fetch_data ();
540+ auto result = pipeline.fetch_data (consumer_id );
535541
536542 switch (result.status ) {
537543 case DataPipeline<FormatResult>::Status::Success:
0 commit comments