无法删除节点 Zookeeper: Packet len5391978 is out of range
问题今天在对Zookeeper进行性能测试, 在/zktest节点下建了16W个节点,每个节点名为30个字符 然后进行删除时出现Packet len5391978 is out of range的错误, 导致不能获取节点列表, 也不能删除节点.
问题
今天在对Zookeeper进行性能测试, 在/zktest节点下建了16W个节点,每个节点名为30个字符 然后进行删除时出现Packet len5391978 is out of range的错误, 导致不能获取节点列表, 也不能删除节点.
[zk: localhost:2181(CONNECTED) 0] ls /zktest
2016-10-15 04:38:07,650 [myid:] - WARN [main-SendThread(localhost:2181):ClientCnxn$SendThread@1162] - Session 0x157c679b965000a for server localhost/127.0.0.1:2181, unexpected error, closing socket connection and attempting reconnect
java.io.IOException: Packet len5391978 is out of range!
at org.apache.zookeeper.ClientCnxnSocket.readLength(ClientCnxnSocket.java:112)
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:79)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:366)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
stackoverflow
Stackoverflow上有一个解答
Zookeeper CLI failing - IOException Packet is out of range
因为每次返回信息, 都要先读取信息的大小, 如果大于默认的4M, 那么就失败.
public static final int packetLen = Integer.getInteger("jute.maxbuffer",
4096 * 1024);
protected void readLength() throws IOException {
int len = incomingBuffer.getInt();
if (len < 0 || len >= ClientCnxn.packetLen) {
throw new IOException("Packet len" + len + " is out of range!");
}
incomingBuffer = ByteBuffer.allocate(len);
}
解决方法
可以通过改变jute.maxbuffer这个System properties, 来接收超过4096*1024大小的包.
使用zkCli.sh:在zkCli.sh中加入-Djute.maxbuffer=40960000
“$JAVA” “-Dzookeeper.log.dir=${ZOO_LOG_DIR}” “-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}” “-Djute.maxbuffer=40960000” \
-cp “$CLASSPATH” $CLIENT_JVMFLAGS $JVMFLAGS \
org.apache.zookeeper.ZooKeeperMain “$@”
或者在程序中, 生成Zookeeper对象前调用
System.setProperty(“jute.maxbuffer”, “40960000”);
总结
对zookeeper进行操作出现Packet len5391978 is out of range, 是因为返回的数据包太大, zookeeper为了提高吞吐量, 对数据包大小进行了限制, 返回数据包大小最大为4096*1024, 而节点最大数据量则为1M
更多推荐
所有评论(0)