【问题标题】:Do I still need to set maxmemory if I put a memory limit on the container for Redis server?如果我对 Redis 服务器的容器设置了内存限制,是否还需要设置 maxmemory?
【发布时间】:2022-01-20 08:01:47
【问题描述】:

我想将 Redis 配置为 LRU 缓存。我想避免重复自己的内存限制。如果我这样做了

command: redis-server --maxmemory-policy allkeys-lru 
deploy:
  resources:
    limits:
      memory: 1.5G

这样就够了还是我真的需要放入这样的东西(我为操作系统等使用了稍小的尺寸)

command: redis-server --maxmemory-policy allkeys-lru --maxmemory 1.4G
deploy:
  resources:
    limits:
      memory: 1.5G

【问题讨论】:

    标签: docker redis


    【解决方案1】:

    检查 redis-cli info memory 它显示总内存为完整系统大小,因此很可能没有 maxmemory 它将使用该值。

    但是,使用getting the memory limit from inside the container 和一点bash 算术,您可以创建一个可以完成工作的命令,因此操作只需要调整一个数字而不是使用command。并结合a proper HEALTHCHECK for Redis

    services:
     cache:
        image: redis:6
        command:
          - bash
          - -c
          - redis-server --appendonly yes --maxmemory $$(( $$( cat /sys/fs/cgroup/memory/memory.limit_in_bytes ) - 100000000)) --maxmemory-policy volatile-lru
        healthcheck:
          test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
        networks:
          - default
        deploy:
          resources:
            limits:
              memory: 512M
    

    这会将最大内存设置为撰写文件中定义的内存减去 100MB 的开销。

    【讨论】:

      猜你喜欢
      • 2013-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-23
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2019-12-14
      相关资源
      最近更新 更多