-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
util/uuid: fork gofrs, generate with math/rand instead of crypto/rand #32238
Conversation
This should go the other way: use crypto/rand by default, and only switch to math/rand where we know performance is critical and we don't need stronger randomness (just transaction ids?) |
What Ben says.
When the change is aiming to improve performance:
|
Also looking at the linked issue #30236 there is only mention of accelerating txn ID generation. So as a word of wisdom, to be reused generally when thinking of changing the "provider" of some of the
|
6317e41
to
80d69eb
Compare
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.
Fixed the comment with regards to the default. I'll go through the other callers and see if they occur on hot paths, but for now updated the diff to just touch the transaction ID.
Reviewable status: complete! 0 of 0 LGTMs obtained
d50a3a0
to
024c5b4
Compare
38aef5c
to
41fee30
Compare
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.
but please wait for someone else to sign off as well!
Reviewed 60 of 60 files at r1.
Reviewable status: complete! 1 of 0 LGTMs obtained
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.
although I'd like to see a benchmark demonstrating the benefit that we observe from this change.
Reviewed 18 of 60 files at r1.
Reviewable status: complete! 2 of 0 LGTMs obtained
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.
Huh wait
There is a huge chunk of new code in the pkg/util
package. There is zero explanation for this code in the commit message. This contrast between the two things does not sit well with me.
See my comments above about what a commit message should state.
See also the comment above by Ben - how did you actually address the requirement to provide different UUID sources for SQL? Did you do so actually? (It's not so clear to me how/where this is happening. The commit message should guide me.)
It seems you copied code from 3rd party sources into the pkg/util
directory. Code imports, together with a highlight of the license that allowed you to import this code, should be called out in the commit message.
Also repeat of my invitation to provide benchmark comparisons.
Reviewed 3 of 60 files at r1.
Reviewable status: complete! 2 of 0 LGTMs obtained
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.
Are we looking at different commit messages, @knz? This is the one I'm looking at:
Copies the source from github.com/gofrs/uuid into util/uuid at 7077aa61129615a0d7f45c49101cd011ab221c27.
Remove github.com/satori/go.uuid dep
Modifies the copyright notice to refer to the license at licenses/MIT-gofrs.txt.
Renames the spurious Bytes method to bytes.
Adds the ability to create a Gen with a random byte Reader.
Add FastMakeV4() which uses a generator which draws from a math/rand.Rand.
Use FastMakeV4 in roachpb.MakeTransaction.
I suppose there could be more rationale but it seems to speak to the questions you've asked.
Here's how I would phrase the commit message, @ajwerner, just FYI. I'm also fine with what you already have!
util/uuid: support generation of fast but non-cryptographically secure UUIDs
Replace our UUID library, github.com/satori/go.uuid, which was unmaintained and did not provide a facility for customizing the source of randomness. The new library is based upon the MIT-licensed github.com/gofrs/uuid library, which is better maintained and allows customizing the source of randomness. Because the code is so simple, copy and paste it wholesale rather than vendoring it. This will ease future customizations.
The new library exposes a fast UUID generation function, FastUUIDV4, that uses a non-cryptographically secure function for generating UUIDs. For now, only transaction ID generation uses the new fast generation function, as transaction IDs are only used internally and therefore do not need a cryptographically-secure source of randomness. Other calls to UUID generation, like the SQL builtins, continue to use a cryptographically-secure source of randomness.
Reviewable status: complete! 2 of 0 LGTMs obtained
Yes indeed I didn't really read the commit message because it was all mashed up together and appeared to me initially as a mere list of steps that were taken without visibility on neither motivation nor end result.
However I apologise for misreading and my resulting wrong impression. The information I was seeking was indeed present and I would not have commissioned if I had paid more attention. My sincerest excuses.
That said a note about the multiple sources and which caller uses which source would be welcome.
And a benchmark 😺
With love,
…--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Part of the expected improvement from #30236 is Mac-specific. I know you don't have a Mac laptop, so I took this for a quick spin to verify the effect. Sure enough, the effect is immediately clear on Mutex profiles when running before:after:The baseline throughput difference on the benchmark was somewhere around .5%, but I didn't run enough trials for the results to be statistically significant:
|
…e UUIDs Replace our UUID library, github.com/satori/go.uuid, which was unmaintained and did not provide a facility for customizing the source of randomness. The new library is based upon the MIT-licensed github.com/gofrs/uuid library (at 7077aa61129615a0d7f45c49101cd011ab221c27), which is a better maintained fork of the previous dependency. Because the code is so simple, copy and paste it wholesale rather than vendoring it to ease modification. Modify the forked library to allow customization of the source of randomness and remove problematic Bytes method on the UUID object which complicates its use inside protobuf generated structs. The new library exposes a fast UUID generation function, FastMakeV4, that uses a non-cryptographically secure function for generating UUIDs. For now, only transaction ID generation uses the new fast generation function, as transaction IDs are only used internally and therefore do not need a cryptographically-secure source of randomness. Other calls to UUID generation, like the SQL builtins, continue to use a cryptographically-secure source of randomness. Fixes cockroachdb#30236 Release note (performance improvement): Use faster randomness source to generate transaction IDs.
41fee30
to
fd9705b
Compare
From micro benchmarks on my Linux laptop I see the below compelling win. I'm running kv benchmarks on roachprod now.
Also added the benchmark to the code and updated the commit message along the lines of @benesch's suggestion. |
Didn't see any statistically significant improvement on 32 core machines but got the below results on 3 64 core machines running kv with 95% reads, with concurrency set to 512:
bors r+ |
32238: util/uuid: fork gofrs, generate with math/rand instead of crypto/rand r=ajwerner a=ajwerner Fixes #30236 Copies the source from github.com/gofrs/uuid into util/uuid at 7077aa61129615a0d7f45c49101cd011ab221c27. Modifies the copyright notice to refer to the license at licenses/MIT-gofrs.txt. Renames the spurious Bytes method to bytes. Adds the ability to create a Gen with a random byte Reader. Add FastMakeV4() which uses a generator which draws from a math/rand.Rand. Use FastMakeV4 in roachpb.MakeTransaction. Release note (performance improvement): Use faster randomness source to generate transaction IDs. Co-authored-by: Andrew Werner <ajwerner@cockroachlabs.com>
Build succeeded |
Fixes #30236
Copies the source from github.com/gofrs/uuid into util/uuid at 7077aa61129615a0d7f45c49101cd011ab221c27.
Modifies the copyright notice to refer to the license at licenses/MIT-gofrs.txt.
Renames the spurious Bytes method to bytes.
Adds the ability to create a Gen with a random byte Reader.
Add FastMakeV4() which uses a generator which draws from a math/rand.Rand.
Use FastMakeV4 in roachpb.MakeTransaction.
Release note (performance improvement): Use faster randomness source to generate transaction IDs.