|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Advanced batch processor with dynamic sizing and back-pressure handling. More...
#include <batch_processor.h>

Classes | |
| struct | batch_entry |
| Batch entry structure. More... | |
| struct | config |
| Configuration for batch processor. More... | |
| struct | processing_stats |
| Processing statistics. More... | |
Public Member Functions | |
| batch_processor (log_writer_ptr writer, const config &cfg=config{}) | |
| Constructor. | |
| ~batch_processor () | |
| Destructor. | |
| bool | start () |
| Start the batch processor. | |
| void | stop (bool flush_remaining=true) |
| Stop the batch processor. | |
| bool | add_entry (batch_entry &&entry) |
| Add entry to the batch queue. | |
| bool | add_entry (const batch_entry &entry) |
| Add entry to the batch queue (copy version) | |
| void | flush () |
| Force flush current batch. | |
| bool | is_healthy () const |
| Check if processor is healthy. | |
| const processing_stats & | get_stats () const |
| Get current processing statistics. | |
| void | reset_stats () |
| Reset statistics. | |
| size_t | get_queue_size () const |
| Get current queue size. | |
| size_t | get_current_batch_size () const |
| Get current batch size setting. | |
Private Member Functions | |
| void | process_loop_iteration () |
| Single iteration of processing loop. | |
| size_t | process_batch (std::vector< batch_entry > &batch) |
| Process current batch. | |
| size_t | collect_entries (std::vector< batch_entry > &batch, size_t max_entries, std::chrono::steady_clock::time_point deadline) |
| Collect entries for batch processing. | |
| void | adjust_batch_size () |
| Adjust batch size based on performance metrics. | |
| bool | handle_back_pressure () |
| Handle back-pressure conditions. | |
| bool | should_flush_by_time (std::chrono::steady_clock::time_point last_flush_time) const |
| Check if batch should be flushed based on time. | |
| void | update_stats (size_t batch_size, std::chrono::nanoseconds processing_time, const std::string &flush_reason) |
| Update processing statistics. | |
Private Attributes | |
| config | config_ |
| log_writer_ptr | writer_ |
| std::unique_ptr< lockfree_spsc_queue< batch_entry, queue_size > > | queue_ |
| std::unique_ptr< batch_processing_jthread_worker > | processing_worker_ |
| std::atomic< bool > | running_ {false} |
| std::atomic< bool > | should_stop_ {false} |
| std::mutex | notify_mutex_ |
| std::condition_variable | notify_cv_ |
| std::atomic< size_t > | current_batch_size_ |
| std::atomic< std::chrono::milliseconds > | current_wait_time_ |
| processing_stats | stats_ |
| std::atomic< double > | recent_processing_time_ms_ {0.0} |
| std::atomic< size_t > | recent_queue_size_ {0} |
| std::chrono::steady_clock::time_point | last_adjustment_time_ |
Static Private Attributes | |
| static constexpr size_t | queue_size = 8192 |
Advanced batch processor with dynamic sizing and back-pressure handling.
Definition at line 36 of file batch_processor.h.
|
explicit |
Constructor.
| writer | Target writer for batch output |
| cfg | Configuration |
Definition at line 119 of file batch_processor.cpp.
References kcenon::logger::async::batch_processor::config::initial_batch_size, kcenon::logger::async::batch_processor::config::max_batch_size, kcenon::logger::async::batch_processor::config::min_batch_size, and writer_.
| kcenon::logger::async::batch_processor::~batch_processor | ( | ) |
Destructor.
Definition at line 141 of file batch_processor.cpp.
References stop().

| bool kcenon::logger::async::batch_processor::add_entry | ( | batch_entry && | entry | ) |
Add entry to the batch queue.
| entry | Log entry to add |
Definition at line 193 of file batch_processor.cpp.
References kcenon::logger::async::batch_processor::processing_stats::dropped_entries, notify_cv_, queue_, running_, and stats_.
Referenced by add_entry().

| bool kcenon::logger::async::batch_processor::add_entry | ( | const batch_entry & | entry | ) |
Add entry to the batch queue (copy version)
| entry | Log entry to add |
Definition at line 209 of file batch_processor.cpp.
References add_entry().

|
private |
Adjust batch size based on performance metrics.
Definition at line 336 of file batch_processor.cpp.
References config_, current_batch_size_, kcenon::logger::async::batch_processor::processing_stats::dynamic_size_adjustments, get_queue_size(), kcenon::logger::async::batch_processor::config::max_batch_size, kcenon::logger::async::batch_processor::config::min_batch_size, queue_size, recent_processing_time_ms_, kcenon::logger::async::batch_processor::config::size_decrease_factor, kcenon::logger::async::batch_processor::config::size_increase_factor, and stats_.
Referenced by process_loop_iteration().


|
private |
Collect entries for batch processing.
| batch | Vector to fill with entries |
| max_entries | Maximum entries to collect |
| deadline | Time deadline for collection |
Definition at line 279 of file batch_processor.cpp.
References notify_cv_, notify_mutex_, queue_, and should_stop_.
Referenced by process_loop_iteration().

| void kcenon::logger::async::batch_processor::flush | ( | ) |
Force flush current batch.
Definition at line 213 of file batch_processor.cpp.
|
inline |
Get current batch size setting.
Definition at line 190 of file batch_processor.h.
References current_batch_size_.
| size_t kcenon::logger::async::batch_processor::get_queue_size | ( | ) | const |
Get current queue size.
Definition at line 223 of file batch_processor.cpp.
References queue_.
Referenced by adjust_batch_size(), handle_back_pressure(), and update_stats().

|
inline |
Get current processing statistics.
Definition at line 173 of file batch_processor.h.
References stats_.
|
private |
Handle back-pressure conditions.
Definition at line 360 of file batch_processor.cpp.
References kcenon::logger::async::batch_processor::config::back_pressure_delay, kcenon::logger::async::batch_processor::processing_stats::back_pressure_events, kcenon::logger::async::batch_processor::config::back_pressure_threshold, config_, get_queue_size(), queue_size, and stats_.
Referenced by process_loop_iteration().


| bool kcenon::logger::async::batch_processor::is_healthy | ( | ) | const |
|
private |
Process current batch.
| batch | Vector of entries to process |
Definition at line 310 of file batch_processor.cpp.
References stats_, kcenon::logger::async::batch_processor::processing_stats::total_batches, kcenon::logger::async::batch_processor::processing_stats::total_entries, and writer_.
Referenced by process_loop_iteration(), and stop().

|
private |
Single iteration of processing loop.
Definition at line 227 of file batch_processor.cpp.
References adjust_batch_size(), collect_entries(), config_, current_batch_size_, current_wait_time_, kcenon::logger::async::batch_processor::config::enable_back_pressure, kcenon::logger::async::batch_processor::config::enable_dynamic_sizing, kcenon::logger::async::batch_processor::processing_stats::flush_by_size, kcenon::logger::async::batch_processor::processing_stats::flush_by_time, handle_back_pressure(), process_batch(), should_flush_by_time(), stats_, and update_stats().
Referenced by start().


|
inline |
Reset statistics.
Definition at line 178 of file batch_processor.h.
References kcenon::logger::async::batch_processor::processing_stats::reset(), and stats_.

|
private |
Check if batch should be flushed based on time.
| last_flush_time | Time of last flush |
Definition at line 375 of file batch_processor.cpp.
References current_wait_time_.
Referenced by process_loop_iteration().

| bool kcenon::logger::async::batch_processor::start | ( | ) |
Start the batch processor.
Definition at line 145 of file batch_processor.cpp.
References notify_cv_, notify_mutex_, process_loop_iteration(), processing_worker_, running_, and should_stop_.

| void kcenon::logger::async::batch_processor::stop | ( | bool | flush_remaining = true | ) |
Stop the batch processor.
| flush_remaining | Whether to flush remaining entries |
Definition at line 158 of file batch_processor.cpp.
References notify_cv_, process_batch(), processing_worker_, queue_, queue_size, running_, should_stop_, and writer_.
Referenced by ~batch_processor().


|
private |
Update processing statistics.
| batch_size | Size of processed batch |
| processing_time | Time taken to process |
| flush_reason | Reason for flush |
Definition at line 383 of file batch_processor.cpp.
References kcenon::logger::async::batch_processor::processing_stats::average_batch_size, kcenon::logger::async::batch_processor::processing_stats::average_processing_time_ms, get_queue_size(), recent_processing_time_ms_, recent_queue_size_, stats_, kcenon::logger::async::batch_processor::processing_stats::total_batches, and kcenon::logger::async::batch_processor::processing_stats::total_entries.
Referenced by process_loop_iteration().


|
private |
Definition at line 247 of file batch_processor.h.
Referenced by adjust_batch_size(), handle_back_pressure(), and process_loop_iteration().
|
private |
Definition at line 266 of file batch_processor.h.
Referenced by adjust_batch_size(), get_current_batch_size(), and process_loop_iteration().
|
private |
Definition at line 267 of file batch_processor.h.
Referenced by process_loop_iteration(), and should_flush_by_time().
|
private |
Definition at line 275 of file batch_processor.h.
|
private |
Definition at line 263 of file batch_processor.h.
Referenced by add_entry(), collect_entries(), start(), and stop().
|
private |
Definition at line 262 of file batch_processor.h.
Referenced by collect_entries(), and start().
|
private |
Definition at line 257 of file batch_processor.h.
|
private |
Definition at line 254 of file batch_processor.h.
Referenced by add_entry(), collect_entries(), get_queue_size(), and stop().
|
staticconstexprprivate |
Definition at line 253 of file batch_processor.h.
Referenced by adjust_batch_size(), handle_back_pressure(), and stop().
|
private |
Definition at line 273 of file batch_processor.h.
Referenced by adjust_batch_size(), and update_stats().
|
private |
|
private |
Definition at line 258 of file batch_processor.h.
Referenced by add_entry(), is_healthy(), start(), and stop().
|
private |
Definition at line 259 of file batch_processor.h.
Referenced by collect_entries(), start(), and stop().
|
mutableprivate |
Definition at line 270 of file batch_processor.h.
Referenced by add_entry(), adjust_batch_size(), get_stats(), handle_back_pressure(), process_batch(), process_loop_iteration(), reset_stats(), and update_stats().
|
private |
Definition at line 250 of file batch_processor.h.
Referenced by batch_processor(), is_healthy(), process_batch(), and stop().