Skip to content

Commit

Permalink
chore: delete recording statistics about rejections
Browse files Browse the repository at this point in the history
  • Loading branch information
maypok86 committed Sep 24, 2024
1 parent 9548d01 commit f3ec528
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 47 deletions.
22 changes: 3 additions & 19 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import (
// If you also want to record eviction statistics,
// then your recorder should implement an EvictionStatsRecorder.
//
// If you also want to record statistics on rejections,
// then your recorder should implement an RejectionStatsRecorder.
//
// If you also want to record load statistics,
// then your recorder should implement an LoadStatsRecorder.
type StatsRecorder interface {
Expand All @@ -45,12 +42,6 @@ type EvictionStatsRecorder interface {
RecordEviction(weight uint32)
}

// RejectionStatsRecorder is a recorder that records statistics on the rejections.
type RejectionStatsRecorder interface {
// RecordRejections records rejections of entries. Cache rejects entries only if they have too much weight.
RecordRejections(count int)
}

// LoadStatsRecorder is a recorder that records statistics on the loads of new entries.
type LoadStatsRecorder interface {
// RecordLoadSuccess records the successful load of a new entry. This method should be called when a cache request
Expand All @@ -66,21 +57,18 @@ type noopStatsRecorder struct{}
func (np noopStatsRecorder) RecordHits(count int) {}
func (np noopStatsRecorder) RecordMisses(count int) {}
func (np noopStatsRecorder) RecordEviction(weight uint32) {}
func (np noopStatsRecorder) RecordRejections(count int) {}
func (np noopStatsRecorder) RecordLoadFailure(loadTime time.Duration) {}
func (np noopStatsRecorder) RecordLoadSuccess(loadTime time.Duration) {}

type statsRecorder interface {
StatsRecorder
EvictionStatsRecorder
RejectionStatsRecorder
LoadStatsRecorder
}

type statsRecorderHub struct {
StatsRecorder
EvictionStatsRecorder
RejectionStatsRecorder
LoadStatsRecorder
}

Expand All @@ -94,18 +82,14 @@ func newStatsRecorder(recorder StatsRecorder) statsRecorder {
}

sc := &statsRecorderHub{
StatsRecorder: recorder,
EvictionStatsRecorder: noopStatsRecorder{},
RejectionStatsRecorder: noopStatsRecorder{},
LoadStatsRecorder: noopStatsRecorder{},
StatsRecorder: recorder,
EvictionStatsRecorder: noopStatsRecorder{},
LoadStatsRecorder: noopStatsRecorder{},
}

if ec, ok := recorder.(EvictionStatsRecorder); ok {
sc.EvictionStatsRecorder = ec
}
if rsc, ok := recorder.(RejectionStatsRecorder); ok {
sc.RejectionStatsRecorder = rsc
}
if lc, ok := recorder.(LoadStatsRecorder); ok {
sc.LoadStatsRecorder = lc
}
Expand Down
9 changes: 0 additions & 9 deletions stats/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type Counter struct {
misses *xsync.Adder
evictions *xsync.Adder
evictionWeight *xsync.Adder
rejections *xsync.Adder
loadSuccesses *xsync.Adder
loadFailures *xsync.Adder
totalLoadTime *xsync.Adder
Expand All @@ -40,7 +39,6 @@ func NewCounter() *Counter {
misses: xsync.NewAdder(),
evictions: xsync.NewAdder(),
evictionWeight: xsync.NewAdder(),
rejections: xsync.NewAdder(),
loadSuccesses: xsync.NewAdder(),
loadFailures: xsync.NewAdder(),
totalLoadTime: xsync.NewAdder(),
Expand All @@ -62,7 +60,6 @@ func (c *Counter) Snapshot() Stats {
misses: c.misses.Value(),
evictions: c.evictions.Value(),
evictionWeight: c.evictionWeight.Value(),
rejections: c.rejections.Value(),
loadSuccesses: c.loadSuccesses.Value(),
loadFailures: c.loadFailures.Value(),
//nolint:gosec // overflow is handled above
Expand Down Expand Up @@ -90,12 +87,6 @@ func (c *Counter) RecordEviction(weight uint32) {
c.evictionWeight.Add(uint64(weight))
}

// RecordRejections records rejections of entries. Cache rejects entries only if they have too much weight.
func (c *Counter) RecordRejections(count int) {
//nolint:gosec // there is no overflow
c.rejections.Add(uint64(count))
}

// RecordLoadSuccess records the successful load of a new entry. This method should be called when a cache request
// causes an entry to be loaded and the loading completes successfully.
func (c *Counter) RecordLoadSuccess(loadTime time.Duration) {
Expand Down
4 changes: 0 additions & 4 deletions stats/counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestCounter_Basic(t *testing.T) {
c.RecordHits(1)
c.RecordMisses(1)
c.RecordEviction(10)
c.RecordRejections(20)
c.RecordLoadSuccess(1)
c.RecordLoadFailure(1)

Expand All @@ -35,7 +34,6 @@ func TestCounter_Basic(t *testing.T) {
misses: 1,
evictions: 1,
evictionWeight: 10,
rejections: 20,
loadSuccesses: 1,
loadFailures: 1,
totalLoadTime: 2,
Expand Down Expand Up @@ -72,7 +70,6 @@ func TestCounter_Concurrent(t *testing.T) {
c.RecordHits(1)
c.RecordMisses(1)
c.RecordEviction(10)
c.RecordRejections(20)
c.RecordLoadSuccess(1)
c.RecordLoadFailure(1)
}()
Expand All @@ -85,7 +82,6 @@ func TestCounter_Concurrent(t *testing.T) {
misses: 50,
evictions: 50,
evictionWeight: 500,
rejections: 1000,
loadSuccesses: 50,
loadFailures: 50,
totalLoadTime: 100,
Expand Down
6 changes: 0 additions & 6 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Stats struct {
misses uint64
evictions uint64
evictionWeight uint64
rejections uint64
loadSuccesses uint64
loadFailures uint64
totalLoadTime time.Duration
Expand Down Expand Up @@ -71,11 +70,6 @@ func (s Stats) MissRatio() float64 {
return float64(s.misses) / float64(requests)
}

// Rejections returns the number of rejections.
func (s Stats) Rejections() uint64 {
return s.rejections
}

// Evictions returns the number of times an entry has been evicted. This count does not include manual
// otter.Cache deletions.
func (s Stats) Evictions() uint64 {
Expand Down
9 changes: 0 additions & 9 deletions stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func testStats(
requests uint64,
hitRatio float64,
missRatio float64,
rejectedSets uint64,
evictions uint64,
evictionWeight uint64,
loadSuccesses uint64,
Expand All @@ -55,9 +54,6 @@ func testStats(
if s.MissRatio() != missRatio {
t.Fatalf("missRatio should be %.2f, but got %.2f", missRatio, s.MissRatio())
}
if s.Rejections() != rejectedSets {
t.Fatalf("rejections should be %d, but got %d", rejectedSets, s.Rejections())
}
if s.Evictions() != evictions {
t.Fatalf("evictions should be %d, but got %d", evictions, s.Evictions())
}
Expand Down Expand Up @@ -98,7 +94,6 @@ func TestStats(t *testing.T) {
0,
0,
0,
0,
0.0,
0,
)
Expand All @@ -110,7 +105,6 @@ func TestStats(t *testing.T) {
misses: 13,
evictions: 27,
evictionWeight: 54,
rejections: 1,
loadSuccesses: 17,
loadFailures: 19,
totalLoadTime: 23,
Expand All @@ -120,7 +114,6 @@ func TestStats(t *testing.T) {
24,
11.0/24,
13.0/24,
1,
27,
54,
17,
Expand All @@ -138,7 +131,6 @@ func TestStats(t *testing.T) {
misses: math.MaxUint64,
evictions: 27,
evictionWeight: 54,
rejections: 1,
loadSuccesses: math.MaxUint64,
loadFailures: math.MaxUint64,
totalLoadTime: math.MaxInt64,
Expand All @@ -148,7 +140,6 @@ func TestStats(t *testing.T) {
math.MaxUint64,
1.0,
1.0,
1,
27,
54,
math.MaxUint64,
Expand Down

0 comments on commit f3ec528

Please sign in to comment.