spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

latency

Open Jason0401 opened this issue 2 years ago • 5 comments

Is sync faster than async? I can't understand,Isn't asynchronous supposed to be faster than synchronous?

Jason0401 avatar Mar 11 '24 07:03 Jason0401

Short answer: async cannot usually be faster than sync

Long answer: most async operations are implemented by requesting a task to another thread. In this case, async cannot be faster than sync because of the cost of passing data to another thread.. However, the thread that requests a task to another thread can proceed to the next operation without waiting for the task to complete, so the next operation can start earlier than sync.

See also: https://stackoverflow.com/questions/29981941/why-is-async-programming-faster

tt4g avatar Mar 11 '24 10:03 tt4g

Thanks for your answer When people use async logger, they hope that it does not affect the latency of the main thread so that the next operation can be started earlier, however, this effect cannot be achieved by using spdlog::async_logger

Jason0401 avatar Mar 13 '24 08:03 Jason0401

If the function “SPDLOG_LOGGER_WARN(async_logger, "")” returned earlier, that would be great

Jason0401 avatar Mar 13 '24 08:03 Jason0401

I think the existing async_logger is primarily used to ensure that the main thread is not blocked,but passing data to queue is not very fast

Jason0401 avatar Mar 13 '24 08:03 Jason0401

The async_logger is intended to avoid I/O latency, and as explained before, there will be additional costs for requesting tasks to different threads, which cannot be avoided.

tt4g avatar Mar 13 '24 10:03 tt4g