-
Notifications
You must be signed in to change notification settings - Fork 439
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
Use faster Rng in RandomIdGenerator (0%-6% performance improvement) #1106
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
📢 Thoughts on this report? Let us know!. |
😓 I need to re-run the baseline I realize my orignal baseline was on battery and I believe that may have shown the drastic improvements. |
Great to see some movement on this! Would be good to redo your measurements with a consistent environment. 😄 Questions:
cc @shaun-cox |
da365a2
to
54d9fcd
Compare
I think something insecure is fine for our case.
From reading the documentation from the random team it does seem like SmallRng is not portable which I think we may wnat to avoid for better univerality.
I think we could just opt for the Pcg32. |
Still seeing improvements, but a bit more variable (2%-12%) I ran base lines a few times to normalize the temperature of my laptop and I did the same with the modification.
|
If I'm reading the docs right, using |
What do you mean by portable, and universality? I don't see these terms in the documentation at https://docs.rs/rand/latest/rand/rngs/struct.SmallRng.html. |
There's some details here, but rust-random/rand#1285 reading into it, I don't think this is an issue for us since we don't plan to use |
On the consistent environment for benchmarking topic: I use the following and find it works well. export "RUSTFLAGS=-C force-frame-pointers=yes -C target-cpu=native"
taskset -c 2,4 cargo bench -p opentelemetry_sdk --bench trace -- --save-baseline main start-end-span/
taskset -c 2,4 cargo bench -p opentelemetry_sdk --bench trace -- --profile-time 20 start-end-span/
The other observation I have on this random generation of Futhermore, couldn't that later 64-bits be used as the Today, we fetch 192 bits of entropy in this codepath, but with above suggestion, we'd only need to fetch 64 bits. |
So i did a few tests looks like 2-7%. I'll post the full results when I'm back at my computer. For the entropy, i like the idea, but the one question I have is will this sharing of the first 64 bits result in a skew in of sampling. |
@hdost ping, can you still drive this forward? |
Yes sorry, was on vacation 🏄♂️ |
@shaun-cox any thoughts on this ? |
I don't readily see any issues with sampling skew, but I'm not an expert. 64-bits of randomness in the trace id would seem to provide enough to make uniform sampling decisions. I'll also reference this sdk issue which I came across while researching: open-telemetry/opentelemetry-specification#1413 |
SmallRng provides 0-6% improvement in Traces. Relates open-telemetry#808
54d9fcd
to
bb71c6c
Compare
|
So then for a followup change we can look to add one of the changes mentioned before about having a pre-sampled most Significant bit and only random generate the lower bits. |
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.
Nice!
@@ -21,7 +21,7 @@ futures-util = { version = "0.3.17", default-features = false, features = ["std" | |||
once_cell = "1.10" | |||
ordered-float = "4.0" | |||
percent-encoding = { version = "2.0", optional = true } | |||
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true } | |||
rand = { version = "0.8", default-features = false, features = ["std", "std_rng","small_rng"], optional = true } |
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.
Nit: add a space before "small_rng"
, please.
Represents a minimum a 11%-22% improvement in relevant benchmarks.
Fixes #808
Changes
Swapped Rng from ThreadLocal to Pcg64Mcg for significant speed improvement.
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changesBenchmarks