From 737517852d08d8b8c68adef45967134b1d500dd7 Mon Sep 17 00:00:00 2001 From: Will Scott <will.scott@protocol.ai> Date: Mon, 4 Sep 2023 11:41:37 +0200 Subject: [PATCH] stabilize dynamics tests --- node_heap.go | 11 +++-------- pool_dynamics_test.go | 13 ++++++------- pool_tier_promotion.go | 7 +------ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/node_heap.go b/node_heap.go index c0566fa..0cce5f6 100644 --- a/node_heap.go +++ b/node_heap.go @@ -53,14 +53,9 @@ func (nh *NodeHeap) TopN(n int) []*Node { m := make([]*Node, 0, n) nh.lk.RLock() defer nh.lk.RUnlock() - for i := 0; i < n; i++ { - node := heap.Pop(nh) - if n, ok := node.(*Node); ok { - m = append(m, n) - } - } - for _, n := range m { - heap.Push(nh, n) + for i := 0; i < n && i < len(nh.Nodes); i++ { + node := nh.Nodes[i] + m = append(m, node) } return m } diff --git a/pool_dynamics_test.go b/pool_dynamics_test.go index 3edb2bd..f0ac675 100644 --- a/pool_dynamics_test.go +++ b/pool_dynamics_test.go @@ -16,8 +16,7 @@ import ( ) const ( - nodesSize = 6 - nodesPoolSize = caboose.PoolConsiderationCount + nodesSize = 6 ) /* @@ -41,7 +40,7 @@ func TestPoolDynamics(t *testing.T) { // This test ensures that when the pool is intialized, it should converge to a set // of nodes that have stats vs a set of nodes that don't have any stats. t.Run("pool converges to good nodes vs nodes with no stats", func(t *testing.T) { - ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesPoolSize) + ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesSize/2) ch.FetchAndAssertSuccess(t, ctx, testCid) goodNodes := make([]*caboose.Node, 0) @@ -96,13 +95,13 @@ func TestPoolDynamics(t *testing.T) { fmt.Println("Final Node Pool", np) for _, n := range ch.CabooseAllNodes.Nodes { - fmt.Println("Node", n.URL, "Priority", n.Priority(), "Rate", n.Rate()) + fmt.Println("Node", n.URL, "Priority", n.Priority(), "Rate", n.Rate(), "samples ", len(n.Samples.PeekAll())) } }) t.Run("pool converges to good nodes vs nodes with worse stats", func(t *testing.T) { - ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesPoolSize) + ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesSize/2) goodNodes := make([]*caboose.Node, 0) badNodes := make([]*caboose.Node, 0) @@ -142,7 +141,7 @@ func TestPoolDynamics(t *testing.T) { // When new nodes join, if they start consistently performing better than the nodes in the current pool, // then those nodes should replace the nodes in the current pool. t.Run("pool converges to new nodes that are better than the current pool", func(t *testing.T) { - ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesPoolSize) + ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesSize/2) goodNodes := make([]*caboose.Node, 0) badNodes := make([]*caboose.Node, 0) @@ -188,7 +187,7 @@ func TestPoolDynamics(t *testing.T) { // If the current active main pool starts failing, the pool should converge to // to nodes that are not failing. t.Run("pool converges to other nodes if the current ones start failing", func(t *testing.T) { - ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesPoolSize) + ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesSize/2) goodNodes := make([]*caboose.Node, 0) badNodes := make([]*caboose.Node, 0) diff --git a/pool_tier_promotion.go b/pool_tier_promotion.go index 4ed770c..e0be6f6 100644 --- a/pool_tier_promotion.go +++ b/pool_tier_promotion.go @@ -1,17 +1,12 @@ package caboose -import "fmt" - const ( - PoolConsiderationCount = 3 + PoolConsiderationCount = 30 activationThreshold = 0 ) func updateActiveNodes(active *NodeRing, all *NodeHeap) error { candidates := all.TopN(PoolConsiderationCount) - for _, c := range(candidates) { - fmt.Println("Candidates", c.URL, c.PredictedThroughput) - } added := 0 for _, c := range candidates { if active.Contains(c) {