简单设置:
- 1个运行twemproxy(vcache:22122)的节点
- 2个运行memcached(vcache-1、vcache-2)的节点,均监听11211端口
我有以下twemproxy配置:
default:
auto_eject_hosts: true
distribution: ketama
hash: fnv1a_64
listen: 0.0.0.0:22122
server_failure_limit: 1
server_retry_timeout: 600000 # 600sec, 10m
timeout: 100
servers:
- vcache-1:11211:1
- vcache-2:11211:1
twemproxy节点可以解析所有主机名。作为测试的一部分,我关闭了vcache-2。理论上,对于每次与vcache:22122接口的尝试,twemproxy将联系池中的服务器来促进尝试。但是,如果其中一个缓存节点宕机,则twemproxy应该将其从池中"自动弹出",以便后续请求不会失败。
由应用层确定与vcache:22122的接口尝试是否由基础设施问题导致,如果是,则再次尝试。然而,我发现在重试时,仍然使用相同的失败服务器,因此除了将后续尝试传递给已知的良好缓存节点(在这种情况下为vcache-1)外,它们仍然被传递给已弹出的缓存节点(vcache-2)。
以下是PHP代码片段,用于尝试重试:
....
// $this is a Memcached object with vcache:22122 in the server list
$retryCount = 0;
do {
$status = $this->set($key, $value, $expiry);
if (Memcached::RES_SUCCESS === $this->getResultCode()) {
return true;
}
} while (++$retryCount < 3);
return false;
-- 更新 --
有关更多信息,请查看在Github上开放的问题链接: 问题#427