roundrobin

package
v0.0.0-...-2b4093a Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package roundrobin provides smooth weighted round-robin balancing

> For edge case weights like { 5, 1, 1 } we now produce { a, a, b, a, c, a, a } > sequence instead of { c, b, a, a, a, a, a } produced previously.

the basic idea is from nginx, refer details in following link https://github.com/nginx/nginx/commit/52327e0627f49dbda1e8db695e63a4b0af4448b1

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Peer

type Peer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Peer represents a backend server.

func CreatePeer

func CreatePeer(addr string, weight int) *Peer

CreatePeer return a Peer object.

func (*Peer) String

func (p *Peer) String() string

type Pool

type Pool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Pool is a group of Peers, one Peer can not belong to multiple Pool.

func CreatePool

func CreatePool(pairs map[string]int) *Pool

CreatePool return a Pool object.

func (*Pool) Add

func (p *Pool) Add(addr string, args ...interface{})

Add append a peer to the pool if not exists.

func (*Pool) DownPeer

func (p *Pool) DownPeer(addr string)

DownPeer mark the peer down.

func (*Pool) EqualGet

func (p *Pool) EqualGet() string

EqualGet get peer by turn, without considering weight.

func (*Pool) Get

func (p *Pool) Get(args ...interface{}) string

Get return peer in smooth weighted roundrobin method.

func (*Pool) Remove

func (p *Pool) Remove(addr string)

Remove removes the peer from the pool.

func (*Pool) Size

func (p *Pool) Size() int

Size return the number of the peer.

func (*Pool) String

func (p *Pool) String() string

func (*Pool) UpPeer

func (p *Pool) UpPeer(addr string)

UpPeer mark the peer up.

Jump to

Keyboard shortcuts

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