Skip to content

Commit

Permalink
feat(blooms): Add in-memory LRU cache for meta files (#12862)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum authored May 2, 2024
1 parent afbeedc commit fcd544c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
20 changes: 20 additions & 0 deletions docs/sources/shared/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5280,6 +5280,26 @@ bloom_shipper:
# component.
# The CLI flags prefix for this block configuration is: bloom.metas-cache
[metas_cache: <cache_config>]

metas_lru_cache:
# In-memory LRU cache for bloom metas. Whether embedded cache is enabled.
# CLI flag: -bloom.metas-lru-cache.enabled
[enabled: <boolean> | default = false]

# In-memory LRU cache for bloom metas. Maximum memory size of the cache in
# MB.
# CLI flag: -bloom.metas-lru-cache.max-size-mb
[max_size_mb: <int> | default = 100]

# In-memory LRU cache for bloom metas. Maximum number of entries in the
# cache.
# CLI flag: -bloom.metas-lru-cache.max-size-items
[max_size_items: <int> | default = 0]

# In-memory LRU cache for bloom metas. The time to live for items in the
# cache before they get purged.
# CLI flag: -bloom.metas-lru-cache.ttl
[ttl: <duration> | default = 1h]
```
### swift_storage_config
Expand Down
8 changes: 8 additions & 0 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,14 @@ func (t *Loki) initBloomStore() (services.Service, error) {
var metasCache cache.Cache
if cache.IsCacheConfigured(bsCfg.MetasCache) {
metasCache, err = cache.New(bsCfg.MetasCache, reg, logger, stats.BloomMetasCache, constants.Loki)

// always enable LRU cache
lruCfg := bsCfg.MetasLRUCache
lruCfg.Enabled = true
lruCfg.PurgeInterval = 1 * time.Minute
lruCache := cache.NewEmbeddedCache("inmemory-metas-lru", lruCfg, reg, logger, stats.BloomMetasCache)

metasCache = cache.NewTiered([]cache.Cache{lruCache, metasCache})
if err != nil {
return nil, fmt.Errorf("failed to create metas cache: %w", err)
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/storage/stores/shipper/bloomshipper/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
)

type Config struct {
WorkingDirectory flagext.StringSliceCSV `yaml:"working_directory"`
MaxQueryPageSize flagext.Bytes `yaml:"max_query_page_size"`
DownloadParallelism int `yaml:"download_parallelism"`
BlocksCache BlocksCacheConfig `yaml:"blocks_cache"`
MetasCache cache.Config `yaml:"metas_cache"`
WorkingDirectory flagext.StringSliceCSV `yaml:"working_directory"`
MaxQueryPageSize flagext.Bytes `yaml:"max_query_page_size"`
DownloadParallelism int `yaml:"download_parallelism"`
BlocksCache BlocksCacheConfig `yaml:"blocks_cache"`
MetasCache cache.Config `yaml:"metas_cache"`
MetasLRUCache cache.EmbeddedCacheConfig `yaml:"metas_lru_cache"`

// This will always be set to true when flags are registered.
// In tests, where config is created as literal, it can be set manually.
Expand All @@ -32,6 +33,7 @@ func (c *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.IntVar(&c.DownloadParallelism, prefix+"download-parallelism", 8, "The amount of maximum concurrent bloom blocks downloads. Usually set to 2x number of CPU cores.")
c.BlocksCache.RegisterFlagsWithPrefixAndDefaults(prefix+"blocks-cache.", "Cache for bloom blocks. ", f, 24*time.Hour)
c.MetasCache.RegisterFlagsWithPrefix(prefix+"metas-cache.", "Cache for bloom metas. ", f)
c.MetasLRUCache.RegisterFlagsWithPrefix(prefix+"metas-lru-cache.", "In-memory LRU cache for bloom metas. ", f)

// always cache LIST operations
c.CacheListOps = true
Expand Down

0 comments on commit fcd544c

Please sign in to comment.