Memcached 服务器故障转移
我在使用 pecl/memcached 客户端时遇到了一个奇怪的问题。在我的设置中,我有 3 个 memcached 服务器。当我停止(这是一个 ec2 实例)其中一台 memcached 服务器来模拟完全故障时,“get”操作需要 4 秒才能完成。如何强制它提前超时?
以下是一些代码片段:
$this->memcache = new Memcached;
$this->memcache->setOption(Memcached::OPT_DISTRIBUTION ,Memcached::DISTRIBUTION_CONSISTENT);
$this->memcache->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE ,TRUE);
...
foreach($CFG->data_memcache_servers as $server){
if (!$this->memcache->addserver($server,11211)){
throw new Exception('Unable to connect to memcache server');
}
}
...
$data = $this->memcache->get($key);
I'm running into an odd issue with pecl/memcached client. In my setup, I have 3 memcached servers. When I stop (this is an ec2 instance) one of the memcached servers to simulate a complete failure, the "get" operation takes 4 seconds to complete. How do I force it to timeout earlier?
Here are some code snippets:
$this->memcache = new Memcached;
$this->memcache->setOption(Memcached::OPT_DISTRIBUTION ,Memcached::DISTRIBUTION_CONSISTENT);
$this->memcache->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE ,TRUE);
...
foreach($CFG->data_memcache_servers as $server){
if (!$this->memcache->addserver($server,11211)){
throw new Exception('Unable to connect to memcache server');
}
}
...
$data = $this->memcache->get($key);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,所有超时设置为 50 毫秒,在没有 memcached(或 memcached 停止)的服务器上执行 set(),set() 或 get() 需要 21 秒。
这似乎是 libmemcached 中的一个错误,我们可以在这里看到:
https://bugs.launchpad.net/libmemcached/+bug/778777
(以及许多其他网站)
我正在 Debian 上工作,libmemcached 是 0.40,并且该错误似乎至少到 0.49 为止(用于自动驱逐坏服务器)。
Debian不稳定有0.44,它正确响应CONNECT_TIMEOUT值。
I'm experiencing the same issue, with all timeouts set to 50ms, a set() on a server without memcached (or memcached stopped), a set() or a get() take 21 seconds.
It seems to be a bug in libmemcached, as we can see here:
https://bugs.launchpad.net/libmemcached/+bug/778777
(and many other websites)
I'm working on Debian, libmemcached is 0.40, and the bug seems to be at least until 0.49 (for auto eviction of bad servers).
Debian unstable has 0.44, which responds correctly to the CONNECT_TIMEOUT value.
试试这个
addserver
语法Try this
addserver
syntaxePECL Memcached 2.0 之前的版本不支持 addServer() 中与故障转移/超时相关的参数。如果您坚持使用 1.0.x 版本(例如 Ubuntu 10.04 LTS 中提供的版本),这是提供从单个主服务器到单个故障转移服务器的故障转移支持的简单方法:
PECL Memcached prior 2.0 doesn't support failover/timeout-relevant parameters in addServer(). If you are stuck with version 1.0.x (as shipped in Ubuntu 10.04 LTS for instance), this is a simple way of providing failover support from a single main server to a single failover server: