loadbalancer

package
v0.0.0-...-3b4426b Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

loadbalancer

provide loadbalancer algorithms for multiple eventmesh grpc server

support:

  1. random, peek one grpc server randomly
  2. roundrobin, peek one grpc server with roundrobin, no weight
  3. iphash, peek one grpc server with iphash, need to provide the client on choose API

https://github.com/lafikl/liblb/blob

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoServerFound = fmt.Errorf("no server found")
	ErrInvalidInput  = fmt.Errorf("invalidate input")
)

Functions

This section is empty.

Types

type BaseLoadBalancer

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

BaseLoadBalancer loadbalancer instance

func (*BaseLoadBalancer) AddServer

func (b *BaseLoadBalancer) AddServer(srvs []*StatusServer)

AddServer add servers to the lb

func (*BaseLoadBalancer) Choose

func (b *BaseLoadBalancer) Choose(input interface{}) (interface{}, error)

Choose choose server in current lb

func (*BaseLoadBalancer) GetAllStatusServer

func (b *BaseLoadBalancer) GetAllStatusServer() []*StatusServer

func (*BaseLoadBalancer) GetAvailableServer

func (b *BaseLoadBalancer) GetAvailableServer() []*StatusServer

type BaseRule

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

BaseRule base rule for all implements, holds the lb to fetch the latest server lists

func (*BaseRule) SetLoadBalancer

func (b *BaseRule) SetLoadBalancer(balancer LoadBalancer)

SetLoadBalancer set the lb for current rule

type IPHashRule

type IPHashRule struct {
	BaseRule
}

IPHashRule iphash rule

func (*IPHashRule) Choose

func (i *IPHashRule) Choose(ip interface{}) (interface{}, error)

Choose return the instance by ip hash the input must be ip

type LoadBalancer

type LoadBalancer interface {
	// GetAllStatusServer return all status server in the lb
	GetAllStatusServer() []*StatusServer

	// GetAvailableServer available servers which is ready for service
	GetAvailableServer() []*StatusServer

	// AddServer add servers to LoadBalancer
	AddServer([]*StatusServer)

	// Choose peek client with rule inside
	Choose(input interface{}) (interface{}, error)
}

LoadBalancer interface to process all grpc client

func NewLoadBalancer

func NewLoadBalancer(lbType conf.LoadBalancerType, srvs []*StatusServer) (LoadBalancer, error)

NewLoadBalancer create new loadbalancer with lb type and servers

type RandomRule

type RandomRule struct {
	BaseRule
}

RandomRule random rule by math.Random

func (*RandomRule) Choose

func (r *RandomRule) Choose(interface{}) (interface{}, error)

Choose return the instance by random the input must be ip

type RoundRobinRule

type RoundRobinRule struct {
	BaseRule
	// contains filtered or unexported fields
}

RoundRobinRule rule with roundrobin algorithm

func (*RoundRobinRule) Choose

func (r *RoundRobinRule) Choose(interface{}) (interface{}, error)

Choose return the instance by roundrobin the input must be ip

type Rule

type Rule interface {
	// Choose return the instance by rule
	Choose(interface{}) (interface{}, error)
}

Rule for loadbalancer algorithms

type StatusServer

type StatusServer struct {
	// ReadyForService indicate the remote is connected
	// and ready for service for client
	ReadyForService bool
	// Host holds the eventmesh server host
	Host string
	// RealServer holds the grpc client, producer/consumer/heartbeat
	RealServer interface{}
}

StatusServer server with status check

func NewStatusServer

func NewStatusServer(in interface{}, host string) *StatusServer

NewStatusServer create new status server

func (*StatusServer) String

func (s *StatusServer) String() string

String return the description about the server

Jump to

Keyboard shortcuts

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