Slow leadership choices with zoo apuch + curator

I play with the leaderboards using LeaderLatch. With a local ZooKeeper installed, I have ~ 30 seconds to select a leader when there is only one instance and almost the same time to select a new leader when the leaders decline (when I complete the process). Should this work like that, and can I speed it up?

I am using the following code:

CuratorFramework curator = CuratorFrameworkFactory.newClient("127.0.0.1", new ExponentialBackoffRetry(100, 3)); curator.start(); LeaderLatch leaderLatch = new LeaderLatch(curator, "/test/t"); leaderLatch.addListener(new LeaderLatchListener() { @Override public void isLeader() { System.out.println("Leader"); } @Override public void notLeader() { } }); leaderLatch.start(); 
+5
source share
2 answers

I realized this: ZooKeeper has a timeout of 30 seconds for sessions during which it does not remove ephemeral nodes. This is why the new leader was not elected (because the node leader was not elected). It also prevents the leader from being selected when all nodes are closed and restarted before the last timeout of the leader ends.

To avoid this, you need to manually close the curator using the close method, in which case the session will be terminated instantly.

+6
source

You can reduce the "ticktime" parameter in the zookeeper configuration file and restart all servers.

+1
source

Source: https://habr.com/ru/post/1200046/


All Articles