1. Set the leader in the cluster to not accept client connections, and let it focus on cluster communication, election and other operations
How to set:
Add in zoo.cfg
leaderServes=no
2. In a large-scale production system, there will be many zookeeper machines. Because of the principle of more than half of the election, each election requires a lot of network communication. If the concurrency is high and the request is large, the performance will be greatly reduced. For this, zookeeper adds an observation. The observer, it does not participate in elections, but can accept connections from clients.
Because the observer does not participate in the election, if the observer hangs, it will not affect the normal operation of the entire cluster.
Configure the observer mode:
- Add peerType=observer to zoo.cfg on observer machine
- Add ":observer" after server.x=192.168.123.102:2888:2888 of the corresponding observer machine in zoo.cfg of each machine in the cluster
restart all machines
Log in to the observer machine and execute ./zkServer.sh status to see mode:observer, others are followers or leaders
Attachment: configuration instructions for zookeeper
parameter name |
illustrate |
clientPort |
The port that the client connects to the server, that is, the external service port, is generally set to 2181. |
dataDir |
Directory to store snapshot files snapshot. By default, transaction logs are also stored here. where x is the Zxid when the snapshot was generated. |
dataLogDir |
Transaction log output directory. During normal operation, for all transaction operations, before returning the client's "transaction successful" response, ZK will ensure that the transaction log of this transaction operation has been written to disk, and only in this way will the transaction take effect. |
tickTime |
A time unit in ZK. All time in ZK is based on this time unit and is configured in integer multiples. For example, the minimum timeout for a session is 2*tickTime. |
initLimit |
During the startup process of the Follower, it will synchronize all the latest data from the Leader, and then determine the starting state that it can serve externally. Leader allows F to complete this work within the initLimit time. Under normal circumstances, we don't care too much about the setting of this parameter. If the amount of data in the ZK cluster is really large, the time for F to synchronize data from the leader will be correspondingly longer when F starts up. Therefore, in this case, it is necessary to appropriately increase this parameter. |
syncLimit |
During the running process, the leader is responsible for communicating with all the machines in the ZK cluster, for example, through some heartbeat detection mechanisms, to detect the survival status of the machines. If L sends a heartbeat packet after syncLimit, but has not received a response from F, then it is considered that this F is no longer online. |
minSessionTimeout maxSessionTimeout |
Session timeout time limit. If the timeout time set by the client is not within this range, it will be forced to be set to the maximum or minimum time. The default session timeout time is in the range of 2 * tickTime ~ 20 * tickTime |
snapCount |
After each snapshotCount transaction log output, a snapshot is triggered. At this time, ZK will generate a snapshot.* file and create a new transaction log file log.*. The default is 100000. This is a situation 此外,在产生新Leader时,也会生成新的快照文件,(同时会生成对应的事务文件) |
autopurge.purgeInterval |
3.4.0及之后版本,ZK提供了自动清理事务日志和快照文件的功能,这个参数指定了清理频率,单位是小时,需要配置一个1或更大的整数,默认是0,表示不开启自动清理功能。 |
server.x=[hostname]:nnnnn[:nnnnn] |
这里的x是一个数字,与myid文件中的id是一致的。右边可以配置两个端口,第一个端口用于F和L之间的数据同步和其它通信,第二个端口用于Leader选举过程中投票通信。
|
jute.maxbuffer |
每个节点最大数据量,是默认是1M。 |
globalOutstandingLimit |
最大请求堆积数。默认是1000。ZK运行的时候, 尽管server已经没有空闲来处理更多的客户端请求了,但是还是允许客户端将请求提交到服务器上来,以提高吞吐性能。当然,为了防止Server内存溢出,这个请求堆积数还是需要限制下的。
|
preAllocSize |
预先开辟磁盘空间,用于后续写入事务日志。默认是64M,每个事务日志大小就是64M。 |
electionAlg |
默认为3,即 fast paxos election 选举算法。在3.4版本后,1 2对应的选举算已弃用,所以此项配置不要更改。 |
leaderServes |
默认情况下,Leader是会接受客户端连接,并提供正常的读写服务。但是,如果你想让Leader专注于集群中机器的协调,那么可以将这个参数设置为no,这样一来,会提高整个zk集群性能。 |