xring

package module
v0.0.0-...-40c1768 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2019 License: MIT Imports: 7 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

xring

A consistent hash ring with bounded loads Consistent hashing with bounded loads implementation using Red Black Tree xring

Example Usage

	nodes := []string{"a", "b", "c"}
	cnf := &xring.Config{
		VirtualNodes: 300,
		LoadFactor:   2,
	}
	hashRing := xring.NewRing(nodes, cnf)
	node,err:=hashRing.Get("foo")

	/*  
		Call this post execution of any function, else 
	 	the traffic would be load balanced, and get stuck if
		all nodes are busy 
	*/
	hashRing.Done(node)

TODO

  • Add more test cases
  • Performance test for xxhash

Paper

https://ai.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html

https://www.akamai.com/es/es/multimedia/documents/technical-publication/consistent-hashing-and-random-trees-distributed-caching-protocols-for-relieving-hot-spots-on-the-world-wide-web-technical-publication.pdf

xring Image source: https://ai.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ERR_EMPTY_RING    = errors.New("empty ring")
	ERR_KEY_NOT_FOUND = errors.New("key not found")
	ERR_HEAVY_LOAD    = errors.New("servers under heavy load")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	VirtualNodes int
	LoadFactor   float64
}

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

func New

func New() *Ring

func NewRing

func NewRing(nodes []string, cnf *Config) *Ring

func (*Ring) Add

func (r *Ring) Add(node string)

func (*Ring) Done

func (r *Ring) Done(node string)

func (*Ring) Get

func (r *Ring) Get(key string) (string, error)

func (*Ring) Remove

func (r *Ring) Remove(node string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址