selector

package
v0.0.0-...-aed9a31 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Unlicense Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SW

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

SW (Smooth Weighted) is a struct that contains weighted items and provides methods to select a weighted item. It is used for the smooth weighted round-robin balancing algorithm. This algorithm is implemented in Nginx: https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35.

Algorithm is as follows: on each peer selection we increase current_weight of each eligible peer by its weight, select peer with greatest current_weight and reduce its current_weight by total number of weight points distributed among peers.

In case of { 5, 1, 1 } weights this gives the following sequence of current_weight's: (a, a, b, a, c, a, a)

func (*SW) Add

func (w *SW) Add(item interface{}, weight int)

Add a weighted server.

func (*SW) All

func (w *SW) All() map[interface{}]int

All returns all items.

func (*SW) Next

func (w *SW) Next() interface{}

Next returns next selected server.

func (*SW) RemoveAll

func (w *SW) RemoveAll()

RemoveAll removes all weighted items.

func (*SW) Reset

func (w *SW) Reset()

Reset resets all current weights.

Jump to

Keyboard shortcuts

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