背景
在日常运维 ZooKeeper 中,经常会遇到长时间无法选主,恢复时进程启动又退出,进而导致内存暴涨,CPU 飙升,GC 频繁,影响业务可用性,这些问题有可能和 jute.maxbuffer 的设置有关。本篇文章就深入 ZooKeeper 源码,一起探究一下 ZooKeeper 的 jute.maxbuffer 参数的最佳实践。

1.png

2.png
分析
首先我们通过 ZooKeeper 的官网上看到 jute.maxbuffer 的描述:
jute.maxbuffer :
(Java system property: jute.maxbuffer).
......, It specifies the maximum size of the data that can be stored in a znode. The unit is: byte. The default is 0xfffff(1048575) bytes, or just under 1M.
When jute.maxbuffer in the client side is greater than the server side, the client wants to write the data exceeds jute.maxbuffer in the server side, the server side will get java.io.IOException: Len error
When jute.maxbuffer in the client side is less than the server side, the client wants to read the data exceeds jute.maxbuffer in the client side, the client side will get java.io.IOException: Unreasonable length or Packet len is out of range!
从官网的描述中我们可以知道,jute.maxbuffer 能够限制 Znode 大小,需要在 Server 端和 Client 端合理设置,否则有可能引起异常。
但事实并非如此,我们在 ZooKeeper 的代码中寻找 jute.maxbuffer 的