Do not acquire lock for file.Sync() fsync call #67
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the Flush() function, a lock is acquired before calling file.flush and file.sync. file.flush writes the glog buffer into the kernel buffer, while file.sync writes the kernel buffer to disk.
We encountered a problem where when disk I/O is heavy(the cloud service provider offers poor cloud disk performance), all glog logs would be blocked due to waiting for file.sync.
file.sync ensures that logs are flushed to disk, but I believe that acquiring a lock before calling file.sync is unnecessary. The kernel has an efficient buffered I/O mechanism, and file.sync does not block kernel buffered I/O. We only need to request that logs are flushed to disk and do not need to acquire a lock and wait for the kernel to complete the flush. Acquiring a lock and waiting for logs to be flushed to disk cannot make good use of the kernel's buffered I/O, and it can lead to performance issues.