Select Page

Redis Eviction Policies

by | Feb 12, 2021 | Technology

After install Redis you don’t have any settings configured to control memory consumption. In Production this brings OOM to the arena which leads into a broken applications.

First thingy what users do is to configure MaxMemory config setting (like me of course ;-)). In combination with a noeviction policy (which is also the default) the documentation says:

[…] return errors when the memory limit was reached and the client is trying to execute commands that could result in more memory to be used (most write commands, but DEL and a few more exceptions).

The bad news is, you’ll have a broken application again. Most web apps just use Redis as an uncontrolled cache data sink and left over to you how to handle it. For 99.9% of the use-cases you just need to configure a cache policy, or in Redis-speech, an Eviction Policy, which means:

maxmemory 128mb
maxmemory-policy allkeys-lru
maxmemory-samples 10

1. You allow roughly 128MB of memory for Redis
2. Redis tries to remove the less recently used (LRU) keys first
3. Because LRU is not a exact LRU algo, you use 10 samples to help the algorithm to find the items

Try to explain by counters:

Icinga Redis Plugin Output:

Above is a icinga redis check plugin output. Which shows a roundabout memory use of 108% – which is more than the configured 128M 100% base.

Grafana Graph (Telegraf Redis Input Plugin)

Here is the config change made on the 02/04 down to 128M MaxMemory and the LRU Eviction Policy. The memory footprint stays the same. The change is more granular if you zoom in:

If the allkeys-lru does not work for you, give the documentation a try. There is a lot you can do to keep your applications up and running and make Redis a fluently easy dependency.

Marius Hein
Marius Hein
Head of ITSM

Marius Hein ist schon seit 2003 bei NETWAYS. Er hat hier seine Ausbildung zum Fachinformatiker absolviert, dann als Application Developer gearbeitet und ist nun Leiter der Softwareentwicklung. Ausserdem ist er Mitglied im Icinga Team und verantwortet dort das Icinga Web.
More posts on the topicTechnology

Administrators Toolbox: Die Zsh

Einfuehrung Zu jeder stereotypischen Hacking-Szene in einem Film oder einer Serie gehoert das Terminal in dem kryptische Ausdruecke, Befehle oder Programmcode ueber den Bildschirm huschen. Je nach Ausfuehrung ist das unterschiedlich laecherlich, aber nichtsdestotrotz...

Sync pictures older than one year between iPhone and Photo

I don't use the cloud to store my pictures so I have to sync the pictures between my Mac and my iPhone on a regular basis. No big hassle, because usually it works like a charm. The problem I have is that I want more pictures than last year, also I don't want to sync...

Ansible Host-Gruppen: Wer gehört zu wem?

Immer wieder kommt es vor, dass ich in größeren Ansible-Umgebungen arbeite. Diese enthalten eine Vielzahl von verschiedenen Gruppen im Inventory, die sich auch mal aus anderen Host-Gruppen zusammen setzen. Da ist es nicht immer leicht den Überblick zu behalten. Da...

NETWAYS ist offizieller Nextcloud-Partner

Nextcloud bietet die branchenführende lokale Plattform für Zusammenarbeit. „Nextcloud – a safe home for all your data“, das Unternehmensmotto von Nextcloud, überzeugte uns bei NETWAYS Web Services von Anfang an, sodass wir stolz sind, unsere bisher schon sehr gute...

Veranstaltungen

Tue 18

Icinga 2 Fundamentals Training | Online

May 18 @ 09:00 - May 21 @ 17:00
Jun 15

stackconf online

June 15 - June 17
Jun 22

Ansible Fundamentals Training | Online

June 22 @ 09:00 - June 24 @ 17:00
Jun 22

Kubernetes Quick Start | Online

June 22 @ 09:00 - 17:00
Jun 25

Ansible AWX (Tower) Training | Online

June 25 @ 09:00 - 17:00