我的团队有一个使用Lumen的项目(这是一个基于Laravel的微观框架)。我们使用Predis连接我们的Redis集群并在其上运行一些队列作业。但有时(我们不能重新生成)系统会抛出“CLUSTER SLOTS
池中没有剩下的连接。”异常
[2017-08-17 14:05:35] bookmark.ALERT: Predis\ClientException: No connections
left in the pool for `CLUSTER SLOTS` in
....../vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php:232
Stack trace:
#0 ....../vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(260):
Predis\Connection\Aggregate\RedisCluster->queryClusterNodeForSlotsMap(NULL)
#1 ....../vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(560):
Predis\Connection\Aggregate\RedisCluster->askSlotsMap()
...
我们调查了很长时间。我们认为问题可能在于Laravel的Predis库,以及它维护连接池的方式。这可能是因为Redis集群由于某种原因关闭了连接,但是Predis库在尝试连接时没有重新打开连接。
下面是我们的集群设置结构:
'redis' => [
'client' => 'predis',
'clusters' => [
// Setting for Queue
'default' => [
'options' => [ 'cluster' => 'redis' ],
[
'host' => 'xxx',
'password' => 'xxx',
'port' => 'xxx',
'timeout' => 0.15,
'read_write_timeout' => 0.15
],
[
'host' => 'xxx',
'password' => 'xxx',
'port' => 'xxx',
'timeout' => 0.15,
'read_write_timeout' => 0.15
],
...
]
]
]
有人知道吗?非常感谢!
发布于 2017-09-20 04:49:57
因为您只是间歇性地看到这些异常,所以'redis'
配置中的超时值可能太低。我只能猜测,PHP和Redis服务器之间网络上的大量通信会减缓通信速度,从而导致客户端连接超时(按配置的0.15
秒之后)。
当Predis客户端无法从所有配置的Redis主机获取插槽映射时,它将抛出No connections,当它从所有配置的Redis主机获取时隙映射时(可能是因为它们都超时了)。您可以通过设置一个非常小的超时值(如0.0001
)来再现此行为。
尝试增加超时值,并考虑监视网络中可能导致延迟的问题。
https://stackoverflow.com/questions/45807401
复制相似问题