xmemcached timeout
各位好!最近在弄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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不是哈。
不是防火墙问题?
不好意思,弄错了。。默认心跳也是开启的/。
如果不使用心跳的话,连接池就没有意义了。memcached 服务挂掉之后,不会自动恢复连接。难道还得重启应用?
引用来自“dennis_zhuang”的评论
你确认下 magent 是否支持 version 协议吧。如果不支持,禁用心跳:
mcc.setEnableHeartBeat(false);