-
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
perf: reconsider crypto/rand use in UUID allocation for txn IDs #30236
Comments
Yes!! Really happy to see this - I've noticed UUID generation taking a lot of time in profiles but I didn't think we could fix it. |
I seem to recall looking at this in the past and discovering that crypto generation on Mac OS X was super slow in comparison to Linux. You might want to verify the perf increase on a Linux box. |
I looked into this at the time and confirmed that However, I'm now seeing it come up on a single node |
…pto/rand Fixes cockroachdb#30236 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. Release note (performance improvement): Use faster randomness source to generate transaction IDs.
…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.
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>
78fee99 moved usages of math/rand to crypto/rand. This has performance implications, as described in cockroachdb#30236 (comment). Rather than forcing a change, we mark the existing non-test usages of math/rand as ignored by the linter so the appropriate engineering teams can decide what to do. Release note: None
78fee99 moved usages of math/rand to crypto/rand. This has performance implications, as described in cockroachdb#30236 (comment). Rather than forcing a change, we mark the existing non-test usages of math/rand as ignored by the linter so the appropriate engineering teams can decide what to do. Release note: None
110561: *: add back non-test usages of math/rand r=rafiss a=rafiss 78fee99 moved usages of math/rand to crypto/rand. This has performance implications, as described in #30236 (comment). Rather than forcing a change, we mark the existing non-test usages of math/rand as ignored by the linter so the appropriate engineering teams can decide what to do. informs #110597 informs #110599 Release note: None 110601: changefeedccl: Fix setting propagation flake r=miretskiy a=miretskiy Setting changes are asynchronous, particularly in tenants. Set the feature setting directly instead. Fixes #110300 Release note: None Co-authored-by: Rafi Shamim <rafi@cockroachlabs.com> Co-authored-by: Yevgeniy Miretskiy <yevgeniy@cockroachlabs.com>
We currently use V4 UUIDs as transaction IDs. Our UUID library,
github.com/satori/go.uuid
, uses a cryptographically secure random number generator (crypto/rand
) to populate the UUID. In #30233, we observed that this was responsible for 77% of mutex contention during akv95 --concurrency=64
run on my laptop:I ran an experiment where I swapped this over to a cryptographically insecure
math/rand
rng (which still uses a global lock) and saw this lock contention completely disappear. I also saw throughput jump by about 2.1%.I don't think we need a cryptographically secure random byte generator for our transaction IDs, so we should consider making this change for real.
github.com/satori/go.uuid
won't let us swap out the rng, butgithub.com/google/uuid
will, and we already have an open issue to replace our uuid library:#26332.
Also, FWIW in the long run, we might be replacing UUID txn ids entirely. See #24194.
@m-schneider this got me thinking about #26178. If/once #30233 is merged, we should take a look at mutex profiles before and after the throughput cliff we're observing in that issue.
The text was updated successfully, but these errors were encountered: