Redis容器停止了很长时间。

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

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:


# 模块
loadmodule /usr/lib/redis/modules/redisearch.so
loadmodule /usr/lib/redis/modules/rejson.so
loadmodule /usr/lib/redis/modules/redistimeseries.so

port 0
tls-port 6379

tls-cert-file /certs/server.crt
tls-key-file /certs/server.key
tls-ca-cert-file /certs/ca.crt
tls-dh-params-file /certs/redis.dh

maxmemory 256mb

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:

loglevel notice

# Modules
loadmodule /usr/lib/redis/modules/redisearch.so
loadmodule /usr/lib/redis/modules/rejson.so
loadmodule /usr/lib/redis/modules/redistimeseries.so

port 0
tls-port 6379

tls-cert-file /certs/server.crt
tls-key-file /certs/server.key
tls-ca-cert-file /certs/ca.crt
tls-dh-params-file /certs/redis.dh

maxmemory 256mb

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:

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

Old start-redis.sh:

#!/usr/bin/env bash

redis-server /usr/local/etc/redis/redis.conf

New start-redis.sh:

#!/usr/bin/env bash

# [ Some work... ]

# Define cleanup function
stop_redis() {
    echo "==========   Stopping Redis server...   =========="
    redis-cli shutdown
    exit 0
}

# Trap SIGINT and SIGTERM signals and run cleanup function
trap stop_redis SIGINT
trap stop_redis SIGTERM

# Start redis
redis-server /usr/local/etc/redis/redis.conf &
wait %?redis-server
英文:

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

Dockerfile:

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

Old start-redis.sh:

#!/usr/bin/env bash

redis-server /usr/local/etc/redis/redis.conf

New start-redis.sh:

#!/usr/bin/env bash

# [ Some work... ]

# Define cleanup function
stop_redis() {
    echo "==========   Stopping Redis server...   =========="
    redis-cli shutdown
    exit 0
}

# Trap SIGINT and SIGTERM signals and run cleanup function
trap stop_redis SIGINT
trap stop_redis SIGTERM

# Start redis
redis-server /usr/local/etc/redis/redis.conf &
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:

确定