balancer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer

type Balancer[T uint32 | string] interface {
	// Next returns next one.
	Next() T
	// Put puts one into balancer.
	Put(T)
	// Delete deletes one from balancer.
	Delete(T)
	// GetAll returns all nodes.
	GetAll() []T
	// Len returns the length of nodes.
	Len() int
}

Balancer is the interface for balancer.

func GenByPolicy

func GenByPolicy[T uint32 | string](policy Policy) Balancer[T]

GenByPolicy generates a balancer by policy.

type Policy

type Policy int

Policy is the policy of balancer.

const (
	// PolicyRoundRobin is the round robin policy.
	PolicyRoundRobin Policy = iota
	// PolicyLeast is the policy to return the least used node.
	// TODO: move indexed heap to pkg and use it.
	PolicyLeast
)

func (Policy) String

func (p Policy) String() string

type RoundRobin

type RoundRobin[T uint32 | string] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RoundRobin is a balancer that selects nodes in a round-robin fashion.

func NewRoundRobin

func NewRoundRobin[T uint32 | string]() *RoundRobin[T]

NewRoundRobin creates a balancer that selects nodes in a round-robin fashion.

func (*RoundRobin[T]) Delete

func (r *RoundRobin[T]) Delete(node T)

Delete deletes one from balancer.

func (*RoundRobin[T]) GetAll

func (r *RoundRobin[T]) GetAll() []T

GetAll returns all nodes

func (*RoundRobin[T]) Len

func (r *RoundRobin[T]) Len() int

Len returns the length of nodes.

func (*RoundRobin[T]) Next

func (r *RoundRobin[T]) Next() (t T)

Next returns next address

func (*RoundRobin[T]) Put

func (r *RoundRobin[T]) Put(node T)

Put puts one into balancer.

Jump to

Keyboard shortcuts

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