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...


Mar 02

Icinga 2 Fundamentals Training | Online

March 2 @ 09:00 - March 5 @ 17:00
Mar 09

Ansible Fundamentals Training | Online

March 9 @ 09:00 - March 11 @ 17:00
Mar 12

Ansible AWX (Tower) Training | Online

March 12 @ 09:00 - 17:00
Mar 23

GitLab Advanced Training | Online

March 23 @ 08:00 - March 25 @ 17:00
Mar 23

Ansible Advanced Training | Online

March 23 @ 09:00 - March 24 @ 17:00