-
Notifications
You must be signed in to change notification settings - Fork 30
Lock-free stream implementation #61
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2a55fef
to
0d96de9
Compare
fca5718
to
b7c5ac8
Compare
miek
reviewed
Mar 17, 2023
I've added a runtime check that the block size is a multiple of the system page size. |
antoinevg
reviewed
Apr 12, 2023
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.
👍
martinling
commented
Apr 12, 2023
miek
approved these changes
May 2, 2023
antoinevg
approved these changes
May 2, 2023
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.
👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds a new lock-free implementation of the basic underlying data structure required by Packetry: an append-only data stream, backed by a file, for which we require fast random access to any part of the data whilst it continues to grow.
Packetry's current implementation, in the
FileVec
andHybridIndex
types, uses file I/O which adds significant overhead. Both reading and writing require exclusive access to a stream object, which is currently managed by a singleMutex
protecting the wholeCapture
database. This creates contention between the decoder and UI threads.The new implementation creates two objects for each stream: a unique
StreamWriter
, and a clonableStreamReader
. The writer and any number of readers may operate concurrently without blocking each other.StreamReader
creates memory-mapped regions on demand to access the file in blocks of a configurable size, which must be a multiple of the system page size. Each reader maintains a fixed-size cache of mappings for its most recently used blocks, using the LruBTreeMap type.StreamWriter
operates much like a conventional buffered writer, but uses interchangeable write buffers whose lifetimes are managed byArc
. To read stream data not yet written to the file, readers clone theArc
of the current write buffer, which they can then retain access to after the writer moves on to using another buffer.Atomically switching from one write buffer to another is achieved using the ArcSwap type.