Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Revert "hit/miss stats for matchcache"
Browse files Browse the repository at this point in the history
This reverts commit 3bae47f.

They consume about 1% cpu (flat and cumul) under heavy ingest load
and they basically just confirm it works exactly like it should.

But the commit is here in case someone ever wants to re-apply it.
  • Loading branch information
Dieterbe committed Mar 9, 2017
1 parent be0b16e commit 8ddd548
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
4 changes: 2 additions & 2 deletions mdata/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ func ConfigProcess() {
}

func Cache(cleanInterval, expireAfter time.Duration) {
schemasCache = matchcache.New("schemas", cleanInterval, expireAfter)
aggsCache = matchcache.New("aggs", cleanInterval, expireAfter)
schemasCache = matchcache.New(cleanInterval, expireAfter)
aggsCache = matchcache.New(cleanInterval, expireAfter)
}
14 changes: 2 additions & 12 deletions mdata/matchcache/matchcache.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package matchcache

import (
"fmt"
"sync"
"time"

"github.com/raintank/metrictank/stats"
)

// Cache caches key to uint16 lookups (for schemas and aggregations)
Expand All @@ -18,22 +15,18 @@ type Cache struct {

cleanInterval time.Duration
expireAfter time.Duration
hits *stats.Counter32
miss *stats.Counter32
}

type Item struct {
val uint16
seen int64
}

func New(name string, cleanInterval, expireAfter time.Duration) *Cache {
func New(cleanInterval, expireAfter time.Duration) *Cache {
m := &Cache{
data: make(map[string]Item),
cleanInterval: cleanInterval,
expireAfter: expireAfter,
hits: stats.NewCounter32(fmt.Sprintf("idx.matchcache.%s.ops.hit", name)),
miss: stats.NewCounter32(fmt.Sprintf("idx.matchcache.%s.ops.miss", name)),
}
go m.maintain()
return m
Expand All @@ -45,10 +38,7 @@ type AddFunc func(key string) uint16
func (m *Cache) Get(key string, fn AddFunc) uint16 {
m.Lock()
item, ok := m.data[key]
if ok {
m.hits.Inc()
} else {
m.miss.Inc()
if !ok {
item.val = fn(key)
}
item.seen = time.Now().Unix()
Expand Down

0 comments on commit 8ddd548

Please sign in to comment.