Redis容器停止了很长时间。

huangapple go评论72阅读模式
英文:

Redis container stops for a long time

问题

我有一个与Redis相关的项目。当我停止或重启Docker Compose项目时,Redis Docker容器需要超过10秒才能停止(其他容器在1到2秒内停止)。与此同时,Redis容器启动几乎是立即的,但与其他容器停止相比需要更多的时间。将save设置为空字符串不产生影响。

使用save 60 1save 对停止时间没有影响。

与开发机器上的Node.js和Postgres容器相比,它需要大约多出10倍的时间(Mac M1 Pro和Linux Ryzen 3600 PC上的开发机器以及具有2个核心的"pet-production" Intel Xeon虚拟服务器)。

是否有方法可以加快停止容器或至少减少开发时的重新启动时间?我经常使用docker compose up -d --build,这需要额外的时间来重新启动Redis。

我不关心Redis数据。在开发环境中重新启动后可以删除它。

redis.conf:

  1. # 模块
  2. loadmodule /usr/lib/redis/modules/redisearch.so
  3. loadmodule /usr/lib/redis/modules/rejson.so
  4. loadmodule /usr/lib/redis/modules/redistimeseries.so
  5. port 0
  6. tls-port 6379
  7. tls-cert-file /certs/server.crt
  8. tls-key-file /certs/server.key
  9. tls-ca-cert-file /certs/ca.crt
  10. tls-dh-params-file /certs/redis.dh
  11. maxmemory 256mb
  12. save # 之前是:`save: 60 1` 与停止时间相同
英文:

I have a pet project with Redis. When I stop or restart docker compose project, it takes over 10 seconds to stop Redis Docker container (other containers stops within 1 or 2 seconds). Meanwhile Redis container starts almost immediately, it takes a lot of times compare to other containers to stop. Setting save to empty string does not effect.

With save 60 1 or save it does not take effect to time to stop.

Takes about 10 times more compare to node.js and Postgres containers on dev machines (Mac M1 Pro and Linux Ryzen 3600 PC) and "pet-production" Intel Xeon virtual server with 2 cores.

Is it way to boost stopping container or restart time for developing at least? I often use docker compose up -d --build and it takes some addition time to restart Redis.

I Does't care about Redis data. It can be deleted after restart on development envoronment.

redis.conf:

  1. loglevel notice
  2. # Modules
  3. loadmodule /usr/lib/redis/modules/redisearch.so
  4. loadmodule /usr/lib/redis/modules/rejson.so
  5. loadmodule /usr/lib/redis/modules/redistimeseries.so
  6. port 0
  7. tls-port 6379
  8. tls-cert-file /certs/server.crt
  9. tls-key-file /certs/server.key
  10. tls-ca-cert-file /certs/ca.crt
  11. tls-dh-params-file /certs/redis.dh
  12. maxmemory 256mb
  13. save # was: `save: 60 1` with the same time to stop

答案1

得分: 0

代码部分不需要翻译,以下是已翻译的内容:

It was a problem with bash script that does not process SIGTERM signal.

Dockerfile:

  1. ENTRYPOINT ["/app/start-redis.sh"]

Old start-redis.sh:

  1. #!/usr/bin/env bash
  2. redis-server /usr/local/etc/redis/redis.conf

New start-redis.sh:

  1. #!/usr/bin/env bash
  2. # [ Some work... ]
  3. # Define cleanup function
  4. stop_redis() {
  5. echo "========== Stopping Redis server... =========="
  6. redis-cli shutdown
  7. exit 0
  8. }
  9. # Trap SIGINT and SIGTERM signals and run cleanup function
  10. trap stop_redis SIGINT
  11. trap stop_redis SIGTERM
  12. # Start redis
  13. redis-server /usr/local/etc/redis/redis.conf &
  14. wait %?redis-server
英文:

It was a problem with bash script that does not process SIGTERM signal.

Dockerfile:

  1. ENTRYPOINT ["/app/start-redis.sh"]

Old start-redis.sh:

  1. #!/usr/bin/env bash
  2. redis-server /usr/local/etc/redis/redis.conf

New start-redis.sh:

  1. #!/usr/bin/env bash
  2. # [ Some work... ]
  3. # Define cleanup function
  4. stop_redis() {
  5. echo "========== Stopping Redis server... =========="
  6. redis-cli shutdown
  7. exit 0
  8. }
  9. # Trap SIGINT and SIGTERM signals and run cleanup function
  10. trap stop_redis SIGINT
  11. trap stop_redis SIGTERM
  12. # Start redis
  13. redis-server /usr/local/etc/redis/redis.conf &
  14. wait %?redis-server

huangapple
  • 本文由 发表于 2023年4月11日 02:00:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979515.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定