From fcd935171749bc3117d8f9403cf715fa66018354 Mon Sep 17 00:00:00 2001 From: zhaohaiyux <99347745@qq.com> Date: Mon, 8 Nov 2021 19:53:35 +0800 Subject: [PATCH] fix:modify annotation and wrong words (#1615) * fix:modify annotation and wrong words --- selector/default_node.go | 2 +- selector/default_selector.go | 2 +- selector/filter/version.go | 2 +- selector/node/ewma/node.go | 15 ++++++++------- selector/p2c/p2c.go | 6 +++--- selector/random/random.go | 2 +- selector/selector.go | 2 +- selector/wrr/wrr.go | 2 +- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/selector/default_node.go b/selector/default_node.go index 130d15aec..b68899817 100644 --- a/selector/default_node.go +++ b/selector/default_node.go @@ -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 diff --git a/selector/default_selector.go b/selector/default_selector.go index b06601f6f..ae5e4596a 100644 --- a/selector/default_selector.go +++ b/selector/default_selector.go @@ -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 diff --git a/selector/filter/version.go b/selector/filter/version.go index 66dc98f72..fdcfcc7e3 100644 --- a/selector/filter/version.go +++ b/selector/filter/version.go @@ -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)) diff --git a/selector/node/ewma/node.go b/selector/node/ewma/node.go index 2f2ff7e68..41bcc37a5 100644 --- a/selector/node/ewma/node.go +++ b/selector/node/ewma/node.go @@ -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) diff --git a/selector/p2c/p2c.go b/selector/p2c/p2c.go index af653af0b..c76db651d 100644 --- a/selector/p2c/p2c.go +++ b/selector/p2c/p2c.go @@ -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) diff --git a/selector/random/random.go b/selector/random/random.go index 48c3e0aa5..824fb8834 100644 --- a/selector/random/random.go +++ b/selector/random/random.go @@ -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 diff --git a/selector/selector.go b/selector/selector.go index 3df4776ea..ee423c9a6 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -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) } diff --git a/selector/wrr/wrr.go b/selector/wrr/wrr.go index 4b0dfc6a0..c3405915b 100644 --- a/selector/wrr/wrr.go +++ b/selector/wrr/wrr.go @@ -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