Issues encountered when processing hot logger in asynchronous mode #3548
-
|
Dear experts, Hello! I am a Linux server-side developer. In my typical use of the spdlog library, one logger instance is bound to only one daily_file_sink. Suppose my program has high logging demands, and I want to start multiple logging worker threads (async threads) to process log messages in the queue, thereby accelerating consumption speed. However, the vast majority of log messages in my program must be output through the same daily_file_sink instance—meaning the number of "hot daily_file_sink instances" is less than the number of worker threads (hot daily_file_sink instance count < thread count). In this case, multiple logging threads will frequently compete for the mutex lock of the same sink instance, which may lead to the following issues:
In this scenario, increasing the number of async threads from 1 to multiple does not significantly improve log consumption speed. For this scenario, might the following design be better?
I would like to ask for your thoughts on this problem. How did you consider such scenarios when designing the spdlog library? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Is this about the async logger provided by spdlog? By the way, even if you use threads to parallelize log output operations, the final destination for log messages is still disk. Fundamentally, log output speed will never exceed disk I/O speed. |
Beta Was this translation helpful? Give feedback.
-
|
The exact same question #3547 |
Beta Was this translation helpful? Give feedback.
First off, please note that spdlog's async logger is slower than the synchronous logger when it comes to log output speed.
This is because the purpose of the async logger is to prevent the logging thread from being blocked during log output, not to speed up log output itself.
Please also see the related issues: #1391, #2282
The purpose of the async logger is as described above.
it is designed to avoid blocking the application's main processing. Therefore, to output a large number of log messages to a file at high speed, a better solution may be required.
As you pointed out, the
std::mutexin the sink may cause lock contention and potentially degrade performan…