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

FIFO cache to support eviction based on memory usage #2319

Merged
merged 20 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@
* [ENHANCEMENT] Output all config fields to /config API, including those with empty value. #2209
* [ENHANCEMENT] Add "missing_metric_name" and "metric_name_invalid" reasons to cortex_discarded_samples_total metric. #2346
* [ENHANCEMENT] Experimental TSDB: sample ingestion errors are now reported via existing `cortex_discarded_samples_total` metric. #2370
* [ENHANCEMENT] FIFO cache to support eviction based on memory usage. The `-<prefix>.fifocache.size` CLI flag has been renamed to `-<prefix>.fifocache.max-size-items` as well as its YAML config option `size` renamed to `max_size_items`. Added `-<prefix>.fifocache.max-size-bytes` CLI flag and YAML config option `max_size_bytes` to specify memory limit of the cache. #2319
* [BUGFIX] Ensure user state metrics are updated if a transfer fails. #2338
* [BUGFIX] Fixed etcd client keepalive settings. #2278
* [BUGFIX] Fixed bug in updating last element of FIFO cache. #2270
dmitsh marked this conversation as resolved.
Show resolved Hide resolved
* [BUGFIX] Register the metrics of the WAL. #2295

### config file breaking changes
Expand Down
15 changes: 12 additions & 3 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2271,13 +2271,22 @@ The `fifo_cache_config` configures the local in-memory cache. The supported CLI
&nbsp;

```yaml
# The number of entries to cache.
# CLI flag: -<prefix>.fifocache.size
[size: <int> | default = 0]
# Maximum memory size of the cache.
# CLI flag: -<prefix>.fifocache.max-size-bytes
dmitsh marked this conversation as resolved.
Show resolved Hide resolved
[max_size_bytes: <int> | default = 0]

# Maximum number of entries in the cache.
# CLI flag: -<prefix>.fifocache.max-size-items
[max_size_items: <int> | default = 0]

# The expiry duration for the cache.
# CLI flag: -<prefix>.fifocache.duration
[validity: <duration> | default = 0s]

# Deprecated (use max-size-items or max-size-bytes instead): The number of
# entries to cache.
# CLI flag: -<prefix>.fifocache.size
[size: <int> | default = 0]
```

### `configs_config`
Expand Down
6 changes: 4 additions & 2 deletions docs/production/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ To enable the FIFO cache, use the following flags:
Enable in-memory cache.
-<prefix>.fifocache.duration duration
The expiry duration for the cache.
-<prefix>.fifocache.size int
The number of entries to cache.
-<prefix>.fifocache.max-size-bytes int
Maximum memory size of the cache.
-<prefix>.fifocache.max-size-items int
Maximum number of entries in the cache.
```

See [`fifo_cache_config` documentation](../configuration/config-file-reference.md#fifo-cache-config) if you use a config file with Cortex.
Expand Down
5 changes: 3 additions & 2 deletions pkg/chunk/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ func New(cfg Config) (Cache, error) {
cfg.Fifocache.Validity = cfg.DefaultValidity
}

cache := NewFifoCache(cfg.Prefix+"fifocache", cfg.Fifocache)
caches = append(caches, Instrument(cfg.Prefix+"fifocache", cache))
if cache := NewFifoCache(cfg.Prefix+"fifocache", cfg.Fifocache); cache != nil {
caches = append(caches, Instrument(cfg.Prefix+"fifocache", cache))
}
}

if (cfg.MemcacheClient.Host != "" || cfg.MemcacheClient.Addresses != "") && cfg.Redis.Endpoint != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/chunk/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestMemcache(t *testing.T) {
}

func TestFifoCache(t *testing.T) {
cache := cache.NewFifoCache("test", cache.FifoCacheConfig{Size: 1e3, Validity: 1 * time.Hour})
cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 1e3, Validity: 1 * time.Hour})
testCache(t, cache)
}

Expand Down
Loading