Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Caching
Loki supports caching of index writes and lookups, chunks and query results to speed up query performance. This sections describes the recommended Memcached configuration to enable caching for chunks and query results. The index lookup cache is configured to be in-memory by default.
Before you begin
- It is recommended to deploy three, or in the case of the Helm chart two, dedicated Memcached clusters.
- As of 2023-02-01, the
memcached:1.6.17-alpineversion of the library is recommended. - Consult the Loki ksonnet memcached deployment and the ksonnet memcached library.
- Index caching is not required for the TSDB index format.
Steps
To enable and configure Memcached:
Deploy each Memcached service with at least three replicas and configure each as follows:
- Chunk cache
--memory-limit=4096 --max-item-size=2m --conn-limit=1024 - Query result and index queries cache
--memory-limit=1024 --max-item-size=5m --conn-limit=1024
- Chunk cache
Configure Loki to use the cache.
If the Helm chart is used
Set
memcached.chunk_cache.hostto the Memcached address for the chunk cache,memcached.results_cache.hostto the Memcached address for the query result cache,memcached.chunk_cache.enabled=trueandmemcached.results_cache.enabled=true.Ensure that the connection limit of Memcached is at least
number_of_clients * max_idle_conns.The options
hostandservicedepend on the type of installation. For example, using thebitnami/memcachedHelm Charts with the following commands, theservicevalues are alwaysmemcached.helm upgrade --install chunk-cache -n loki bitnami/memcached -f memcached-overrides-chunk.yaml helm upgrade --install results-cache -n loki bitnami/memcached -f memcached-overrides-results.yamlThe current Helm Chart only supports the chunk and results cache.
In this case, the Loki configuration would be
loki: memcached: chunk_cache: enabled: true host: chunk-cache-memcached.loki.svc service: memcached-client batch_size: 256 parallelism: 10 results_cache: enabled: true host: results-cache-memcached.loki.svc service: memcached-client default_validity: 12hIf the Loki configuration is used, modify the following three sections in the Loki configuration file.
- Configure the chunk and index write cache
chunk_store_config: chunk_cache_config: memcached: batch_size: 256 parallelism: 10 memcached_client: host: <chunk cache memcached host> service: <port name of memcached service> - Configure the query result cache
query_range: cache_results: true results_cache: cache: memcached_client: consistent_hash: true host: <memcached host> service: <port name of memcached service> max_idle_conns: 16 timeout: 500ms update_interval: 1m - Configure the index queries cache
storage_config: index_queries_cache_config: memcached: batch_size: 100 parallelism: 100 memcached_client: host: <memcached host> service: <port name of memcached service> consistent_hash: true
- Configure the chunk and index write cache



