-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Limit Redis memory usage to 25% of system RAM #3907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…etting max memory using container's available memory. Removed unused `redis.conf`.
…ty and maintainability.
Are we sure this is true for self-hosted? Also I checked two self-hosted instances and one of them is using 20MB and the other is using 40MB :) |
@kixorz Which version is self-hosted are you on? I remember we had a memory leak problem with redis about two or three years ago, but it got fine after a couple of releases, unfortunately I cannot remember the exact version. And I was wondering why your redis instance got OOMed? |
Hey, thanks for the question. We ran out of disk space, Sentry stopped working. When we rebooted, redis allocated all available memory on the system and the machine hung. We had to double the RAM to make it work again. After it started to work, we modified the RAM back. Redis exhausted the memory again when it was trying to start back up. This is because its disk database is already as big as the highest RAM value from the previous start. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think redis usage is relevant to total memory of server, so there is no need for it to be 1 / 4 of total memory.
On another note some users may have changed their redis.conf
locally and this change breaks them.
It'll be nice if we have a estimation of how redis uses memory and set a maxmemory
suitable for that usage, for example if self-hosted redis is using 2GB memory at max for example, we can just set maxmemory
to 4GB.
Also copying this from original PR which created The default value of the maxmemory setting in Redis depends on the system architecture:
I believe we can set the default value to unlimited, allowing users to adjust this setting as needed based on their specific requirements. Originally posted by @Hassanzadeh-sd in #3427 (comment) |
The problem is that with maxmemory 0 there is no cap on redis memory use. There are situations where redis will use all available memory - for example after the system runs out of disk space. This hangs the system. If the solution is to modify the conf file, feel free to close this. |
It's fine to set an appropriate limit on redis
We can change this PR to set the limit in |
👎🏻 on this. We should just let people change the redis config. @kixorz if you feel strongly about the env variable you can also use |
@BYK How do you feel about a default redis |
Don't have enough ops expertise to make an intelligent comment about this 😅 |
Limit Redis memory usage to 25% of system RAM and enable eviction policy to prevent OOM.
Summary
This PR configures Redis in our Docker Compose deployment to use a bounded amount of memory (25% of the container’s available RAM) and enables an eviction policy. This reduces the risk of Redis consuming all available memory, triggering out-of-memory (OOM) conditions, and forcing costly instance size increases in cloud environments.
What changed
volatile-lru
so Redis evicts the least recently used keys that have an expiration set when under memory pressure.Why this is needed
How it works
/proc/meminfo
and compute 25% for--maxmemory
.--maxmemory-policy volatile-lru
to evict the least recently used keys among those with TTLs when approaching the memory cap.Impact
volatile-lru
. If the dataset is dominated by non-expiring keys, you may want a different policy (see below).Configuration and overrides
volatile-lru
./3
or/2
instead of/4
).--maxmemory-policy volatile-lru
with one of Redis’s supported policies (e.g.,allkeys-lru
,volatile-ttl
,allkeys-random
,noeviction
, etc.).--maxmemory 2gb
.Risks and trade-offs
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.