lbcache

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package lbcache combine balancer with reslover and cache the resolve result

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump added in v0.1.0

func Dump() interface{}

Types

type Balancer

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

Balancer same with loadbalance.Loadbalancer but without resolver.Result that has been cached

func (*Balancer) GetPicker

func (bl *Balancer) GetPicker() loadbalance.Picker

GetPicker equal to loadbalance.Balancer without pass discovery.Result, because we cache the result

type BalancerFactory

type BalancerFactory struct {
	Hookable
	// contains filtered or unexported fields
}

BalancerFactory get or create a balancer with given target if has the same key(reslover.Target(target)), we will cache and reuse the Balance

func NewBalancerFactory

func NewBalancerFactory(resolver discovery.Resolver, balancer loadbalance.Loadbalancer, opts Options) *BalancerFactory

NewBalancerFactory get or create a balancer factory for balancer instance cache key with resolver name, balancer name and options

func (*BalancerFactory) Get

Get create a new balancer if not exists

type Hookable

type Hookable interface {
	// register loadbalance rebalance hook for Rebalance events
	RegisterRebalanceHook(func(ch *discovery.Change)) (index int)
	DeregisterRebalanceHook(index int)
	// register loadbalance delete hook for Delete events
	RegisterDeleteHook(func(ch *discovery.Change)) (index int)
	DeregisterDeleteHook(index int)
}

Hookable add hook for rebalancer events

type Options

type Options struct {
	// refresh discovery result timely
	RefreshInterval time.Duration

	// Balancer expire check interval
	// we need remove idle Balancers for resource saving
	ExpireInterval time.Duration

	// DiagnosisService is used register info for diagnosis
	DiagnosisService diagnosis.Service
}

Options for create builder

Jump to

Keyboard shortcuts

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