github.com/unionj-cloud/go-doudou/v2@v2.3.5/toolkit/memberlist/README.md (about) 1 # memberlist [](https://godoc.org/github.com/hashicorp/memberlist) [](https://circleci.com/gh/hashicorp/memberlist) 2 3 memberlist is a [Go](http://www.golang.org) library that manages cluster 4 membership and member failure detection using a gossip based protocol. 5 6 The use cases for such a library are far-reaching: all distributed systems 7 require membership, and memberlist is a re-usable solution to managing 8 cluster membership and node failure detection. 9 10 memberlist is eventually consistent but converges quickly on average. 11 The speed at which it converges can be heavily tuned via various knobs 12 on the protocol. Node failures are detected and network partitions are partially 13 tolerated by attempting to communicate to potentially dead nodes through 14 multiple routes. 15 16 ## Building 17 18 If you wish to build memberlist you'll need Go version 1.2+ installed. 19 20 Please check your installation with: 21 22 ``` 23 go version 24 ``` 25 26 ## Usage 27 28 Memberlist is surprisingly simple to use. An example is shown below: 29 30 ```go 31 /* Create the initial memberlist from a safe configuration. 32 Please reference the godoc for other default config types. 33 http://godoc.org/github.com/hashicorp/memberlist#Config 34 */ 35 list, err := memberlist.Create(memberlist.DefaultLocalConfig()) 36 if err != nil { 37 panic("Failed to create memberlist: " + err.Error()) 38 } 39 40 // Join an existing cluster by specifying at least one known member. 41 n, err := list.Join([]string{"1.2.3.4"}) 42 if err != nil { 43 panic("Failed to join cluster: " + err.Error()) 44 } 45 46 // Ask for members of the cluster 47 for _, member := range list.Members() { 48 fmt.Printf("Member: %s %s\n", member.Name, member.Addr) 49 } 50 51 // Continue doing whatever you need, memberlist will maintain membership 52 // information in the background. Delegates can be used for receiving 53 // events when members join or leave. 54 ``` 55 56 The most difficult part of memberlist is configuring it since it has many 57 available knobs in order to tune state propagation delay and convergence times. 58 Memberlist provides a default configuration that offers a good starting point, 59 but errs on the side of caution, choosing values that are optimized for 60 higher convergence at the cost of higher bandwidth usage. 61 62 For complete documentation, see the associated [Godoc](http://godoc.org/github.com/hashicorp/memberlist). 63 64 ## Protocol 65 66 memberlist is based on ["SWIM: Scalable Weakly-consistent Infection-style Process Group Membership Protocol"](http://ieeexplore.ieee.org/document/1028914/). However, we extend the protocol in a number of ways: 67 68 * Several extensions are made to increase propagation speed and 69 convergence rate. 70 * Another set of extensions, that we call Lifeguard, are made to make memberlist more robust in the presence of slow message processing (due to factors such as CPU starvation, and network delay or loss). 71 72 For details on all of these extensions, please read our paper "[Lifeguard : SWIM-ing with Situational Awareness](https://arxiv.org/abs/1707.00788)", along with the memberlist source. We welcome any questions related 73 to the protocol on our issue tracker.