Skip to content

Commit

Permalink
Consolidate sort's candidateLimit and Director's serverResLimit
Browse files Browse the repository at this point in the history
As implemented, the adaptive sort protocol would only return `candidateLimit = 3`
servers for the Director to include in its redirect response. However, we already
have `serverResLimit = 6`, which configures the max number of servers with which
to supply a client request. Since these two variables have the same effect (i.e.
limiting the number of sorted servers sent to clients by the Director), why not
make them the same variable?

That's what this commit does :)
  • Loading branch information
jhiemstrawisc committed Aug 7, 2024
1 parent c13bdd7 commit b652c21
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions director/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const (
objAvailabilityFactor = 2 // Multiplier for knowing whether an object is present
loadHalvingThreshold = 10.0 // Threshold where the load havling factor kicks in
loadHalvingFactor = 4.0 // Halving interval for load
candidateLimit = 3 // Number of servers return
)

func (me SwapMaps) Len() int {
Expand Down Expand Up @@ -253,15 +252,15 @@ func sortServerAds(clientAddr netip.Addr, ads []server_structs.ServerAd, availab
case server_structs.RandomType:
weights[idx] = SwapMap{rand.Float64(), idx}
default:
return nil, errors.Errorf("Invalid sort method '%s' set in Director.CacheSortMethod. Valid methods are 'distance',"+
"'distanceAndLoad', 'adaptive', and 'random.'", param.Director_CacheSortMethod.GetString())
// Never say never, but this should never get hit because we validate the value on startup.
return nil, errors.Errorf("Invalid sort method '%s' set in Director.CacheSortMethod.", param.Director_CacheSortMethod.GetString())
}
}

if sortMethod == string(server_structs.AdaptiveType) {
candidates, _ := stochasticSort(weights, candidateLimit)
candidates, _ := stochasticSort(weights, serverResLimit)
resultAds := []server_structs.ServerAd{}
for _, cidx := range candidates[:candidateLimit] {
for _, cidx := range candidates[:serverResLimit] {
resultAds = append(resultAds, ads[cidx])
}
return resultAds, nil
Expand Down

0 comments on commit b652c21

Please sign in to comment.