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

Reuse aggregation handles for delta temporality #5176

Merged
merged 2 commits into from
Feb 5, 2023

Conversation

jack-berg
Copy link
Member

@jack-berg jack-berg commented Feb 3, 2023

After recent changes, cumulative aggregations now use the same AggregationHandle over the course of their life, resulting in lower allocation than delta, which issue new AggregationHandle instances after each collect. This isn't necessary - after collecting and reseting, the AggregationHandles are back to their initial state and can be reused.

The result is a >50% memory allocation reduction for delta instruments. Pretty slick for just a handful of lines of code!

Performance benchmarks before:

Benchmark                                                                            (aggregationGenerator)  (aggregationTemporality)  Mode  Cnt           Score            Error   Units
HistogramCollectBenchmark.recordAndCollect                                        EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5  3458089008.200 ±   26999461.789   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                         EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           6.707 ±          0.051  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                    EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5    24324384.000 ±      36995.153    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                              EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           2.000                   counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                               EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           4.000                       ms
HistogramCollectBenchmark.recordAndCollect                                        EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  3407994625.000 ±   32476845.163   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                         EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.228 ±          0.168  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                    EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    11536617.600 ±     526515.571    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                              EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                   counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                               EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.000                       ms
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  8986348966.600 ±   24049913.999   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           3.227 ±          0.035  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5    30412870.400 ±     395977.482    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                   DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           2.000                   counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                    DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           5.000                       ms
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  9247763016.600 ±  105509714.595   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           0.903 ±          0.071  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8760268.800 ±     618060.579    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                   DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                   counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                    DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           2.000                       ms
HistogramCollectBenchmark.recordAndCollect                      ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  2670762033.200 ±  147260902.960   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           6.943 ±          0.428  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5    19443435.200 ±     302459.415    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count            ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           2.000                   counts
HistogramCollectBenchmark.recordAndCollect:·gc.time             ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           4.000                       ms
HistogramCollectBenchmark.recordAndCollect                      ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  4340594333.200 ± 6376432742.032   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           2.215 ±          3.196  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8949961.600 ±     313437.791    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count            ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                   counts
HistogramCollectBenchmark.recordAndCollect:·gc.time             ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.000                       ms

And after:

Benchmark                                                                            (aggregationGenerator)  (aggregationTemporality)  Mode  Cnt           Score           Error   Units
HistogramCollectBenchmark.recordAndCollect                                        EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5  3390255558.400 ±  29491981.021   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                         EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           3.007 ±         0.020  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                    EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5    10689731.200 ±     36579.743    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                              EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                               EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           2.000                      ms
HistogramCollectBenchmark.recordAndCollect                                        EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  3436534566.600 ± 102736943.608   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                         EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.202 ±         0.199  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                    EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    11536620.800 ±    526953.810    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                              EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                               EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.000                      ms
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  9538995141.800 ±  95720490.562   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           0.636 ±         0.030  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     6363548.800 ±    305261.174    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                   DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5             ≈ 0                  counts
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  9042829725.000 ± 169838553.573   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           0.933 ±         0.068  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8849014.400 ±    654075.369    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                   DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                    DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                      ms
HistogramCollectBenchmark.recordAndCollect                      ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  2616061300.000 ±  67260283.355   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           2.391 ±         0.104  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     6559592.000 ±    284720.892    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count            ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5             ≈ 0                  counts
HistogramCollectBenchmark.recordAndCollect                      ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  2624043408.200 ±  48730935.089   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.420 ±         0.167  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     9411476.800 ±    308800.163    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count            ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time             ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                      ms

Notice how memory allocation for cumulative and delta temporality are now in line with one another.

@codecov
Copy link

codecov bot commented Feb 3, 2023

Codecov Report

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

Coverage data is based on head (14bb709) compared to base (249d097).
Patch coverage: 80.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5176   +/-   ##
=========================================
  Coverage     91.06%   91.07%           
- Complexity     4863     4866    +3     
=========================================
  Files           548      548           
  Lines         14360    14368    +8     
  Branches       1375     1377    +2     
=========================================
+ Hits          13077    13085    +8     
  Misses          891      891           
  Partials        392      392           
Impacted Files Coverage Δ
...nternal/state/DefaultSynchronousMetricStorage.java 91.37% <80.00%> (-4.63%) ⬇️
...y/exporter/internal/marshal/CodedOutputStream.java 70.76% <0.00%> (+1.16%) ⬆️
...ava/io/opentelemetry/sdk/internal/RateLimiter.java 100.00% <0.00%> (+5.88%) ⬆️

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 jack-berg marked this pull request as ready for review February 3, 2023 23:33
@jack-berg jack-berg requested a review from a team February 3, 2023 23:33
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