1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-14 02:33:03 +02:00
kratos/selector/balancer.go
longxboy cd79c2a458
feat: add raw node (#1611)
* add raw node to improve performace
2021-11-05 16:43:40 +08:00

39 lines
738 B
Go

package selector
import (
"context"
"time"
)
// Balancer is balancer interface
type Balancer interface {
Pick(ctx context.Context, nodes []WeightedNode) (selected WeightedNode, done DoneFunc, err error)
}
// BalancerBuilder build balancer
type BalancerBuilder interface {
Build() Balancer
}
// WeightedNode calculates scheduling weight in real time
type WeightedNode interface {
Node
// Raw returns the original node
Raw() Node
// Weight is the runtime calculated weight
Weight() float64
// Pick the node
Pick() DoneFunc
// PickElapsed is time elapsed since the latest pick
PickElapsed() time.Duration
}
// WeightedNodeBuilder is WeightedNode Builder
type WeightedNodeBuilder interface {
Build(Node) WeightedNode
}