Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom BUFSIZ support #1799

Open
randomizedthinking opened this issue Jan 13, 2021 · 4 comments
Open

Custom BUFSIZ support #1799

randomizedthinking opened this issue Jan 13, 2021 · 4 comments

Comments

@randomizedthinking
Copy link

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.

@gabime
Copy link
Owner

gabime commented Jan 13, 2021

Maybe calling https://en.cppreference.com/w/cpp/io/c/setvbuf somewhere in the file sink impl would do the trick?

@randomizedthinking
Copy link
Author

It should work, and spdlog can add a parameter to expose it to end users.

@gabime gabime changed the title Custom buffer size for loggers Custom BUFSIZ su Jan 13, 2021
@gabime gabime changed the title Custom BUFSIZ su Custom BUFSIZ support Jan 13, 2021
@gabime
Copy link
Owner

gabime commented Jan 13, 2021

Would be nice if you could try and report the actual performance gain.

@randomizedthinking
Copy link
Author

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                                                                                                                                                                 

bachittle pushed a commit to bachittle/spdlog that referenced this issue Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants