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()) + } +}