26

简单设置:

  • 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

4

2 回答 2

1

I can't see anything wrong with your configuration. As you know the important settings are in place:

default:
  auto_eject_hosts: true
  server_failure_limit: 1

The documentation suggests connection timeouts might be an issue.

Relying only on client-side timeouts has the adverse effect of the original request having timedout on the client to proxy connection, but still pending and outstanding on the proxy to server connection. This further gets exacerbated when client retries the original request.

Is your PHP script closing the connection and retrying before twemproxy failed its first attempt and removed the server from the pool? Perhaps adding a timeout value in the twemproxy lower than the connection timeout used in PHP solves the issue.

From your discussion on Github though it sounds like support for healthcheck, and perhaps auto ejection, aren't stable in twemproxy. If you're building against old packages you might be better to find a package which has been stable for some time. Is mcrouter (with interesting article) suitable?

于 2015-11-12T13:43:16.243 回答
0

要使此功能正常工作,请与此 repo/branch 合并

https://github.com/charsyam/twemproxy/tree/feature/heartbeat

有这个特定的提交

https://github.com/charsyam/twemproxy/commit/4d49d2ecd9e1d60f18e665570e4ad1a2ba9b65b1

这是公关

https://github.com/twitter/twemproxy/pull/428

之后重新编译它

于 2016-08-28T14:07:07.500 回答