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.
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
[rhythm] Make ID generator more robust #4416
[rhythm] Make ID generator more robust #4416
Changes from 2 commits
170cd95
e68587a
28bffe8
d2c5a84
f510ce7
6cc54ed
fe81332
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Any reason not to call
uuid.NewSHA1
, since we are already using that hash function and version?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.
It's so hash.Hash is not created each time, saving some allocations.
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.
The current global var isn't safe for concurrent use, how about making it a struct var? I know the ID generator isn't called concurrently yet, but there's nothing preventing it, and seems likely (parallelism in the block builder).
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.
I've been strongly preferring the
fnv1a
static methods that require no struct and have no concurrency concerns.https://pkg.go.dev/github.com/segmentio/fasthash/fnv1a
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.
Moved the
hash.Hash
to a struct field. Agree it's safer, and the difference won't be noticeable.From what I read, the main arguments for using fasthash is saving allocs and avoiding inefficient string to bytes conversions.
We'd need to do the alloc manually since we're reusing the data byte slice between sequential IDs and already have bytes. I don't see a big benefit on using other than Go's sha1 in this case.
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.
i may be misunderstanding the issue, but hashing bytes does not alloc with fnv1a. i
https://github.com/segmentio/fasthash/blob/v1.0.3/fnv1a/hash.go#L76-L108
while working on ingester locking I benched it against this:
tempo/pkg/tracesizes/traceSizes.go
Lines 28 to 32 in e0e6e6c
neither function alloc'ed, but it's twice as fast, has no state and requires no locking. i think the only question is whether or not its hash alg is as collision resistant.
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.
Yes agree that would be my concern with fnv. I think we can start with the SHAs in the uuid package and go from there. Realistically this is not called much (once per block), much less than trace/span hashing.