You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 1, 2019. It is now read-only.
[Rendezvous or highest random weight](https://en.wikipedia.org/wiki/Rendezvous_hashing) (HRW) hashing is an algorithm that allows clients to achieve distributed agreement on a set of k options out of a possible set of n options. A typical application is when clients need to agree on which sites (or proxies) objects are assigned to. When k is 1, it subsumes the goals of consistent hashing, using an entirely different method.
9
+
10
+
## Install
11
+
12
+
`go get github.com/im-kulikov/hrw`
13
+
14
+
## Example
15
+
16
+
```go
17
+
package main
18
+
19
+
import (
20
+
"fmt"
21
+
22
+
"github.com/im-kulikov/hrw"
23
+
)
24
+
25
+
funcmain() {
26
+
// given a set of servers
27
+
servers:= []string{
28
+
"one.example.com",
29
+
"two.example.com",
30
+
"three.example.com",
31
+
"four.example.com",
32
+
"five.example.com",
33
+
"six.example.com",
34
+
}
35
+
36
+
// HRW can consistently select a uniformly-distributed set of servers for
37
+
// any given key
38
+
var (
39
+
key = []byte("/examples/object-key")
40
+
h = hrw.Hash(key)
41
+
)
42
+
43
+
hrw.SortSliceByValue(servers, h)
44
+
forid:=range servers {
45
+
fmt.Printf("trying GET %s%s\n", servers[id], key)
46
+
}
47
+
48
+
// Output:
49
+
// trying GET four.example.com/examples/object-key
50
+
// trying GET three.example.com/examples/object-key
51
+
// trying GET one.example.com/examples/object-key
52
+
// trying GET two.example.com/examples/object-key
53
+
// trying GET six.example.com/examples/object-key
54
+
// trying GET five.example.com/examples/object-key
0 commit comments