Memcached错误:管道断开/对等方重置连接

时间:2018-09-25 06:28:19

标签: java linux memcached ubuntu-16.04

当我使用Java MemcachedClient(com.whalin.MemCached)设置巨大数据时,出现broken pipeConnection reset by peer错误。

这是我的配置文件。 [/etc/memcached.conf]

# memcached default config file
# 2003 - Jay Bonci <jaybonci@debian.org>
# This configuration file is read by the start-memcached script provided as
# part of the Debian GNU/Linux distribution.

# Run memcached as a daemon. This command is implied, and is not needed for the
# daemon to run. See the README.Debian that comes with this package for more
# information.
-d

# Log memcached's output to /var/log/memcached
logfile /var/log/memcached.log

# Be verbose
 -v

# Be even more verbose (print client commands as well)
 -vv

# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-m 4096

# Default connection port is 11211
-p 11311

# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
-u memcache

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l 127.0.0.1

# Limit the number of simultaneous incoming connections. The daemon default is 1024
# -c 1024

# Lock down all paged memory. Consult with the README and homepage before you do this
# -k

# Return error when memory is exhausted (rather than removing items)
# -M

# Maximize core file limit
# -r

即使将大小增加到4096,仍然会出现这些错误。

又一期: 即使没有注释,也无法获取日志文件

运行过程

memcache  9304     1  0 11:26 ?        00:00:00 /usr/bin/memcached -v -vv -m 4096 -p 11311 -u memcache -l 127.0.0.1

仅供参考:从数据库中读取50000条记录,添加到地图并将该地图存储到内存缓存中。

断管:

java.io.IOException: Broken pipe
        at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
        at sun.nio.ch.IOUtil.write(IOUtil.java:51)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
        at com.schooner.MemCached.SockOutputStream.writeToChannel(Unknown Source)
        at com.schooner.MemCached.SockOutputStream.write(Unknown Source)
        at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
        at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1189)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        at java.util.HashMap.internalWriteEntries(HashMap.java:1790)
        at java.util.HashMap.writeObject(HashMap.java:1363)
        at sun.reflect.GeneratedMethodAccessor100.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        at com.schooner.MemCached.ObjectTransCoder.encode(Unknown Source)
        at com.schooner.MemCached.AbstractTransCoder.encode(Unknown Source)
        at com.schooner.MemCached.AscIIClient.set(Unknown Source)
        at com.schooner.MemCached.AscIIClient.set(Unknown Source)
        at com.whalin.MemCached.MemCachedClient.set(Unknown Source)

用户重置连接

java.io.IOException: Connection reset by peer
        at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
        at sun.nio.ch.IOUtil.write(IOUtil.java:51)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
        at com.schooner.MemCached.SockOutputStream.writeToChannel(Unknown Source)
        at com.schooner.MemCached.SockOutputStream.write(Unknown Source)
        at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
        at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1189)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        at java.util.HashMap.internalWriteEntries(HashMap.java:1790)
        at java.util.HashMap.writeObject(HashMap.java:1363)
        at sun.reflect.GeneratedMethodAccessor100.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        at com.schooner.MemCached.ObjectTransCoder.encode(Unknown Source)
        at com.schooner.MemCached.AbstractTransCoder.encode(Unknown Source)
        at com.schooner.MemCached.AscIIClient.set(Unknown Source)
        at com.schooner.MemCached.AscIIClient.set(Unknown Source)
        at com.whalin.MemCached.MemCachedClient.set(Unknown Source)

1 个答案:

答案 0 :(得分:0)

我认为问题可能是您正在尝试将非常大的对象存储到内存缓存

默认情况下,内存缓存最多可设置1MB对象。在较新版本的内存缓存中,您可以设置-I选项以将大小增加到最大128MB。 (https://linux.die.net/man/1/memcached

我不推荐它。最好创建较小的对象。