Automatic selection of a leader in a cluster of nodes

为君一笑 提交于 2019-12-09 13:17:34

问题


What are the best methods/algorithms available to select a leading node in a cluster of nodes, knowing that nodes come up and down at anytime? If implementations are available in Java, it is a plus.


回答1:


I've implemented the Paxos algorith before in Java. It's very useful, and fairly simple. (It took about 16 hours to put together a demo of it, using Threads to simulate servers. I was also much worse at threading then!)

It won't help you select the leader exactly... but what it will do is allow the various nodes to agree on a leader. So you have this leader selection algorithm, but because each node is going to pick it's own node to lead, you may find a "civil war" among your nodes. The Paxos algorithm allows you to say which picked leader is the real leader.

http://en.wikipedia.org/wiki/Paxos_%28computer_science%29




回答2:


You can look through the sources of JGroups. (keyword: "coordinator", check out chapter 7 in jGroups manual)




回答3:


Some options:

  • Hazelcast - Cluster leader election with Spring Integration and Hazelcast.
  • JGroups - Cluster leader election with JGroups
  • Apache ZooKeeper - Cluster leader election with ZooKeeper.

I have personally implemented it with Hazelcast and JGroups and say that both were fairly straight-forward and simple. For a new project, I'd go with Hazelcast.



来源:https://stackoverflow.com/questions/5824728/automatic-selection-of-a-leader-in-a-cluster-of-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!