Skip to content

Commit 880de93

Browse files
jeschkiesJStickler
andauthored
Document memcached configuration for caching. (#8373)
**What this PR does / why we need it**: Memcached is our default options for caching. However, the options for Memcached are not well documented. This change documents how Memcached should be configured and how Loki itself should be documented based on our ksonnet deployment. **Checklist** - [ ] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [x] Documentation added - [ ] Tests updated - [ ] `CHANGELOG.md` updated - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/upgrading/_index.md` Co-authored-by: J Stickler <[email protected]>
1 parent 2f8d771 commit 880de93

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

docs/sources/installation/helm/install-scalable/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ It is not possible to run the scalable mode with the `filesystem` storage.
2323
- Helm 3 or above. See [Installing Helm](https://helm.sh/docs/intro/install/).
2424
- A running Kubernetes cluster.
2525
- A Prometheus operator installation in case meta-monitoring should be used.
26+
- Optionally a Memcached deployment for better performance. Consult the [caching section]({{<relref "../../../operations/caching">}}) on how to configure Memcached.
2627

2728
**To deploy Loki in scalable mode:**
2829

docs/sources/operations/caching.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: Caching
3+
menuTitle: Caching
4+
description: Enable and configure memcached for caching.
5+
weight: 100
6+
keywords:
7+
- memcached
8+
- caching
9+
---
10+
11+
# Caching
12+
13+
Loki supports caching of index writes and lookups, chunks and query results to
14+
speed up query performance. This sections describes the recommended Memcached
15+
configuration to enable caching for chunks and query results. The index lookup
16+
cache is configured to be in-memory by default.
17+
18+
## Before you begin
19+
20+
- It is recommended to deploy four dedicated Memcached clusters.
21+
- As of 2023-02-01, the `memcached:1.6.17-alpine` version of the library is recommended.
22+
- Consult the Loki ksonnet [memcached](https://github.com/grafana/loki/blob/main/production/ksonnet/loki/memcached.libsonnet) deployment and the ksonnet [memcached library](https://github.com/grafana/jsonnet-libs/tree/master/memcached).
23+
24+
## Steps
25+
26+
To enable and configure Memcached:
27+
28+
1. Deploy each Memcached service with at least three replicas and configure
29+
each as follows:
30+
1. Chunk cache
31+
```
32+
--memory-limit=4096 --max-item-size=2m --conn-limit=1024
33+
```
34+
1. Query result cache
35+
```
36+
--memory-limit=1024 --max-item-size=5m --conn-limit=1024
37+
```
38+
39+
1. Configure Loki to use the cache.
40+
1. If the Helm chart is used
41+
42+
Set `memcached.chunk_cache.host` to the Memecache address for the chunk cache, `memcached.results_cache.host` to the Memecache address for the query result cache, `memcached.chunk_cache.enabled=true` and `memcached.results_cache.enabled=true`.
43+
44+
Ensure that the connection limit of Memcached is at least `number_of_clients * max_idle_conns`.
45+
46+
The options `host` and `service` depend on the type of installation. For example, using the `bitname/memcached` Helm Charts with the following commands, the `service` values are always `memcached`.
47+
```
48+
helm upgrade --install chunk-cache -n loki bitnami/memcached -f memcached-overrides.yaml
49+
helm upgrade --install write-cache -n loki bitnami/memcached -f memcached-overrides.yaml
50+
helm upgrade --install results-cache -n loki bitnami/memcached -f memcached-overrides.yaml
51+
helm upgrade --install index-cache -n loki bitnami/memcached -f memcached-overrides.yaml
52+
```
53+
In this case, the Loki configuration would be
54+
```yaml
55+
loki:
56+
memcached:
57+
chunk_cache:
58+
enabled: true
59+
host: chunk-cache-memcached.loki.svc
60+
service: memcache
61+
batch_size: 256
62+
parallelism: 10
63+
results_cache:
64+
enabled: true
65+
host: results-cache-memcached.loki.svc
66+
service: memcache
67+
default_validity: 12h
68+
```
69+
1. If the Loki configuration is used
70+
1. Configure the chunk cache
71+
```yaml
72+
chunk_store_config:
73+
chunk_cache_config:
74+
memcached:
75+
batch_size: 256
76+
parallelism: 10
77+
memcached_client:
78+
host: <memcached host>
79+
service: <port name of memcached service>
80+
```
81+
1. Configure the query result cache
82+
```yaml
83+
query_range:
84+
cache_results: true
85+
results_cache:
86+
cache:
87+
memcached_client:
88+
consistent_hash: true
89+
host: <memcached host>
90+
service: <port name of memcached service>
91+
max_idle_conns: 16
92+
timeout: 500ms
93+
update_interval: 1m
94+
```

0 commit comments

Comments
 (0)