mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
fix:modify annotation and wrong words (#1615)
* fix:modify annotation and wrong words
This commit is contained in:
parent
988c2312b4
commit
fcd9351717
@ -6,7 +6,7 @@ import (
|
||||
"github.com/go-kratos/kratos/v2/registry"
|
||||
)
|
||||
|
||||
// DefaultNode is slector node
|
||||
// DefaultNode is selector node
|
||||
type DefaultNode struct {
|
||||
addr string
|
||||
weight *int64
|
||||
|
@ -14,7 +14,7 @@ type Default struct {
|
||||
nodes atomic.Value
|
||||
}
|
||||
|
||||
// Select select one node.
|
||||
// Select is select one node.
|
||||
func (d *Default) Select(ctx context.Context, opts ...SelectOption) (selected Node, done DoneFunc, err error) {
|
||||
var (
|
||||
options SelectOptions
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/go-kratos/kratos/v2/selector"
|
||||
)
|
||||
|
||||
// Version is verion filter.
|
||||
// Version is version filter.
|
||||
func Version(version string) selector.Filter {
|
||||
return func(_ context.Context, nodes []selector.Node) []selector.Node {
|
||||
filters := make([]selector.Node, 0, len(nodes))
|
||||
|
@ -72,13 +72,13 @@ func (n *Node) load() (load uint64) {
|
||||
now := time.Now().UnixNano()
|
||||
avgLag := atomic.LoadInt64(&n.lag)
|
||||
lastPredictTs := atomic.LoadInt64(&n.predictTs)
|
||||
predicInterval := avgLag / 5
|
||||
if predicInterval < int64(time.Millisecond*5) {
|
||||
predicInterval = int64(time.Millisecond * 5)
|
||||
} else if predicInterval > int64(time.Millisecond*200) {
|
||||
predicInterval = int64(time.Millisecond * 200)
|
||||
predictInterval := avgLag / 5
|
||||
if predictInterval < int64(time.Millisecond*5) {
|
||||
predictInterval = int64(time.Millisecond * 5)
|
||||
} else if predictInterval > int64(time.Millisecond*200) {
|
||||
predictInterval = int64(time.Millisecond * 200)
|
||||
}
|
||||
if now-lastPredictTs > predicInterval {
|
||||
if now-lastPredictTs > predictInterval {
|
||||
if atomic.CompareAndSwapInt64(&n.predictTs, lastPredictTs, now) {
|
||||
var (
|
||||
total int64
|
||||
@ -104,7 +104,8 @@ func (n *Node) load() (load uint64) {
|
||||
}
|
||||
|
||||
if avgLag == 0 {
|
||||
// penalty是node刚启动时没有数据时的惩罚值,默认为1e9 * 10
|
||||
// penalty is the penalty value when there is no data when the node is just started.
|
||||
// The default value is 1e9 * 10
|
||||
load = penalty * uint64(atomic.LoadInt64(&n.inflight))
|
||||
} else {
|
||||
predict := atomic.LoadInt64(&n.predict)
|
||||
|
@ -67,15 +67,15 @@ func (s *Balancer) Pick(ctx context.Context, nodes []selector.WeightedNode) (sel
|
||||
|
||||
var pc, upc selector.WeightedNode
|
||||
nodeA, nodeB := s.prePick(nodes)
|
||||
// meta.Weight为服务发布者在discovery中设置的权重
|
||||
// meta.Weight is the weight set by the service publisher in discovery
|
||||
if nodeB.Weight() > nodeA.Weight() {
|
||||
pc, upc = nodeB, nodeA
|
||||
} else {
|
||||
pc, upc = nodeA, nodeB
|
||||
}
|
||||
|
||||
// 如果落选节点在forceGap期间内从来没有被选中一次,则强制选一次
|
||||
// 利用强制的机会,来触发成功率、延迟的更新
|
||||
// If the failed node has never been selected once during forceGap, it is forced to be selected once
|
||||
// Take advantage of forced opportunities to trigger updates of success rate and delay
|
||||
if upc.PickElapsed() > forcePick && atomic.CompareAndSwapInt64(&s.lk, 0, 1) {
|
||||
pc = upc
|
||||
atomic.StoreInt64(&s.lk, 0)
|
||||
|
@ -38,7 +38,7 @@ func New(opts ...Option) selector.Selector {
|
||||
return NewBuilder(opts...).Build()
|
||||
}
|
||||
|
||||
// Pick pick a weighted node.
|
||||
// Pick is pick a weighted node.
|
||||
func (p *Balancer) Pick(_ context.Context, nodes []selector.WeightedNode) (selector.WeightedNode, selector.DoneFunc, error) {
|
||||
if len(nodes) == 0 {
|
||||
return nil, nil, selector.ErrNoAvailable
|
||||
|
@ -20,7 +20,7 @@ type Selector interface {
|
||||
|
||||
// Rebalancer is nodes rebalancer.
|
||||
type Rebalancer interface {
|
||||
// apply all nodes when any changes happen
|
||||
// Apply is apply all nodes when any changes happen
|
||||
Apply(nodes []Node)
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ func New(opts ...Option) selector.Selector {
|
||||
return NewBuilder(opts...).Build()
|
||||
}
|
||||
|
||||
// Pick pick a weighted node.
|
||||
// Pick is pick a weighted node.
|
||||
func (p *Balancer) Pick(_ context.Context, nodes []selector.WeightedNode) (selector.WeightedNode, selector.DoneFunc, error) {
|
||||
if len(nodes) == 0 {
|
||||
return nil, nil, selector.ErrNoAvailable
|
||||
|
Loading…
x
Reference in New Issue
Block a user