From afbf005c45a9e6e9cfb96014d57a270ed27b71b3 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Fri, 10 May 2024 17:03:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BD=AE=E8=AF=A2=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E9=AB=98=E5=B9=B6=E5=8F=91=E6=8A=A5no=20valid?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upstream/round-robin/round_robin.go | 5 ++- upstream/round-robin/round_robin_test.go | 49 +++++++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/upstream/round-robin/round_robin.go b/upstream/round-robin/round_robin.go index dacbeb65..89b97fa9 100644 --- a/upstream/round-robin/round_robin.go +++ b/upstream/round-robin/round_robin.go @@ -2,12 +2,13 @@ package round_robin import ( "errors" - "github.com/eolinker/apinto/utils/queue" "strconv" "sync" "sync/atomic" "time" + "github.com/eolinker/apinto/utils/queue" + eoscContext "github.com/eolinker/eosc/eocontext" "github.com/eolinker/apinto/upstream/balance" @@ -101,7 +102,7 @@ func (r *roundRobin) Next() (eoscContext.INode, int, error) { nodeValue.effectiveWeight -= r.gcdWeight - if nodeValue.weight > 0 { + if nodeValue.effectiveWeight > 0 { r.nodeQueue.Push(entry) } else { nodeValue.effectiveWeight = nodeValue.weight diff --git a/upstream/round-robin/round_robin_test.go b/upstream/round-robin/round_robin_test.go index e07dec63..5f8eb7b3 100644 --- a/upstream/round-robin/round_robin_test.go +++ b/upstream/round-robin/round_robin_test.go @@ -1,12 +1,13 @@ package round_robin import ( - "github.com/eolinker/apinto/drivers/discovery/static" - "github.com/eolinker/eosc/eocontext" "runtime" "sync" "testing" "time" + + "github.com/eolinker/apinto/drivers/discovery/static" + "github.com/eolinker/eosc/eocontext" ) type demoNode struct { @@ -107,3 +108,47 @@ func Test_roundRobin_Next_Retry_Status(t *testing.T) { } wg.Wait() } + +func Test_roundRobin_Next_Retry_Status_2(t *testing.T) { + discovery := static.CreateAnonymous(&static.Config{ + HealthOn: false, + Health: nil, + }) + + app, err := discovery.GetApp("") + if err != nil { + return + } + robin := newRoundRobin(app, "http", time.Second) + for i := 0; i < 12; i++ { + n, _, err := robin.Select(nil) + if err != nil { + t.Error(err) + return + } + t.Log(i, n.Addr()) + } +} + +var () + +func Benchmark_roundRobin_Next_Retry_demo(b *testing.B) { + discovery := static.CreateAnonymous(&static.Config{ + HealthOn: false, + Health: nil, + }) + app, err := discovery.GetApp("127.0.0.1:8080;127.0.0.1:8081;127.0.0.1:8083;127.0.0.1:8084") + if err != nil { + b.Fatal(err) + } + + robin := newRoundRobin(app, "http", time.Second) + for i := 0; i < b.N; i++ { + _, _, err := robin.Select(nil) + if err != nil { + b.Fatal(err) + return + } + //b.Log(i, n.Addr()) + } +}