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

Support concurrent logging to a single WriteSyncer #106

Merged
merged 2 commits into from
Jul 27, 2016

Conversation

prashantv
Copy link
Collaborator

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.

Fixes #99

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()) {
Copy link
Contributor

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()).

Copy link
Collaborator Author

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.

@prashantv
Copy link
Collaborator Author

Updated with test fix

@akshayjshah
Copy link
Contributor

:shipit:

@prashantv prashantv merged commit 0a2fe7e into master Jul 27, 2016
@prashantv prashantv deleted the pv_concurrent_write branch July 27, 2016 17:58
flisky added a commit to flisky/zap that referenced this pull request Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants