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

Asynchronous/double-buffering support? #16

Open
toddlipcon opened this issue Apr 8, 2015 · 7 comments
Open

Asynchronous/double-buffering support? #16

toddlipcon opened this issue Apr 8, 2015 · 7 comments

Comments

@toddlipcon
Copy link

This has come up a few times in the past, but figured I'd re-raise it after the transition from google code to github:

I'm seeing a case in my application where doing LOG() calls from an event loop thread is causing the entire event loop to stall for hundreds of milliseconds. Eventually I captured stacks showing that it's blocking trying to acquire log_mutex while another thread is in the middle of a disk flush. The disk flush can be very slow in the case that the logging disk is in the middle of an ext4 checkpoint (the buffered IO calls file_update_time to update the inode mtime, but the inode is locked for writeback)

A partial solution here would be to add double-buffering within the glog process (instead of relying on fwrite/fflush buffering). Writes would be appended into a buffer, and at "flush" time, we swap the buffer and do a non-buffered write of the old buffer to the file, while not holding the lock. Meanwhile other threads can continue to append to the new buffer without blocking.

A fuller solution would involve deferring the actual logging work to a background thread (eg by a MPSC queue). Either a bounded implementation (which drops messages or blocks when the queue is full) or an unbounded one (which uses a lot of RAM if you can't keep up) could be reasonable choices depending on the workload.

Does anyone have a fork of glog that does this? Would the glog maintainers be willing to accept a pull request if we decided to implement it ourselves?

@Bklyn
Copy link

Bklyn commented Jul 1, 2015

This sounds like a great feature. Holding up any thread to block on expensive I/O operations is a bad idea. There should be a way to set things up so a background thread handles all I/O.

@toddlipcon
Copy link
Author

FWIW I ended up implementing this using existing public glog APIs, in case anyone's interested in borrowing the code for their projects (or for distribution as part of glog)

https://github.com/apache/kudu/blob/master/src/kudu/util/async_logger.h
https://github.com/apache/kudu/blob/master/src/kudu/util/async_logger.cc
https://github.com/apache/kudu/blob/master/src/kudu/util/logging.cc#L129 (EnableAsyncLogging)

@steve-o
Copy link

steve-o commented Feb 16, 2017

An additional enhancement with caveats is to replace the mutex with a lock-free queue, there is discussion by the author of g3log here:

https://kjellkod.wordpress.com/2015/06/30/the-worlds-fastest-logger-vs-g3log/

@tangfu
Copy link

tangfu commented Mar 6, 2017

@toddlipcon :hi,have you benchmark kudu's async_logger?with native glog?

@toddlipcon
Copy link
Author

I didn't do throughput benchmarks, but the async logging solved a lot of blocking issues that we saw before where critical parts of our code would get "stuck" for several hundred milliseconds. Throughput is likely improved as well, but that's rarely a consideration for our app, so we didn't test it.

@Sasthan-SK
Copy link

Hi @sergiud @toddlipcon Since the ticket is closed, did we add Asynchronous/double-buffering support in glog ? It doesn't appear so, but can you please confirm.

@sergiud
Copy link
Collaborator

sergiud commented Aug 1, 2022

No support was added. The issue was closed due to inactivity. I'll reopen it.

@sergiud sergiud reopened this Aug 1, 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

6 participants