我正在使用 red:set_keepalive(max_idle_timeout, pool_size)
(来自这里:https://github.com/openresty/lua-resty-redis#set_keepalive)
使用 Nginx 并尝试确定用于 max_idle_timeout 和 pool_size 的最佳值。
如果我的 worker_connections 设置为 1024,那么将 pool_size 设置为 1024 是否有意义?
对于 max_idle_timeout,60000(1 分钟)是不是太“激进”了?使用较小的值是否更安全?
谢谢,
马特
最佳答案
我认为Check List for Issues官方文档的一部分有一个很好的连接池大小指南:
Basically if your NGINX handle
n
concurrent requests and your NGINX hasm
workers, then the connection pool size should be configured asn/m
. For example, if your NGINX usually handles 1000 concurrent requests and you have 10 NGINX workers, then the connection pool size should be 100.
因此,如果您预计有 1024 个并发请求实际连接到 Redis,那么您的池的合适大小是 1024/worker_processes
。可能还有一些是为了解决工作人员之间请求分配不均的问题。
您的 keepalive 应该足够长以说明流量到达的方式。如果您的流量稳定,那么您可以降低超时时间。或者保持 60 秒,在大多数情况下,更长的超时不会产生任何明显的差异。
关于nginx - lua-resty-redis set_keepalive 推荐设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52750688/