ahww520 / xmemcached

Automatically exported from code.google.com/p/xmemcached
Apache License 2.0
0 stars 0 forks source link

高并发下XMemcache会出现点问题. #192

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
首先膜拜下 killme2008. 
看源码的时候既然发现有中文注释,太高兴了,这么强悍的XMemca
ched既然是 Made In China !!!

我在使用XMemcached 的 inrc方法的时候出现一点小问题 
(XMemcached-Version:1.3.5):
初始化:
transcoder = new SerializingTranscoder();
builder.setSessionLocator(new KetamaMemcachedSessionLocator());
builder.setCommandFactory(new BinaryCommandFactory());
这是几个主要的初始化类.

在调用 client.incr(key, delta) 的时候会出现问题:

如果 client.set(key,data) 初始化一个key的时候,将data 
设置为整形的数字,比如直接1,2,3之类的,然后再incr 
就会出现错误,或者是 
incr返回的结果完全错误.只能在set初始化一个key的时候将整形
的转换成字符串,例如 "1","2" 
这样才不会出现问题.结果也是正确的.但是在高并发下会出现
下面这个异常:

net.rubyeye.xmemcached.exception.MemcachedServerException: Incr/Decr on 
non-numeric value.
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.readStatus(BaseBinaryCommand.java:251)
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.readHeader(BaseBinaryCommand.java:182)
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.decode(BaseBinaryCommand.java:121)
        at net.rubyeye.xmemcached.codec.MemcachedDecoder.decode0(MemcachedDecoder.java:59)
        at net.rubyeye.xmemcached.codec.MemcachedDecoder.decode(MemcachedDecoder.java:54)
        at com.google.code.yanf4j.nio.impl.NioTCPSession.decode(NioTCPSession.java:288)
        at com.google.code.yanf4j.nio.impl.NioTCPSession.readFromBuffer(NioTCPSession.java:205)
        at com.google.code.yanf4j.nio.impl.AbstractNioSession.onRead(AbstractNioSession.java:198)
        at com.google.code.yanf4j.nio.impl.AbstractNioSession.onEvent(AbstractNioSession.java:343)
        at com.google.code.yanf4j.nio.impl.SocketChannelController.dispatchReadEvent(SocketChannelController.java:56)
        at com.google.code.yanf4j.nio.impl.NioController$ReadTask.run(NioController.java:110)
        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:619)
[ERROR] 2012-04-21 09:10:21 [net.rubyeye.xmemcached.impl.MemcachedHandler:111] 
- XMemcached network layout exception
net.rubyeye.xmemcached.exception.MemcachedDecodeException: Not a proper response
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.readMagicNumber(BaseBinaryCommand.java:305)
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.readHeader(BaseBinaryCommand.java:174)
        at net.rubyeye.xmemcached.command.binary.BinaryStoreCommand.readHeader(BinaryStoreCommand.java:67)
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.decode(BaseBinaryCommand.java:121)
        at net.rubyeye.xmemcached.codec.MemcachedDecoder.decode0(MemcachedDecoder.java:59)
        at net.rubyeye.xmemcached.codec.MemcachedDecoder.decode(MemcachedDecoder.java:54)
        at com.google.code.yanf4j.nio.impl.NioTCPSession.decode(NioTCPSession.java:288)
        at com.google.code.yanf4j.nio.impl.NioTCPSession.readFromBuffer(NioTCPSession.java:205)
        at com.google.code.yanf4j.nio.impl.AbstractNioSession.onRead(AbstractNioSession.java:198)
        at com.google.code.yanf4j.nio.impl.AbstractNioSession.onEvent(AbstractNioSession.java:343)
        at com.google.code.yanf4j.nio.impl.SocketChannelController.dispatchReadEvent(SocketChannelController.java:56)
        at com.google.code.yanf4j.nio.impl.NioController$ReadTask.run(NioController.java:110)
        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:619)
[ERROR] 2012-04-21 09:10:21 
[com.google.code.yanf4j.core.impl.AbstractSession:301] - Decode error
net.rubyeye.xmemcached.exception.MemcachedDecodeException: Not a proper response
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.readMagicNumber(BaseBinaryCommand.java:305)
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.readHeader(BaseBinaryCommand.java:174)
        at net.rubyeye.xmemcached.command.binary.BinaryStoreCommand.readHeader(BinaryStoreCommand.java:67)
        at net.rubyeye.xmemcached.command.binary.BaseBinaryCommand.decode(BaseBinaryCommand.java:121)
        at net.rubyeye.xmemcached.codec.MemcachedDecoder.decode0(MemcachedDecoder.java:59)
        at net.rubyeye.xmemcached.codec.MemcachedDecoder.decode(MemcachedDecoder.java:54)
        at com.google.code.yanf4j.nio.impl.NioTCPSession.decode(NioTCPSession.java:288)
        at com.google.code.yanf4j.nio.impl.NioTCPSession.readFromBuffer(NioTCPSession.java:205)
        at com.google.code.yanf4j.nio.impl.AbstractNioSession.onRead(AbstractNioSession.java:198)
        at com.google.code.yanf4j.nio.impl.AbstractNioSession.onEvent(AbstractNioSession.java:343)
        at com.google.code.yanf4j.nio.impl.SocketChannelController.dispatchReadEvent(SocketChannelController.java:56)
        at com.google.code.yanf4j.nio.impl.NioController$ReadTask.run(NioController.java:110)
        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:619)
net.rubyeye.xmemcached.exception.MemcachedException: Session has been closed
        at net.rubyeye.xmemcached.impl.MemcachedTCPSession.destroy(MemcachedTCPSession.java:110)
        at net.rubyeye.xmemcached.impl.MemcachedHandler.onSessionClosed(MemcachedHandler.java:136)
        at com.google.code.yanf4j.core.impl.AbstractSession.onClosed(AbstractSession.java:305)
        at com.google.code.yanf4j.core.impl.AbstractSession.close(AbstractSession.java:293)
        at com.google.code.yanf4j.nio.impl.NioTCPSession.decode(NioTCPSession.java:302)
        at com.google.code.yanf4j.nio.impl.NioTCPSession.readFromBuffer(NioTCPSession.java:205)
        at com.google.code.yanf4j.nio.impl.AbstractNioSession.onRead(AbstractNioSession.java:198)
        at com.google.code.yanf4j.nio.impl.AbstractNioSession.onEvent(AbstractNioSession.java:343)
        at com.google.code.yanf4j.nio.impl.SocketChannelController.dispatchReadEvent(SocketChannelController.java:56)
        at com.google.code.yanf4j.nio.impl.NioController$ReadTask.run(NioController.java:110)
        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:619)

目前解决的办法就是每天定时清理所有incr 的 
key,否则日志就会刷屏,全是这个异常,这三段 
异常每次都是一起按顺序出现的..

期待您的 修复. 谢谢!!!

Original issue reported on code.google.com by libtian@gmail.com on 21 Apr 2012 at 1:44

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
MemcachedClient client = builder.build();

Original comment by libtian@gmail.com on 21 Apr 2012 at 1:48

GoogleCodeExporter commented 8 years ago
请问你的xmemcached版本是多少,你确认你的value都是字符串吗��
� 
inc/dec只能作用在字符串的value上,这并非xmemcached的限制,而�
��memcached本身这样设计的。我怀疑你还是有value不是字符串,�
��会抛出Incr/Decr on non-numeric 
value.这样的错误,这个错误是memcached服务器返回的。

建议你检查自己的代码,确认没有非字符串的value做inc/dec
其次,也可以尝试不要用binary协议,而用默认的文本协议实��
�,性能更好。

Original comment by killme2...@gmail.com on 24 Apr 2012 at 4:38

GoogleCodeExporter commented 8 years ago

Original comment by killme2...@gmail.com on 7 Jun 2012 at 10:30