Skip to content

Conversation

@dhartunian
Copy link
Collaborator

@dhartunian dhartunian commented Jan 22, 2025

metric: add histogram benchmark

Simple benchmark to measure histogram recording performance.

Release note: None


deps: use forked prometheus/client_golang

This modifies our dependencies to use a forked client_golang in
order to take some perf shortcuts we can't do via the public API.

Resolves: #138930
Part of: #138932

Release note: None


metric: lookup histogram bucket once to update

Previously, we would look up the histogram bucket twice. Once for
the cumulative histogram, and another time for the windowed. This was
unnecessary because we guarantee that the two histograms are always
using identical bucket configurations.

Once we forked the client_golang dependency, and made public the
bucket lookup method we were able to call it directly and reuse the
lookup result for both observations.

Benchmark results:

❯ benchdiff ./pkg/util/metric -b -r 'BenchmarkHistogramRecordValue' -c 10
checking out 'e85968b'
building benchmark binaries for e85968b: deps: use forked prometheus/client_golang [bazel=true] 1/1 |
checking out '8c28ed3'
building benchmark binaries for 8c28ed3: metric: lookup histogram bucket once to update [bazel=true] 1/1 |

  pkg=1/1 iter=10/10 cockroachdb/cockroach/pkg/util/metric \

name                                     old time/op    new time/op    delta
HistogramRecordValue/insert_integers-10    53.9ns ± 2%    36.4ns ± 0%  -32.49%  (p=0.000 n=10+10)
HistogramRecordValue/random_integers-10    59.1ns ± 1%    43.4ns ± 0%  -26.63%  (p=0.000 n=9+10)
HistogramRecordValue/insert_zero-10        31.6ns ± 1%    29.5ns ± 0%   -6.78%  (p=0.000 n=10+8)

name                                     old alloc/op   new alloc/op   delta
HistogramRecordValue/insert_integers-10     0.00B          0.00B          ~     (all equal)
HistogramRecordValue/insert_zero-10         0.00B          0.00B          ~     (all equal)
HistogramRecordValue/random_integers-10     0.00B          0.00B          ~     (all equal)

name                                     old allocs/op  new allocs/op  delta
HistogramRecordValue/insert_integers-10      0.00           0.00          ~     (all equal)
HistogramRecordValue/insert_zero-10          0.00           0.00          ~     (all equal)
HistogramRecordValue/random_integers-10      0.00           0.00          ~     (all equal)

Resolves: #138932

Release note: None

@dhartunian dhartunian requested review from a team as code owners January 22, 2025 20:27
@dhartunian dhartunian requested review from aa-joshi, angles-n-daemons and arjunmahishi and removed request for a team January 22, 2025 20:27
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@dhartunian dhartunian force-pushed the use-forked-client_golang branch from 217f763 to 121e750 Compare January 23, 2025 20:12
@dhartunian
Copy link
Collaborator Author

@dhartunian dhartunian force-pushed the use-forked-client_golang branch from 121e750 to e034e72 Compare January 24, 2025 16:30
Hypothesis: all the cluster setting customizations in this test
are causing flakes and lockups but making subsystems behave in
non-standard ways.

I ran the test a few times without any settings changes and it seems
to run in about the same time or faster than before. It appears that
their intention was to make the test "faster" but that doesn't seem to
be the case, especially since we don't care to run it under duress.

Resolves: cockroachdb#139600
Release note: None
Copy link
Contributor

@angles-n-daemons angles-n-daemons left a comment

Choose a reason for hiding this comment

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

Nice like the performance enhancements 👍

One comment


b.ResetTimer()

b.Run("insert integers", func(b *testing.B) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also do a diff for randomly generated values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done! thx for the suggestion.

Simple benchmark to measure histogram recording performance.

Release note: None
This modifies our dependencies to use a forked `client_golang` in
order to take some perf shortcuts we can't do via the public API.

Resolves: cockroachdb#138930
Part of: cockroachdb#138932

Release note: None
Previously, we would look up the histogram bucket twice. Once for
the cumulative histogram, and another time for the windowed. This was
unnecessary because we guarantee that the two histograms are always
using identical bucket configurations.

Once we forked the `client_golang` dependency, and made public the
bucket lookup method we were able to call it directly and reuse the
lookup result for both observations.

Benchmark results:
```
❯ benchdiff ./pkg/util/metric -b -r 'BenchmarkHistogramRecordValue' -c 10
checking out 'e85968b'
building benchmark binaries for e85968b: deps: use forked prometheus/client_golang [bazel=true] 1/1 |
checking out '8c28ed3'
building benchmark binaries for 8c28ed3: metric: lookup histogram bucket once to update [bazel=true] 1/1 |

  pkg=1/1 iter=10/10 cockroachdb/cockroach/pkg/util/metric \

name                                     old time/op    new time/op    delta
HistogramRecordValue/insert_integers-10    53.9ns ± 2%    36.4ns ± 0%  -32.49%  (p=0.000 n=10+10)
HistogramRecordValue/random_integers-10    59.1ns ± 1%    43.4ns ± 0%  -26.63%  (p=0.000 n=9+10)
HistogramRecordValue/insert_zero-10        31.6ns ± 1%    29.5ns ± 0%   -6.78%  (p=0.000 n=10+8)

name                                     old alloc/op   new alloc/op   delta
HistogramRecordValue/insert_integers-10     0.00B          0.00B          ~     (all equal)
HistogramRecordValue/insert_zero-10         0.00B          0.00B          ~     (all equal)
HistogramRecordValue/random_integers-10     0.00B          0.00B          ~     (all equal)

name                                     old allocs/op  new allocs/op  delta
HistogramRecordValue/insert_integers-10      0.00           0.00          ~     (all equal)
HistogramRecordValue/insert_zero-10          0.00           0.00          ~     (all equal)
HistogramRecordValue/random_integers-10      0.00           0.00          ~     (all equal)
```

Resolves: cockroachdb#138932

Release note: None
@dhartunian dhartunian force-pushed the use-forked-client_golang branch from e034e72 to d0b60bf Compare January 24, 2025 19:54
@dhartunian
Copy link
Collaborator Author

TFTR!

bors r=angles-n-daemons

@craig craig bot merged commit ebb1d25 into cockroachdb:master Jan 24, 2025
22 checks passed
@dhartunian dhartunian added the o-perf-efficiency Related to performance efficiency label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

o-perf-efficiency Related to performance efficiency

Projects

None yet

3 participants