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

Track evictions in the PostingsForMatchers cache #824

Merged
merged 3 commits into from
Jan 28, 2025

Conversation

pracucci
Copy link
Collaborator

@pracucci pracucci commented Jan 27, 2025

In #822 I've introduced metrics for the PostingsForMatchers cache. In this PR I'm extending the metrics to count evictions by reason.

Ref: https://github.com/grafana/pir-actions/issues/307

Benchmarks

goos: darwin
goarch: arm64
pkg: github.com/prometheus/prometheus/tsdb
cpu: Apple M3 Pro
                                                          │ before.txt  │             after.txt             │
                                                          │   sec/op    │   sec/op     vs base              │
PostingsForMatchersCache/no_evictions-11                    639.1n ± 2%   636.2n ± 1%       ~ (p=0.394 n=6)
PostingsForMatchersCache/high_eviction_rate-11              10.66µ ± 0%   10.70µ ± 1%       ~ (p=0.071 n=6)
PostingsForMatchersCache_ConcurrencyOnHighEvictionRate-11   328.2n ± 1%   326.3n ± 3%       ~ (p=0.167 n=6)
geomean                                                     1.308µ        1.305µ       -0.24%

                                                          │  before.txt  │              after.txt               │
                                                          │     B/op     │     B/op      vs base                │
PostingsForMatchersCache/no_evictions-11                      974.0 ± 0%     974.0 ± 0%       ~ (p=1.000 n=6) ¹
PostingsForMatchersCache/high_eviction_rate-11              26.32Ki ± 0%   26.32Ki ± 0%       ~ (p=1.000 n=6) ¹
PostingsForMatchersCache_ConcurrencyOnHighEvictionRate-11   1.000Ki ± 0%   1.000Ki ± 0%       ~ (p=1.000 n=6)
geomean                                                     2.925Ki        2.925Ki       +0.00%
¹ all samples are equal

                                                          │ before.txt │             after.txt              │
                                                          │ allocs/op  │ allocs/op   vs base                │
PostingsForMatchersCache/no_evictions-11                    20.00 ± 0%   20.00 ± 0%       ~ (p=1.000 n=6) ¹
PostingsForMatchersCache/high_eviction_rate-11              46.00 ± 0%   46.00 ± 0%       ~ (p=1.000 n=6) ¹
PostingsForMatchersCache_ConcurrencyOnHighEvictionRate-11   20.00 ± 0%   20.00 ± 5%       ~ (p=1.000 n=6)
geomean                                                     26.40        26.40       +0.00%
¹ all samples are equal

@pracucci pracucci marked this pull request as ready for review January 27, 2025 10:31
Comment on lines 354 to 365
if evictionReasons[evictionReasonTTL] > 0 {
c.metrics.evictionsBecauseTTL.Add(float64(evictionReasons[evictionReasonTTL]))
}
if evictionReasons[evictionReasonMaxBytes] > 0 {
c.metrics.evictionsBecauseMaxBytes.Add(float64(evictionReasons[evictionReasonMaxBytes]))
}
if evictionReasons[evictionReasonMaxItems] > 0 {
c.metrics.evictionsBecauseMaxItems.Add(float64(evictionReasons[evictionReasonMaxItems]))
}
if evictionReasons[evictionReasonUnknown] > 0 {
c.metrics.evictionsBecauseUnknown.Add(float64(evictionReasons[evictionReasonUnknown]))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the ifs here necessary? If so, would be good to add a comment explaining why.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought it was slightly after on high eviction rate (assuming most of the times cached promises are removed because of 1 out of 4 reasons), but benchmark doesn't show it far, so I've removed the if stataements.

goos: darwin
goarch: arm64
pkg: github.com/prometheus/prometheus/tsdb
cpu: Apple M3 Pro
                                                          │ before.txt  │             after.txt             │
                                                          │   sec/op    │   sec/op     vs base              │
PostingsForMatchersCache/no_evictions-11                    640.7n ± 3%   644.4n ± 9%       ~ (p=0.260 n=6)
PostingsForMatchersCache/high_eviction_rate-11              10.75µ ± 0%   10.73µ ± 0%       ~ (p=0.260 n=6)
PostingsForMatchersCache_ConcurrencyOnHighEvictionRate-11   338.6n ± 4%   332.5n ± 3%       ~ (p=0.818 n=6)
geomean                                                     1.326µ        1.320µ       -0.45%

                                                          │  before.txt  │              after.txt               │
                                                          │     B/op     │     B/op      vs base                │
PostingsForMatchersCache/no_evictions-11                      974.0 ± 0%     974.0 ± 0%       ~ (p=1.000 n=6) ¹
PostingsForMatchersCache/high_eviction_rate-11              26.32Ki ± 0%   26.32Ki ± 0%       ~ (p=1.000 n=6) ¹
PostingsForMatchersCache_ConcurrencyOnHighEvictionRate-11   1.003Ki ± 1%   1.000Ki ± 1%       ~ (p=0.571 n=6)
geomean                                                     2.928Ki        2.926Ki       -0.08%
¹ all samples are equal

                                                          │ before.txt │             after.txt              │
                                                          │ allocs/op  │ allocs/op   vs base                │
PostingsForMatchersCache/no_evictions-11                    20.00 ± 0%   20.00 ± 0%       ~ (p=1.000 n=6) ¹
PostingsForMatchersCache/high_eviction_rate-11              46.00 ± 0%   46.00 ± 0%       ~ (p=1.000 n=6) ¹
PostingsForMatchersCache_ConcurrencyOnHighEvictionRate-11   21.00 ± 5%   20.00 ± 5%       ~ (p=0.567 n=6)
geomean                                                     26.83        26.40       -1.61%
¹ all samples are equal

Signed-off-by: Marco Pracucci <[email protected]>
@pracucci pracucci enabled auto-merge (squash) January 28, 2025 17:29
@pracucci pracucci merged commit 127392e into main Jan 28, 2025
8 checks passed
@pracucci pracucci deleted the track-postings-for-matchers-cache-eviction-metrics branch January 28, 2025 17:40
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