-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support concurrent logging to a single WriteSyncer #106
Conversation
Currently, the WriteSyncer assumes the underlying Writer will support concurrent Writes correctly. However, this is not true for common io.Writer implementations: - *os.File may call the write syscall multiple times - *bytes.Buffer does not support concurrent writes at all Instead, we will wrap all passed in WriteSyncers in a lockedWriteSyncer which will use a mutex to serialize calls to the underlying WriteSyncer. In future, we may want to expose a way of setting a WriteSyncer that already supports concurrent calls, but since most common implementations cannot handle concurrent writes correctly, locking the writer seems like a simpler default.
}) | ||
} | ||
|
||
func runNTimes(n int, wg *sync.WaitGroup, f func()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth capturing the full pattern you're using? This helper could easily be runNTimes(n numGoroutines, m iterationsPerGoroutine, wg *sync.WaitGroup, f func())
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, can do that. It's a little less clear to have 2 ints as args, so I added comments for the arguments to make it clearer.
Updated with test fix |
3223491
to
ab8fc4f
Compare
ab8fc4f
to
9d327a5
Compare
Currently, the WriteSyncer assumes the underlying Writer will support
concurrent Writes correctly. However, this is not true for common
io.Writer implementations:
Instead, we will wrap all passed in WriteSyncers in a lockedWriteSyncer
which will use a mutex to serialize calls to the underlying WriteSyncer.
In future, we may want to expose a way of setting a WriteSyncer that
already supports concurrent calls, but since most common implementations
cannot handle concurrent writes correctly, locking the writer seems like
a simpler default.
Fixes #99