Skip to content

Commit

Permalink
update/revert LoggerBase.h
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Jun 2, 2024
1 parent c27bcf6 commit 196c6d4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 37 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
## v4.3.0

- Refactored `BacktraceStorage` to simplify the code.
- Improved `LoggerBase` memory layout by reorganizing class members.
- Fixed multiple definitions of `on_alarm` in `SignalHandler.h`
- Fixed a bug in the backend thread where `flush()` and `run_periodic_tasks()` were skipped for certain sinks. All sinks
are now correctly processed.
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ The following message is logged 100'000 times for each thread:

| Library | 50th | 75th | 90th | 95th | 99th | 99.9th |
|---------------------------------------------------------------------|:----:|:----:|:----:|:----:|:----:|:------:|
| [Quill v4.2 Bounded Dropping Queue](http://github.com/odygrd/quill) | 6 | 7 | 8 | 8 | 9 | 10 |
| [Quill v4.2 Unbounded Queue](http://github.com/odygrd/quill) | 8 | 8 | 9 | 9 | 10 | 13 |
| [Quill v4.3 Bounded Dropping Queue](http://github.com/odygrd/quill) | 6 | 7 | 8 | 8 | 9 | 10 |
| [Quill v4.3 Unbounded Queue](http://github.com/odygrd/quill) | 8 | 8 | 9 | 9 | 10 | 13 |
| [Quill v3.8 Unbounded Queue](http://github.com/odygrd/quill) | 8 | 8 | 9 | 9 | 10 | 13 |
| [fmtlog](http://github.com/MengRao/fmtlog) | 8 | 8 | 9 | 9 | 10 | 13 |
| [PlatformLab NanoLog](http://github.com/PlatformLab/NanoLog) | 11 | 12 | 13 | 14 | 15 | 20 |
Expand All @@ -203,10 +203,10 @@ The following message is logged 100'000 times for each thread:

| Library | 50th | 75th | 90th | 95th | 99th | 99.9th |
|---------------------------------------------------------------------|:----:|:----:|:----:|:----:|:----:|:------:|
| [Quill v4.2 Bounded Dropping Queue](http://github.com/odygrd/quill) | 7 | 8 | 9 | 9 | 10 | 12 |
| [Quill v4.3 Bounded Dropping Queue](http://github.com/odygrd/quill) | 7 | 8 | 9 | 9 | 10 | 12 |
| [fmtlog](http://github.com/MengRao/fmtlog) | 8 | 8 | 9 | 9 | 11 | 13 |
| [Quill v3.8 Unbounded Queue](http://github.com/odygrd/quill) | 8 | 9 | 10 | 10 | 11 | 13 |
| [Quill v4.2 Unbounded Queue](http://github.com/odygrd/quill) | 9 | 9 | 10 | 11 | 12 | 15 |
| [Quill v4.3 Unbounded Queue](http://github.com/odygrd/quill) | 9 | 9 | 10 | 11 | 12 | 15 |
| [PlatformLab NanoLog](http://github.com/PlatformLab/NanoLog) | 12 | 13 | 13 | 14 | 15 | 19 |
| [MS BinLog](http://github.com/Morgan-Stanley/binlog) | 21 | 21 | 22 | 22 | 29 | 62 |
| [Reckless](http://github.com/mattiasflodin/reckless) | 42 | 46 | 47 | 48 | 54 | 78 |
Expand All @@ -228,10 +228,10 @@ of `std::string`.
| Library | 50th | 75th | 90th | 95th | 99th | 99.9th |
|---------------------------------------------------------------------|:----:|:----:|:----:|:----:|:----:|:------:|
| [Quill v3.8 Unbounded Queue](http://github.com/odygrd/quill) | 10 | 12 | 13 | 13 | 14 | 16 |
| [Quill v4.2 Bounded Dropping Queue](http://github.com/odygrd/quill) | 11 | 12 | 13 | 14 | 15 | 17 |
| [Quill v4.3 Bounded Dropping Queue](http://github.com/odygrd/quill) | 11 | 12 | 13 | 14 | 15 | 17 |
| [fmtlog](http://github.com/MengRao/fmtlog) | 11 | 12 | 13 | 14 | 15 | 17 |
| [Quill v4.3 Unbounded Queue](http://github.com/odygrd/quill) | 13 | 14 | 15 | 15 | 17 | 19 |
| [PlatformLab NanoLog](http://github.com/PlatformLab/NanoLog) | 13 | 14 | 15 | 15 | 17 | 19 |
| [Quill v4.2 Unbounded Queue](http://github.com/odygrd/quill) | 13 | 14 | 16 | 16 | 17 | 21 |
| [MS BinLog](http://github.com/Morgan-Stanley/binlog) | 22 | 23 | 23 | 25 | 30 | 59 |
| [Iyengar NanoLog](http://github.com/Iyengar111/NanoLog) | 52 | 55 | 64 | 83 | 114 | 160 |
| [Reckless](http://github.com/mattiasflodin/reckless) | 102 | 122 | 134 | 137 | 143 | 153 |
Expand All @@ -242,11 +242,11 @@ of `std::string`.

| Library | 50th | 75th | 90th | 95th | 99th | 99.9th |
|---------------------------------------------------------------------|:----:|:----:|:----:|:----:|:----:|:------:|
| [Quill v4.2 Bounded Dropping Queue](http://github.com/odygrd/quill) | 11 | 12 | 13 | 15 | 16 | 18 |
| [Quill v4.3 Bounded Dropping Queue](http://github.com/odygrd/quill) | 11 | 12 | 13 | 15 | 16 | 18 |
| [fmtlog](http://github.com/MengRao/fmtlog) | 11 | 12 | 13 | 15 | 16 | 18 |
| [Quill v3.8 Unbounded Queue](http://github.com/odygrd/quill) | 12 | 13 | 14 | 15 | 16 | 19 |
| [PlatformLab NanoLog](http://github.com/PlatformLab/NanoLog) | 13 | 15 | 15 | 16 | 17 | 20 |
| [Quill v4.2 Unbounded Queue](http://github.com/odygrd/quill) | 14 | 16 | 17 | 18 | 19 | 22 |
| [Quill v4.3 Unbounded Queue](http://github.com/odygrd/quill) | 14 | 15 | 16 | 17 | 18 | 21 |
| [MS BinLog](http://github.com/Morgan-Stanley/binlog) | 23 | 24 | 24 | 25 | 31 | 62 |
| [Iyengar NanoLog](http://github.com/Iyengar111/NanoLog) | 53 | 60 | 92 | 121 | 149 | 212 |
| [Reckless](http://github.com/mattiasflodin/reckless) | 101 | 121 | 133 | 136 | 143 | 160 |
Expand All @@ -266,8 +266,8 @@ The strings used in the log message are over 35 characters to prevent the short

| Library | 50th | 75th | 90th | 95th | 99th | 99.9th |
|---------------------------------------------------------------------|:----:|:----:|:----:|:----:|:----:|:------:|
| [Quill v4.2 Bounded Dropping Queue](http://github.com/odygrd/quill) | 52 | 54 | 56 | 58 | 60 | 71 |
| [Quill v4.2 Unbounded Queue](http://github.com/odygrd/quill) | 53 | 56 | 57 | 59 | 61 | 64 |
| [Quill v4.3 Bounded Dropping Queue](http://github.com/odygrd/quill) | 52 | 54 | 56 | 58 | 60 | 71 |
| [Quill v4.3 Unbounded Queue](http://github.com/odygrd/quill) | 53 | 56 | 57 | 59 | 61 | 64 |
| [MS BinLog](http://github.com/Morgan-Stanley/binlog) | 66 | 70 | 79 | 81 | 84 | 91 |
| [Quill v3.8 Unbounded Queue](http://github.com/odygrd/quill) | 632 | 651 | 676 | 698 | 737 | 1049 |
| [fmtlog](http://github.com/MengRao/fmtlog) | 724 | 752 | 776 | 789 | 814 | 857 |
Expand All @@ -277,9 +277,9 @@ The strings used in the log message are over 35 characters to prevent the short

| Library | 50th | 75th | 90th | 95th | 99th | 99.9th |
|---------------------------------------------------------------------|:----:|:----:|:----:|:----:|:----:|:------:|
| [Quill v4.2 Bounded Dropping Queue](http://github.com/odygrd/quill) | 52 | 55 | 57 | 59 | 62 | 77 |
| [Quill v4.3 Bounded Dropping Queue](http://github.com/odygrd/quill) | 52 | 55 | 57 | 59 | 62 | 77 |
| [MS BinLog](http://github.com/Morgan-Stanley/binlog) | 70 | 74 | 83 | 85 | 88 | 102 |
| [Quill v4.2 Unbounded Queue](http://github.com/odygrd/quill) | 86 | 94 | 103 | 110 | 122 | 138 |
| [Quill v4.3 Unbounded Queue](http://github.com/odygrd/quill) | 86 | 94 | 103 | 110 | 122 | 138 |
| [Quill v3.8 Unbounded Queue](http://github.com/odygrd/quill) | 674 | 694 | 736 | 762 | 805 | 884 |
| [fmtlog](http://github.com/MengRao/fmtlog) | 789 | 813 | 833 | 845 | 872 | 908 |
| [spdlog](http://github.com/gabime/spdlog) | 6500 | 6596 | 6724 | 6848 | 7560 | 9036 |
Expand All @@ -301,7 +301,7 @@ The maximum throughput is measured by determining the maximum number of log mess
write to the log file per second.

When measured on the same system as the latency benchmarks mentioned above the average throughput of the backend
logging thread is `4.56 million msgs/sec`
logging thread when formatting a log message consisting of an int and a double is ~`4.40 million msgs/sec`

While the primary focus of the library is not on throughput, it does provide efficient handling of log messages across
multiple threads. The backend logging thread, responsible for formatting and ordering log messages from hot threads,
Expand Down
39 changes: 16 additions & 23 deletions quill/include/quill/core/LoggerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class LoggerBase
LoggerBase(std::string logger_name, std::vector<std::shared_ptr<Sink>> sinks,
std::string format_pattern, std::string time_pattern, Timezone timezone,
ClockSourceType clock_source, UserClockSource* user_clock)
: clock_source(clock_source),
user_clock(user_clock),
: format_pattern(static_cast<std::string&&>(format_pattern)),
time_pattern(static_cast<std::string&&>(time_pattern)),
logger_name(static_cast<std::string&&>(logger_name)),
user_clock(user_clock),
timezone(timezone),
format_pattern(static_cast<std::string&&>(format_pattern)),
time_pattern(static_cast<std::string&&>(time_pattern))
clock_source(clock_source)
{
#ifndef NDEBUG
for (auto const& sink : sinks)
Expand Down Expand Up @@ -124,25 +124,18 @@ class LoggerBase
protected:
friend class detail::BackendWorker;

/** Accessed by Frontend frequently - hot **/
std::atomic<LogLevel> log_level{LogLevel::Info}; /* Accessed by frontend only */
ClockSourceType clock_source; /* Accessed by the frontend, accessed but not modified by the frontend AND backend */
UserClockSource* user_clock{nullptr}; /* A non owned pointer to a custom timestamp clock, valid only when provided. accessed by frontend only */
std::atomic<LogLevel> backtrace_flush_level{LogLevel::None}; /** Modified by the frontend, accessed but not modified by the backend */

/** Backend only variables - Modified by the Backend **/
alignas(CACHE_LINE_ALIGNED) std::shared_ptr<PatternFormatter> pattern_formatter; /* The backend thread will construct this, we never access it on the frontend */
std::shared_ptr<PatternFormatter> pattern_formatter; /* The backend thread will set this once, we never access it on the frontend */
std::shared_ptr<BacktraceStorage> backtrace_storage; /* The backend thread will construct this, we never access it on the frontend */

/** Frequent Backend access - Rare Frontend access **/
std::string logger_name; /* Set by the frontend, accessed rarely by the frontend */
std::vector<std::shared_ptr<Sink>> sinks; /* Set by the frontend */
std::atomic<bool> valid{true}; /* Modified by the frontend, accessed but not modified the backend */

/** Set by the Frontend on constructor - Backend access once **/
Timezone timezone; /* Set by the frontend and accessed by the backend to construct PatternFormatter */
std::string format_pattern; /* Set by the frontend and accessed by the backend to construct PatternFormatter */
std::string time_pattern; /* Set by the frontend and accessed by the backend to construct PatternFormatter */
std::vector<std::shared_ptr<Sink>> sinks; /* Set by the frontend and accessed by the backend */
std::string format_pattern; /* Set by the frontend and accessed by the backend to initialise PatternFormatter */
std::string time_pattern; /* Set by the frontend and accessed by the backend to initialise PatternFormatter */
std::string logger_name; /* Set by the frontend, accessed by the frontend AND backend */
UserClockSource* user_clock{nullptr}; /* A non owned pointer to a custom timestamp clock, valid only when provided. used by frontend only */
Timezone timezone; /* Set by the frontend and accessed by the backend to initialise PatternFormatter */
ClockSourceType clock_source; /* Set by the frontend and accessed by the frontend AND backend */
std::atomic<LogLevel> log_level{LogLevel::Info}; /* used by frontend only */
std::atomic<LogLevel> backtrace_flush_level{LogLevel::None}; /** Updated by the frontend at any time, accessed by the backend */
std::atomic<bool> valid{true}; /* Updated by the frontend at any time, accessed by the backend */
};
} // namespace detail
} // namespace quill
} // namespace quill

0 comments on commit 196c6d4

Please sign in to comment.