Skip to content
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 low precision Clock#now when computing timestamp for exemplars #6417

Merged

Conversation

jack-berg
Copy link
Member

@jack-berg jack-berg commented Apr 30, 2024

Resolves #6403.

Introduces a new Clock#now(boolean highPrecision) overload, which uses a performance optimized millisecond precision when highPrecision=false. Updates ReservoirCell to obtain measurement times using Clock#now(false), which shaves a good chunk of time off the time to record each exemplar (~50ns on my machine).

This has a greater impact the more frequent measurements are candidates to be stored in ReservoirCell. The savings are especially impactful for the histogram exemplar reservoir, where the algorithm requires us to take the last measurement for each bucket. This means we compute the time for every measurement recorded.

Here's a benchmark output comparing the high precision and low precision Clock#now implementations. Benchmark run using OpenJDK Runtime Environment Temurin-17.0.3+7.

Benchmark                                                     Mode  Cnt   Score    Error   Units
ExemplarClockBenchmarks.now_highPrecision                     avgt   10  66.006 ±  0.110   ns/op
ExemplarClockBenchmarks.now_highPrecision:gc.alloc.rate       avgt   10   0.001 ±  0.001  MB/sec
ExemplarClockBenchmarks.now_highPrecision:gc.alloc.rate.norm  avgt   10  ≈ 10⁻⁴             B/op
ExemplarClockBenchmarks.now_highPrecision:gc.count            avgt   10     ≈ 0           counts
ExemplarClockBenchmarks.now_lowPrecision                      avgt   10  17.982 ±  0.152   ns/op
ExemplarClockBenchmarks.now_lowPrecision:gc.alloc.rate        avgt   10   0.001 ±  0.001  MB/sec
ExemplarClockBenchmarks.now_lowPrecision:gc.alloc.rate.norm   avgt   10  ≈ 10⁻⁵             B/op
ExemplarClockBenchmarks.now_lowPrecision:gc.count             avgt   10     ≈ 0           counts

@jack-berg jack-berg requested a review from a team April 30, 2024 20:17
Copy link

codecov bot commented Apr 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.11%. Comparing base (9845ac9) to head (c31f282).
Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6417      +/-   ##
============================================
- Coverage     91.12%   91.11%   -0.01%     
- Complexity     5856     5868      +12     
============================================
  Files           636      636              
  Lines         17062    17082      +20     
  Branches       1733     1741       +8     
============================================
+ Hits          15548    15565      +17     
- Misses         1019     1021       +2     
- Partials        495      496       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -68,8 +68,8 @@ synchronized void recordDoubleMeasurement(double value, Attributes attributes, C

private void offerMeasurement(Attributes attributes, Context context) {
this.attributes = attributes;
// Note: It may make sense in the future to attempt to pull this from an active span.
this.recordTime = clock.now();
// High precision time is not worth the additional performance expense it incurs for exemplars
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jkwatson
Copy link
Contributor

jkwatson commented May 1, 2024

what JVM version were you using to benchmark with? (not that it matters much..but might be nice to include in the PR description for posterity).

Copy link
Contributor

@jkwatson jkwatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jack-berg
Copy link
Member Author

what JVM version were you using to benchmark with? (not that it matters much..but might be nice to include in the PR description for posterity).

Updated!

@jack-berg jack-berg merged commit 9b67fe0 into open-telemetry:main May 1, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider different mechanism for computing time of exemplar measurements
3 participants