← Redis maxmemory calculator

How the Redis calculator works

This page walks through how the Redis calculator turns your used_memory into maxmemory and the memory to give the Redis process. It starts from the shared sizing model; this page covers what happens after that. Statements backed by the Redis documentation end with a Redis docs link to it. Choices the documentation doesn't make for us are explained and marked Assumption, which links to its row in the table of all of them.

01 maxmemory and the eviction policy

  • maxmemory is the most memory Redis uses for data; past it Redis applies the eviction policy. 0 means no limit, the default on 64-bit systems. Redis docs
  • allkeys-lru evicts the least recently used keys, and Redis calls it a good default when you have no reason to prefer another. noeviction instead returns errors for writes at the limit. Redis docs The calculator writes allkeys-lru, taking this Redis to be a cache. Assumption
  • Buffers for replication and the AOF don't count towards maxmemory, so Redis can use somewhat more. Redis docs

02 From used_memory to maxmemory

maxmemory           = max(peak × (1 + limit margin), average × (1 + request margin))   rounded up to a whole mb
memory to provision = 2 × maxmemory

The margins come from the sensitivity, workload type and environment you choose; the sizing model explains them, and they are assumptions too. In Redis's configuration, mb is 1024 × 1024 bytes, so MiB pass through unconverted. Redis docs

The samples are used_memory, which includes Redis's own overhead and not only the data, so a maxmemory sized from them is on the generous side. Assumption

Worked example

A cache peaking at 630 MiB of used_memory, medium sensitivity, production:

maxmemory630 MiB × 1.30 = 819 MiB819mb
memory to provision2 × 8191638 MiB

A steady cache, averaging 1000 MiB with a 1010 MiB peak at high sensitivity, where the average decides:

maxmemory1000 MiB × 1.55 = 1550 MiB, above 1010 × 1.40 = 14141550mb
memory to provision2 × 15503100 MiB

03 Memory for the process

  • In a write-heavy application, Redis can use up to twice its normal memory while it saves an RDB file or rewrites the AOF, because the forked child shares pages that writes then copy. Redis docs
  • With replication, Redis makes RDB saves even with persistence off, unless replication is diskless. Redis docs
  • Redis also advises setting maxmemory below the free memory, to leave room for its overhead and fragmentation: with 10 GB free, set it to 8 or 9 GB. Redis docs

So the calculator provisions the worst case, 2 × maxmemory. Assumption Without persistence or replication, the note suggests about 1.25 × maxmemory, which is Redis's 10-to-8 ratio turned around. Assumption

04 What the calculator writes

maxmemory 819mb
maxmemory-policy allkeys-lru
  • Both lines go in redis.conf, or at runtime with CONFIG SET maxmemory 819mb, as the eviction guide shows. Redis docs
  • CONFIG SET takes effect from the next command, and CONFIG REWRITE writes the running configuration back to the redis.conf the server started with. Redis docs

05 Every warning, and why

Message aboutShown whenBasis
Peak below average error The peak you entered is lower than the average Impossible with real samples; it usually means two different series. See the sizing model.

06 What to paste

redis_memory_used_bytes{instance="redis:6379"}
  • redis_exporter publishes INFO's used_memory as redis_memory_used_bytes. redis_exporter source
  • Without it, sample redis-cli INFO memory and paste the used_memory: lines; the calculator reads them as bytes.

07 All assumptions in one place

Besides the margins of the shared sizing model:

Our default: a value we chose. Our reading: how we read documentation that isn't explicit. About your setup: something we take for granted about your data or cluster.

AssumptionKindWhyIf it doesn't hold
Provision 2 × maxmemory ↩Our defaultRedis documents up to 2× during RDB saves and AOF rewritesA read-mostly Redis copies fewer pages during a fork and needs less.
About 1.25 × maxmemory without persistence or replication ↩Our readingRedis's example sets maxmemory to 8 of 10 GB freeWith 9 of 10 GB, the ratio is 1.11; more fragmentation needs more.
maxmemory from peak used_memory ↩Our defaultused_memory is the figure INFO and exporters giveIt includes overhead beyond the data, so maxmemory comes out a little high.
This Redis is a cache ↩About your setupThat's what an eviction policy is forFor data you can't lose, use noeviction so writes fail at the limit instead.

Values you can change

The calculator’s Advanced: margins and defaults section, closed by default, lets you replace these values when your setup differs. Each field’s “?” says how it moves the result; a value outside the range is used at its nearest end, and “Reset to defaults” puts them all back.

ValueDefaultRangeWhere the default comes from
Request marginfrom the profile0–200%MemoryLimit’s default, from sensitivity, workload type and environment (sizing model); sizes the floor of maxmemory
Limit marginfrom the profile0–200%MemoryLimit’s default, from sensitivity, workload type and environment (sizing model); sizes maxmemory
Provisioning factor2 × maxmemory1–3×Redis documents up to 2× during RDB saves and AOF rewrites, assumption 1; about 1.25× without persistence or replication, assumption 2

08 References

← Back to the Redis calculator