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

Commit

Permalink
make findCache settings configurable
Browse files Browse the repository at this point in the history
- add config settings for:
 - find-cache-invalidate-queue:  number of new series names to process
    Each new series name is compared against expresions in the findCache
    if the expression matches the new name, it is removed from the cache.
 - find-cache-backoff: amount of time to disable the findCache for when
   the invalidate-queue fills up.  If there are lots of new series being
   added then scanning the cache for patterns that match can become
   exspensive, so it is just best to disable the cache for a while.
- log a message when the cache is disabled due to the invalidateQueue
  limit being reached.
  • Loading branch information
woodsaj committed Mar 11, 2019
1 parent 68f9601 commit 2088aab
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docker/docker-chaos/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ max-prune-lock-time = 100ms
partitioned = false
# number of find expressions to cache
find-cache-size = 1000
# size of queue for invalidating findCache entries.
find-cache-invalidate-queue = 100
# amount of time to disable the findCache when the invalidate queue fills up
find-cache-backoff = 60s

### Bigtable index
[bigtable-idx]
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-cluster/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ max-prune-lock-time = 100ms
partitioned = false
# number of find expressions to cache
find-cache-size = 1000
# size of queue for invalidating findCache entries.
find-cache-invalidate-queue = 100
# amount of time to disable the findCache when the invalidate queue fills up
find-cache-backoff = 60s

### Bigtable index
[bigtable-idx]
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-dev-custom-cfg-kafka/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ max-prune-lock-time = 100ms
partitioned = false
# number of find expressions to cache
find-cache-size = 1000
# size of queue for invalidating findCache entries.
find-cache-invalidate-queue = 100
# amount of time to disable the findCache when the invalidate queue fills up
find-cache-backoff = 60s

### Bigtable index
[bigtable-idx]
Expand Down
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ max-prune-lock-time = 100ms
partitioned = false
# number of find expressions to cache
find-cache-size = 1000
# size of queue for invalidating findCache entries.
find-cache-invalidate-queue = 100
# amount of time to disable the findCache when the invalidate queue fills up
find-cache-backoff = 60s
```

### Bigtable index
Expand Down
10 changes: 7 additions & 3 deletions idx/memory/find_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var (
findCacheHit = stats.NewCounterRate32("idx.memory.find-cache.hit")
// metric idx.memory.find-cache.hit is a counter of findCache misses
findCacheMiss = stats.NewCounterRate32("idx.memory.find-cache.miss")

findCacheSize = 1000
findCacheInvalidateQueue = 100
findCacheBackoff = time.Minute
)

type FindCache struct {
Expand Down Expand Up @@ -70,7 +74,7 @@ func (c *FindCache) Add(orgId uint32, pattern string, nodes []*Node) {
}
c.Lock()
c.cache[orgId] = cache
c.newSeries[orgId] = make(chan struct{}, 100)
c.newSeries[orgId] = make(chan struct{}, findCacheInvalidateQueue)
c.Unlock()
}
cache.Add(pattern, nodes)
Expand Down Expand Up @@ -98,7 +102,7 @@ func (c *FindCache) InvalidateFor(orgId uint32, path string) {
case c.newSeries[orgId] <- struct{}{}:
default:
c.Lock()
c.backoff[orgId] = time.Now().Add(time.Minute)
c.backoff[orgId] = time.Now().Add(findCacheBackoff)
delete(c.cache, orgId)
c.Unlock()
for i := 0; i < len(c.newSeries[orgId]); i++ {
Expand All @@ -107,7 +111,7 @@ func (c *FindCache) InvalidateFor(orgId uint32, path string) {
default:
}
}

log.Infof("memory-idx: findCache invalidate-queue full. Disabling cache for %s. num-cached-entries=%d", findCacheBackoff.String(), cache.Len())
return
}

Expand Down
3 changes: 2 additions & 1 deletion idx/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ var (
indexRulesFile string
IndexRules conf.IndexRules
Partitioned bool
findCacheSize = 1000
)

func ConfigSetup() {
Expand All @@ -67,6 +66,8 @@ func ConfigSetup() {
memoryIdx.IntVar(&TagQueryWorkers, "tag-query-workers", 50, "number of workers to spin up to evaluate tag queries")
memoryIdx.IntVar(&matchCacheSize, "match-cache-size", 1000, "size of regular expression cache in tag query evaluation")
memoryIdx.IntVar(&findCacheSize, "find-cache-size", 1000, "number of find expressions to cache")
memoryIdx.IntVar(&findCacheInvalidateQueue, "find-cache-invalidate-queue", 100, "size of queue for invalidating findCache entries.")
memoryIdx.DurationVar(&findCacheBackoff, "find-cache-backoff", time.Minute, "amount of time to disable the findCache when the invalidate queue fills up.")
memoryIdx.StringVar(&indexRulesFile, "rules-file", "/etc/metrictank/index-rules.conf", "path to index-rules.conf file")
memoryIdx.StringVar(&maxPruneLockTimeStr, "max-prune-lock-time", "100ms", "Maximum duration each second a prune job can lock the index.")
globalconf.Register("memory-idx", memoryIdx, flag.ExitOnError)
Expand Down
4 changes: 4 additions & 0 deletions metrictank-sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ max-prune-lock-time = 100ms
partitioned = false
# number of find expressions to cache
find-cache-size = 1000
# size of queue for invalidating findCache entries.
find-cache-invalidate-queue = 100
# amount of time to disable the findCache when the invalidate queue fills up
find-cache-backoff = 60s

### Bigtable index
[bigtable-idx]
Expand Down
4 changes: 4 additions & 0 deletions scripts/config/metrictank-package.ini
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ max-prune-lock-time = 100ms
partitioned = false
# number of find expressions to cache
find-cache-size = 1000
# size of queue for invalidating findCache entries.
find-cache-invalidate-queue = 100
# amount of time to disable the findCache when the invalidate queue fills up
find-cache-backoff = 60s

### Bigtable index
[bigtable-idx]
Expand Down

0 comments on commit 2088aab

Please sign in to comment.