-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
performance of UUID generation is slow – implementation uses getrandom
syscall
#109397
Comments
NOTE: there might be wrong assumptions in the code which assume that the underlying implementation of [1]
[2] https://cockroachlabs.slack.com/archives/C4X2J0RH6/p1692725321047249 |
@cockroachdb/sql-foundations |
We actually intentionally assume collision free UUIDs in some parts of the code. For example, the optimizer will skip certain uniqueness checks if you have a UUID primary key in some cases. @mgartner can describe that better, and also may have an opinion on this issue. |
Yes, that's an assumption we make by default for |
Also note that for PG compat, we may need to keep UUID generation through SQL as cryptographically secure https://security.stackexchange.com/questions/93902/is-postgress-uuid-generate-v4-securely-random/93905#93905 |
We can make a cluster setting that determines which random source to use for |
As of
Thus, we should be able to switch to |
UUID (
gen_random_uuid()
anduuid_v4()
) [1] are currently implemented usingcrypto/rand
. While this provides a strong guarantee wrt security, it's highly inefficient. UUID v4 is a randomly generated 128-bit value; nothing in the spec. [2] dictates that the implementation must use a cryptographically secure PRNG.The current implementation effectively requires a system call (
getrandom
) for every new value ofgen_random_uuid()
. This was originally observed in [3]. I have independently stumbled upon it whilestrace
ing an execution of,which induced ~
6 million
syscalls togetrandom
! The reason is we usegen_random_uuid()
for automatically generating therowid
column in thehistory
table [4].Microbenchmarks
Using the existing microbenchmarks
BenchmarkMakeV4
andBenchmarkFastMakeV4
onc5.9xlarge
(with PMU), we can see that the performance is > 10x slower; cf. ~811 ns/op vs. 54 ns/op.[1] https://www.cockroachlabs.com/docs/stable/uuid
[2] https://www.ietf.org/rfc/rfc4122.txt
[3] #30236 (comment)
[4]
cockroach/pkg/workload/tpcc/ddls.go
Line 91 in b24aa96
Jira issue: CRDB-30899
The text was updated successfully, but these errors were encountered: