Skip to content

Make cumulative count computations in takeCountSnapshot more efficient - #3581

Merged
shakuzen merged 1 commit into
micrometer-metrics:mainfrom
ThePumpingLemma:accidentally-quadratic
Mar 16, 2023
Merged

shakuzen merged 1 commit into
micrometer-metrics:mainfrom
ThePumpingLemma:accidentally-quadratic

Conversation

@ThePumpingLemma

Copy link
Copy Markdown
Contributor

Instead of recomputing the cumulative sum again for each CountAtBucket, keep a running tally during iteration

Instead of recomputing the cumulative sum again for each
`CountAtBucket`, keep a running tally during iteration
@ThePumpingLemma

Copy link
Copy Markdown
Contributor Author

This brings back #3394 but without references to fixing the concurrency issues (since it is not a comprehensive fix for it, merely an optimization).

@shakuzen shakuzen self-assigned this Jan 24, 2023
@ThePumpingLemma

Copy link
Copy Markdown
Contributor Author

@shakuzen any thoughts on this changeset?

@shakuzen shakuzen added enhancement A general enhancement performance Issues related to general performance module: micrometer-core An issue that is related to our core module registry: prometheus A Prometheus Registry related issue labels Mar 16, 2023
@shakuzen shakuzen added this to the 1.11.0-RC1 milestone Mar 16, 2023
@shakuzen

Copy link
Copy Markdown
Member

I took the liberty of benchmarking this and it indeed cuts down on the time taken to create a snapshot. Results from my M1 Macbook:

Benchmark                                                                                (useOld)    Mode     Cnt      Score   Error   Units
HistogramCountSnapshotBenchmark.snapshotHistogramCounts                                     false  sample  395700      6.376 ± 0.041   us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.00       false  sample              5.832           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.50       false  sample              6.120           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.90       false  sample              6.536           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.95       false  sample              6.704           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.99       false  sample              8.000           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.999      false  sample             23.242           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.9999     false  sample            603.433           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p1.00       false  sample           1527.808           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:·gc.alloc.rate                      false  sample       2   3216.273          MB/sec
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:·gc.alloc.rate.norm                 false  sample       2  21312.144            B/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:·gc.count                           false  sample       2    175.000          counts
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:·gc.time                            false  sample       2     87.000              ms
HistogramCountSnapshotBenchmark.snapshotHistogramCounts                                      true  sample  237385     42.119 ± 0.050   us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.00        true  sample             40.896           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.50        true  sample             41.664           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.90        true  sample             43.072           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.95        true  sample             44.160           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.99        true  sample             48.000           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.999       true  sample             59.687           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p0.9999      true  sample            645.120           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:snapshotHistogramCounts·p1.00        true  sample           1002.496           us/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:·gc.alloc.rate                       true  sample       2    482.374          MB/sec
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:·gc.alloc.rate.norm                  true  sample       2  21312.563            B/op
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:·gc.count                            true  sample       2     33.000          counts
HistogramCountSnapshotBenchmark.snapshotHistogramCounts:·gc.time                             true  sample       2     17.000              ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A general enhancement module: micrometer-core An issue that is related to our core module performance Issues related to general performance registry: prometheus A Prometheus Registry related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants