lbcache

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 11 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func (*Balancer) GetResult added in v0.3.0

func (bl *Balancer) GetResult() (res discovery.Result, ok bool)

GetResult returns the discovery result that the Balancer holds.

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