From c3814f08077ce42428af4c583699f810e8dba78e Mon Sep 17 00:00:00 2001 From: Sajjad hassanzadeh <32982356+Hassanzadeh-sd@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:13:58 +0330 Subject: [PATCH] feat: add Redis configuration for improved memory management (#3427) As Sentry continues to evolve, effective resource management becomes crucial for maintaining performance and stability. This update includes configurations that will help optimize Redis's memory usage, ensuring that the system runs efficiently under varying loads. **Key Changes:** - **Added `maxmemory` Directive**: Configured Redis to limit its memory usage to a specified size. This prevents excessive memory consumption and helps maintain system stability. - **Set `maxmemory-policy` to `allkeys-lru`**: This policy allows Redis to evict the least recently used keys when it reaches the memory limit, ensuring that frequently accessed data remains available while older, less-used data is removed. --- docker-compose.yml | 4 ++++ redis.conf | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 redis.conf diff --git a/docker-compose.yml b/docker-compose.yml index 9e4ae9d..b11db2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -110,6 +110,10 @@ services: test: redis-cli ping | grep PONG volumes: - "sentry-redis:/data" + - type: bind + read_only: true + source: ./redis.conf + target: /usr/local/etc/redis/redis.conf ulimits: nofile: soft: 10032 diff --git a/redis.conf b/redis.conf new file mode 100644 index 0000000..25103a8 --- /dev/null +++ b/redis.conf @@ -0,0 +1,26 @@ +# redis.conf + +# The 'maxmemory' directive controls the maximum amount of memory Redis is allowed to use. +# Setting 'maxmemory 0' means there is no limit on memory usage, allowing Redis to use as much +# memory as the operating system allows. This is suitable for environments where memory +# constraints are not a concern. +# +# Alternatively, you can specify a limit, such as 'maxmemory 15gb', to restrict Redis to +# using a maximum of 15 gigabytes of memory. +# +# Example: +# maxmemory 0 # Unlimited memory usage +# maxmemory 15gb # Limit memory usage to 15 GB + +maxmemory 0 + +# maxmemory-policy allkeys-lru +# +# This setting determines how Redis evicts keys when it reaches the memory limit. +# 'allkeys-lru' evicts the least recently used keys from all keys stored in Redis, +# allowing frequently accessed data to remain in memory while older data is removed. +# +# Example: +# maxmemory-policy allkeys-lru # Use LRU eviction for all keys + +maxmemory-policy allkeys-lru