Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Test cache affinity #163

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions pool_dynamics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ func TestPoolAffinity(t *testing.T) {
cidList := generateRandomCIDs(20)

t.Run("selected nodes remain consistent for same cid reqs", func(t *testing.T) {
ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesSize/2)
// 80 nodes will be in the good pool. 20 will be added later with the same stats.
// So, 20% of the nodes in the pool will eventually be "new nodes" that have been added later.
ch, controlGroup := getHarnessAndControlGroup(t, 100, 80)
_, _ = ch.Caboose.Get(ctx, cidList[0])

goodNodes := make([]*caboose.Node, 0)
Expand Down Expand Up @@ -265,38 +267,32 @@ func TestPoolAffinity(t *testing.T) {
Size: float64(baseStatSize) * float64(10),
}

// variedStats := util.NodeStats{
// Start: time.Now().Add(-time.Second * 2),
// Latency: float64(baseStatLatency) / (float64(10) + (1 + statVarianceFactor)),
// Size: float64(baseStatSize) * float64(10) * (1 + statVarianceFactor),
// }

ch.RecordSuccesses(t, goodNodes, baseStats, 100)
ch.RecordSuccesses(t, badNodes, baseStats, 10)

ch.CaboosePool.DoRefresh()
}

// for _, i := range ch.CabooseAllNodes.Nodes {
// fmt.Println(i.URL, i.Priority(), i.PredictedLatency)
// }
rerouteCount := 0

// Get the candidate nodes for a few cids from our formed cid list using
// the affinity of each cid.
for i := 0; i < 10; i++ {
rand.New(rand.NewSource(time.Now().Unix()))
idx := rand.Intn(len(cidList))
c := cidList[idx]
// Get the candidate nodes for each cid in the cid list to see if it's been rerouted to a new node.
for _, c := range cidList {
aff := ch.Caboose.GetAffinity(ctx)
if aff == "" {
aff = fmt.Sprintf(blockPathPattern, c)
}
nodes, _ := ch.CabooseActiveNodes.GetNodes(aff, ch.Config.MaxRetrievalAttempts)

// We expect that the candidate nodes are part of the "good nodes" list.
assert.Contains(t, goodNodes, nodes[0])
for _, n := range badNodes {
n := n
if n.URL == nodes[0].URL {
rerouteCount++
}
Comment on lines +288 to +290
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should 'reroute' be incremented when this doesn't match?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe reroute is meant to keep track of how often caboose returns a new joining node as the candidate node to fetch a cid in which case caboose is "rerouting" where it fetches that cid from. In that case, the increment here is good imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah what Amean said.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're iterating over bad nodes here.

}
}

// no more than 5 cids from the cid list of 20 should get re-routed (25%)
assert.LessOrEqual(t, rerouteCount, 4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be 5, rather than 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

})
}

Expand Down