fix:modify annotation and wrong words (#1615)

* fix:modify annotation and wrong words
pull/1617/head
zhaohaiyux 3 years ago committed by GitHub
parent 988c2312b4
commit fcd9351717
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      selector/default_node.go
  2. 2
      selector/default_selector.go
  3. 2
      selector/filter/version.go
  4. 15
      selector/node/ewma/node.go
  5. 6
      selector/p2c/p2c.go
  6. 2
      selector/random/random.go
  7. 2
      selector/selector.go
  8. 2
      selector/wrr/wrr.go

@ -6,7 +6,7 @@ import (
"github.com/go-kratos/kratos/v2/registry" "github.com/go-kratos/kratos/v2/registry"
) )
// DefaultNode is slector node // DefaultNode is selector node
type DefaultNode struct { type DefaultNode struct {
addr string addr string
weight *int64 weight *int64

@ -14,7 +14,7 @@ type Default struct {
nodes atomic.Value 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) { func (d *Default) Select(ctx context.Context, opts ...SelectOption) (selected Node, done DoneFunc, err error) {
var ( var (
options SelectOptions options SelectOptions

@ -6,7 +6,7 @@ import (
"github.com/go-kratos/kratos/v2/selector" "github.com/go-kratos/kratos/v2/selector"
) )
// Version is verion filter. // Version is version filter.
func Version(version string) selector.Filter { func Version(version string) selector.Filter {
return func(_ context.Context, nodes []selector.Node) []selector.Node { return func(_ context.Context, nodes []selector.Node) []selector.Node {
filters := make([]selector.Node, 0, len(nodes)) filters := make([]selector.Node, 0, len(nodes))

@ -72,13 +72,13 @@ func (n *Node) load() (load uint64) {
now := time.Now().UnixNano() now := time.Now().UnixNano()
avgLag := atomic.LoadInt64(&n.lag) avgLag := atomic.LoadInt64(&n.lag)
lastPredictTs := atomic.LoadInt64(&n.predictTs) lastPredictTs := atomic.LoadInt64(&n.predictTs)
predicInterval := avgLag / 5 predictInterval := avgLag / 5
if predicInterval < int64(time.Millisecond*5) { if predictInterval < int64(time.Millisecond*5) {
predicInterval = int64(time.Millisecond * 5) predictInterval = int64(time.Millisecond * 5)
} else if predicInterval > int64(time.Millisecond*200) { } else if predictInterval > int64(time.Millisecond*200) {
predicInterval = int64(time.Millisecond * 200) predictInterval = int64(time.Millisecond * 200)
} }
if now-lastPredictTs > predicInterval { if now-lastPredictTs > predictInterval {
if atomic.CompareAndSwapInt64(&n.predictTs, lastPredictTs, now) { if atomic.CompareAndSwapInt64(&n.predictTs, lastPredictTs, now) {
var ( var (
total int64 total int64
@ -104,7 +104,8 @@ func (n *Node) load() (load uint64) {
} }
if avgLag == 0 { 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)) load = penalty * uint64(atomic.LoadInt64(&n.inflight))
} else { } else {
predict := atomic.LoadInt64(&n.predict) 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 var pc, upc selector.WeightedNode
nodeA, nodeB := s.prePick(nodes) 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() { if nodeB.Weight() > nodeA.Weight() {
pc, upc = nodeB, nodeA pc, upc = nodeB, nodeA
} else { } else {
pc, upc = nodeA, nodeB 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) { if upc.PickElapsed() > forcePick && atomic.CompareAndSwapInt64(&s.lk, 0, 1) {
pc = upc pc = upc
atomic.StoreInt64(&s.lk, 0) atomic.StoreInt64(&s.lk, 0)

@ -38,7 +38,7 @@ func New(opts ...Option) selector.Selector {
return NewBuilder(opts...).Build() 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) { func (p *Balancer) Pick(_ context.Context, nodes []selector.WeightedNode) (selector.WeightedNode, selector.DoneFunc, error) {
if len(nodes) == 0 { if len(nodes) == 0 {
return nil, nil, selector.ErrNoAvailable return nil, nil, selector.ErrNoAvailable

@ -20,7 +20,7 @@ type Selector interface {
// Rebalancer is nodes rebalancer. // Rebalancer is nodes rebalancer.
type Rebalancer interface { type Rebalancer interface {
// apply all nodes when any changes happen // Apply is apply all nodes when any changes happen
Apply(nodes []Node) Apply(nodes []Node)
} }

@ -41,7 +41,7 @@ func New(opts ...Option) selector.Selector {
return NewBuilder(opts...).Build() 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) { func (p *Balancer) Pick(_ context.Context, nodes []selector.WeightedNode) (selector.WeightedNode, selector.DoneFunc, error) {
if len(nodes) == 0 { if len(nodes) == 0 {
return nil, nil, selector.ErrNoAvailable return nil, nil, selector.ErrNoAvailable

Loading…
Cancel
Save