Skip to content

Commit e47625a

Browse files
committed
debug: add log for debug discovery
1 parent dbe1257 commit e47625a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

pkg/loadbalance/weighted_balancer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (wb *weightedBalancer) GetPicker(ctx context.Context, e discovery.Result) P
6464
picker, ok := wb.pickerCache.Load(e.CacheKey)
6565
if !ok {
6666
picker, _, _ = wb.sfg.Do(e.CacheKey, func() (interface{}, error) {
67-
klog.CtxErrorf(ctx, "KITEX-DEBUG: start createPicker, CacheKey=%s", e.CacheKey)
67+
klog.CtxErrorf(ctx, "KITEX-DEBUG: start createPicker, CacheKey=%s, instanceSize=%d", e.CacheKey, len(e.Instances))
6868
p := wb.createPicker(ctx, e)
6969
klog.CtxErrorf(ctx, "KITEX-DEBUG: end createPicker, CacheKey=%s", e.CacheKey)
7070
wb.pickerCache.Store(e.CacheKey, p)
@@ -79,6 +79,7 @@ func (wb *weightedBalancer) createPicker(ctx context.Context, e discovery.Result
7979
weightSum := 0
8080
balance := true
8181
cnt := 0
82+
klog.CtxErrorf(ctx, "KITEX-DEBUG: createPicker, begin iterator")
8283
for idx, instance := range e.Instances {
8384
weight := instance.Weight()
8485
if weight <= 0 {
@@ -92,6 +93,7 @@ func (wb *weightedBalancer) createPicker(ctx context.Context, e discovery.Result
9293
}
9394
cnt++
9495
}
96+
klog.CtxErrorf(ctx, "KITEX-DEBUG: createPicker, end iterator, size=%d", len(instances))
9597
instances = instances[:cnt]
9698
if len(instances) == 0 {
9799
return new(DummyPicker)
@@ -102,7 +104,9 @@ func (wb *weightedBalancer) createPicker(ctx context.Context, e discovery.Result
102104
if balance {
103105
picker = newRoundRobinPicker(instances)
104106
} else {
105-
picker = newWeightedRoundRobinPicker(instances)
107+
klog.CtxErrorf(ctx, "KITEX-DEBUG: start newWeightedRoundRobinPicker")
108+
picker = newWeightedRoundRobinPicker(ctx, instances)
109+
klog.CtxErrorf(ctx, "KITEX-DEBUG: end newWeightedRoundRobinPicker")
106110
}
107111
default: // random
108112
if balance {

pkg/loadbalance/weighted_round_robin.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type wrrNode struct {
3838
current int
3939
}
4040

41-
func newWeightedRoundRobinPicker(instances []discovery.Instance) Picker {
41+
func newWeightedRoundRobinPicker(ctx context.Context, instances []discovery.Instance) Picker {
4242
wrrp := new(WeightedRoundRobinPicker)
4343
wrrp.iterator = newRound()
4444

@@ -60,6 +60,7 @@ func newWeightedRoundRobinPicker(instances []discovery.Instance) Picker {
6060
}
6161
wrrp.vcapacity = uint64(totalWeight)
6262
wrrp.vnodes = make([]discovery.Instance, wrrp.vcapacity)
63+
klog.CtxErrorf(ctx, "KITEX-DEBUG: newWeightedRoundRobinPicker, vcapacity=%d", totalWeight)
6364
wrrp.buildVirtualWrrNodes(wrrVNodesBatchSize)
6465
return wrrp
6566
}
@@ -99,8 +100,9 @@ func (wp *WeightedRoundRobinPicker) Next(ctx context.Context, request interface{
99100
vtarget = idx
100101
}
101102

102-
klog.CtxErrorf(ctx, "KITEX-DEBUG: start buildVirtualWrrNodes")
103+
klog.CtxErrorf(ctx, "KITEX-DEBUG: start buildVirtualWrrNodes, vcapacity=%d", wp.vcapacity)
103104
wp.buildVirtualWrrNodes(vtarget)
105+
klog.CtxErrorf(ctx, "KITEX-DEBUG: end buildVirtualWrrNodes")
104106
return wp.vnodes[idx]
105107
}
106108

0 commit comments

Comments
 (0)