spdlog
spdlog copied to clipboard
Custom BUFSIZ support
The default BUFSIZ parameter on most Linux systems is simply 8K. On my box, a dd command shows a buffer size of 512K would have much better performance. I wonder whether there is any way I can use a custom buffer size when creating a logger.
In my case, spdlog is used to stream data to multiple (about 100) files. I suspect the default flush policy is hitting the disk too frequently, and would like to see whether there is any way to improve the performance.
Maybe calling https://en.cppreference.com/w/cpp/io/c/setvbuf somewhere in the file sink impl would do the trick?
It should work, and spdlog can add a parameter to expose it to end users.
Would be nice if you could try and report the actual performance gain.
Here is a simple test of using different buffer size, and the results are significant.
For simplicity, I only tested single-thread since the buffer is managed by myself. The bench_single_threaded function is used to evaluation the performance.
[info] **************************************************************
[info] Single threaded: 2500000 messages; BufSize: 8192
[info] **************************************************************
[info] basic_st Elapsed: 1.20 secs 2,089,389/sec
[info] basic_st/backtrace-on Elapsed: 1.29 secs 1,931,904/sec
[info] **************************************************************
[info] Single threaded: 2500000 messages; BufSize: 262144
[info] **************************************************************
[info] basic_st Elapsed: 0.62 secs 4,021,943/sec
[info] basic_st/backtrace-on Elapsed: 0.64 secs 3,896,717/sec