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

Stop extra copy of exponential histogram buckets #5020

Merged
merged 1 commit into from Dec 7, 2022

Conversation

jack-berg
Copy link
Member

Currently an extra copy of exponential histogram buckets is made during collection, which causes extra memory allocation when temporality is cumulative.

This PR addresses it by mutating the buckets instead of operating on a copy.

Here's the the HistogramCollectBenchmark before:

Benchmark                                                                      (aggregationGenerator)  (aggregationTemporality)  Mode  Cnt           Score           Error   Units
HistogramCollectBenchmark.recordAndCollect                               EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  9507808383.600 ± 160312845.363   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           3.493 ±         0.090  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm           EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5    36675027.200 ±    794113.234    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space       EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           3.673 ±        15.302  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space.norm  EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5    38587596.800 ± 160860384.216    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           6.000                      ms
HistogramCollectBenchmark.recordAndCollect                               EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  9350454516.600 ± 292150521.432   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           4.355 ±         0.149  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm           EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    45011481.600 ±    224644.078    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space       EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.889 ±        15.728  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.churn.G1_Eden_Space.norm  EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    40265318.400 ± 162152456.251    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           6.000                      ms

And after:

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

The key bit is a reduction in HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate for CUMULATIVE temporality from 4.355 MB/sec to 3.806 MB/sec. A modest but non-negligible improvement.

@jack-berg jack-berg marked this pull request as ready for review December 6, 2022 20:21
@jack-berg jack-berg requested a review from a team as a code owner December 6, 2022 20:21
@codecov
Copy link

codecov bot commented Dec 6, 2022

Codecov Report

Base: 91.24% // Head: 91.24% // Increases project coverage by +0.00% 🎉

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

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5020   +/-   ##
=========================================
  Coverage     91.24%   91.24%           
+ Complexity     4886     4881    -5     
=========================================
  Files           552      552           
  Lines         14440    14421   -19     
  Branches       1379     1375    -4     
=========================================
- Hits          13176    13159   -17     
+ Misses          876      875    -1     
+ Partials        388      387    -1     
Impacted Files Coverage Δ
.../aggregator/DoubleExponentialHistogramBuckets.java 87.27% <ø> (-0.77%) ⬇️
...opentelemetry/opentracingshim/SpanBuilderShim.java 94.78% <100.00%> (+0.98%) ⬆️
...ava/io/opentelemetry/opentracingshim/SpanShim.java 91.07% <100.00%> (+0.80%) ⬆️
...gregator/DoubleExponentialHistogramAggregator.java 100.00% <100.00%> (ø)
...metry/sdk/logs/export/BatchLogRecordProcessor.java 89.36% <0.00%> (-0.71%) ⬇️

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.

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.

None yet

2 participants