xmemcached timeout

发布于 2021-11-23 11:51:47 字数 5604 浏览 865 评论 5

各位好!最近在弄memcached2.0,客户端采用xmemcached,但是会遇到读取数据超时的情况!

采用magent代理;客户端连接magent服务;


初始化方法:

public void init() {
/** 设置与缓存服务器的连接池 */
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddressMap(serverAddress));
try {
//启用failure模式。
builder.setFailureMode(true);
builder.setSessionLocator(new KetamaMemcachedSessionLocator());
builder.setConnectionPoolSize(poolSize);
builder.setHealSessionInterval(healConnectionInterval);
mcc = builder.build();
if(mcc!=null){
mcc.setConnectTimeout(soTimeout);
mcc.setOpTimeout(soTimeout);
}
log.info("Memcache initialization successful!"+serverAddress);
} catch (IOException e) {
log.error("初始化memcache连接失败:" + e.getLocalizedMessage(), e);
}
}



/**
* 根据指定的关键字获取对象. 内部测试方法, 准备删除.

* @param key
* @return
* @throws MemcachedException
* @throws InterruptedException
* @throws TimeoutException
*/
public Object get(String key) throws Exception {
try {
return mcc.get(key);
} catch (TimeoutException e) {
String message = "读取缓存超时key="+key;
log.error(message, e);
throw new Exception(message, e);
} catch (InterruptedException e) {
String message = "读取缓存被打断key="+key;
log.error(message, e);
throw new Exception(message, e);
} catch (MemcachedException e) {
String message = "读取缓存异常key="+key;
log.error(message, e);
throw new Exception(message, e);
}


}

错误描述: 在本地循环测试始终不能浮现,在测试环境,c++ 写入缓存后发送消息至 我这边,然后读取指定key,有时候能读取到数据,有时候会不会超时,超时比较频繁;每条数据大小也就只有几k;另外日志会显示客户端4次心跳失败;

java.lang.Exception: 读取缓存超时key=xxxxxx
at com.palmcity.memached.MemcacheManager.get(MemcacheManager.java:410)
at com.palmcity.bus.handler.thrift.ThriftBusArrivalHandler.handler(ThriftBusArrivalHandler.java:48)
at com.palmcity.bus.handler.thrift.ThriftServerImpl.sendCommand(ThriftServerImpl.java:51)
at com.palmcity.bus.servers.ThriftCommandService$Processor$sendCommand.getResult(ThriftCommandService.java:175)
at com.palmcity.bus.servers.ThriftCommandService$Processor$sendCommand.getResult(ThriftCommandService.java:1)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:225)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.util.concurrent.TimeoutException: Timed out(50000 milliseconds) waiting for operation while connected to 192.168.3.101:12000
at net.rubyeye.xmemcached.XMemcachedClient.latchWait(XMemcachedClient.java:2536)
at net.rubyeye.xmemcached.XMemcachedClient.fetch0(XMemcachedClient.java:644)
at net.rubyeye.xmemcached.XMemcachedClient.get0(XMemcachedClient.java:1058)
at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1016)
at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1027)
at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1049)
at com.palmcity.memached.MemcacheManager.get(MemcacheManager.java:406)
... 10 more


java.lang.Exception: 读取缓存超时key=xxxxxx
at com.palmcity.memached.MemcacheManager.get(MemcacheManager.java:410)
at com.palmcity.bus.handler.thrift.ThriftBusArrivalHandler.handler(ThriftBusArrivalHandler.java:48)
at com.palmcity.bus.handler.thrift.ThriftServerImpl.sendCommand(ThriftServerImpl.java:51)
at com.palmcity.bus.servers.ThriftCommandService$Processor$sendCommand.getResult(ThriftCommandService.java:175)
at com.palmcity.bus.servers.ThriftCommandService$Processor$sendCommand.getResult(ThriftCommandService.java:1)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:225)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.util.concurrent.TimeoutException: Timed out(5000 milliseconds) waiting for operation while connected to 192.168.3.101:12000
at net.rubyeye.xmemcached.XMemcachedClient.latchWait(XMemcachedClient.java:2536)
at net.rubyeye.xmemcached.XMemcachedClient.fetch0(XMemcachedClient.java:644)
at net.rubyeye.xmemcached.XMemcachedClient.get0(XMemcachedClient.java:1058)
at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1016)
at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1027)
at net.rubyeye.xmemcached.XMemcachedClient.get(XMemcachedClient.java:1049)
at com.palmcity.memached.MemcacheManager.get(MemcacheManager.java:406)
... 10 more


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

瀞厅☆埖开 2021-11-29 20:49:56

不是哈。

情绪失控 2021-11-29 20:32:25

不是防火墙问题?

为你鎻心 2021-11-29 17:27:22

不好意思,弄错了。。默认心跳也是开启的/。

回眸一笑 2021-11-29 13:10:34

如果不使用心跳的话,连接池就没有意义了。memcached 服务挂掉之后,不会自动恢复连接。难道还得重启应用?

无法言说的痛 2021-11-28 06:54:51

引用来自“dennis_zhuang”的评论

你确认下 magent 是否支持 version 协议吧。如果不支持,禁用心跳:

mcc.setEnableHeartBeat(false);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文