Files
tasks/service/matching/counter/counter.go
David ReissandGitHub d75074587f Fairness counter: keep top K on resize (#9187)
## What changed?
Fairness counters can use a count-min sketch that can automatically grow
on contention. But when it grows it drops all values. This adds a
mechanism to preserve counts of the top 100 keys.

## Why?
More accurate fairness

## How did you test it?
- [x] added new unit test(s)
2026-02-11 12:09:09 -08:00

19 lines
674 B
Go

package counter
type Counter interface {
// GetPass tracks a value per key, which may be lossy or approximate. It increments the
// value by inc and returns the new value. The value returned must be >= base.
GetPass(key string, base, inc int64) int64
// EstimateDistinctKeys returns an estimate of the number of distinct keys in the counter.
EstimateDistinctKeys() int
// Get the counts for a small number of top keys (the maximum keys returned will be limited
// by the Counter's configuration). Not guaranteed to return the exact top.
TopK() []TopKEntry
}
// TopKEntry is a count for a value with high count.
type TopKEntry struct {
Key string
Count int64
}