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

Lazily initialize exponential histogram buckets #5023

Merged
merged 1 commit into from
Dec 14, 2022

Conversation

jack-berg
Copy link
Member

@jack-berg jack-berg commented Dec 7, 2022

Exponential histograms separately track bucket counts in the negative and positive range. Currently, histograms are not permitted to record negative measurements, yet we allocate memory to negative buckets anyway. The exponential histogram aggregation logic works with negative measurements in anticipation of them being permitted in the future, but even when they are permitted, many instruments will only record positive values.

This PR adjusts the exponential histogram aggregation to lazily instantiate both positive and negative buckets.

Here are the results of the HistogramCollectBenchmark before:

Benchmark                                                                          (aggregationGenerator)  (aggregationTemporality)  Mode  Cnt           Score           Error   Units
HistogramCollectBenchmark.recordAndCollect                                   EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  9197564316.600 ± 157971347.306   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                    EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           3.764 ±         0.040  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm               EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5    38305473.600 ±    816439.674    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space           EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           3.949 ±        15.903  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space.norm      EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5    40265318.400 ± 162152456.251    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Survivor_Space       EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5          ≈ 10⁻³                  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Survivor_Space.norm  EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5        3412.800 ±     29385.237    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                         EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           3.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                          EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           5.000                      ms
HistogramCollectBenchmark.recordAndCollect                                   EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  9216800908.200 ±  31120256.517   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                    EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.806 ±         0.089  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm               EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    38807947.200 ±    830507.303    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space           EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.783 ±        15.757  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space.norm      EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    38587596.800 ± 160860384.216    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                         EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                          EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           7.000                      ms

And after:

HistogramCollectBenchmark.recordAndCollect                               EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  9363457049.800 ± 348621966.366   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           3.069 ±         0.125  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm           EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5    31767908.800 ±    760387.947    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space       EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           1.946 ±        10.261  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space.norm  EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5    20132659.200 ± 106153700.699    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                     EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           2.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                      EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           6.000                      ms
HistogramCollectBenchmark.recordAndCollect                               EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  9282971800.200 ± 643932624.558   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.136 ±         0.119  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm           EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    32196094.400 ±    868793.468    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space       EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.939 ±        10.229  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space.norm  EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    20132659.200 ± 106153700.699    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                     EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           2.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                      EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           5.000                      ms

Edit
Was comparing gc.alloc.rate when I should be comparing gc.alloc.rate.norm. Comparing the bytes allocated for second doesn't account for a speed increase in the number of operations per second, which may increase the allocation rate. gc.alloc.rate.norm improves from 38_305_473 B/op to 31_767_908 B/op (~17% reduction) for delta temporality, and 38_807_947 B/op to 32_196_094 B/op (~17%) for cumulative temporality.

@jack-berg jack-berg requested a review from a team December 7, 2022 22:32
@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Base: 91.24% // Head: 91.22% // Decreases project coverage by -0.02% ⚠️

Coverage data is based on head (d1f5ef9) compared to base (ab31828).
Patch coverage: 93.33% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5023      +/-   ##
============================================
- Coverage     91.24%   91.22%   -0.03%     
+ Complexity     4886     4885       -1     
============================================
  Files           552      552              
  Lines         14440    14456      +16     
  Branches       1379     1384       +5     
============================================
+ Hits          13176    13187      +11     
- Misses          876      879       +3     
- Partials        388      390       +2     
Impacted Files Coverage Δ
.../aggregator/DoubleExponentialHistogramBuckets.java 83.63% <ø> (-4.40%) ⬇️
...l/aggregator/ExponentialHistogramAccumulation.java 100.00% <ø> (ø)
...gregator/DoubleExponentialHistogramAggregator.java 96.80% <92.98%> (-3.21%) ⬇️
...opentelemetry/opentracingshim/SpanBuilderShim.java 94.78% <100.00%> (+0.98%) ⬆️
...ava/io/opentelemetry/opentracingshim/SpanShim.java 91.07% <100.00%> (+0.80%) ⬆️
...internal/aggregator/ExponentialBucketStrategy.java 88.88% <100.00%> (+1.38%) ⬆️
...metry/sdk/logs/export/BatchLogRecordProcessor.java 89.36% <0.00%> (-0.71%) ⬇️
...telemetry/sdk/trace/export/BatchSpanProcessor.java 91.72% <0.00%> (-0.69%) ⬇️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jack-berg
Copy link
Member Author

@jsuereth / @jkwatson please take a look when you have a chance.

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.

fine with me!

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.

2 participants