Skip to content

Commit

Permalink
Reduce rand dist weight range for distanceAndLoad & adaptive sort
Browse files Browse the repository at this point in the history
Previously, an unknown client/server IP resulted in a random distance weight
in (-1, 0]. However, in `distanceAndLoad`/`adaptive` sort, this means a bad
choice of random distance weight could overpower information we potentially
_do_ know from the load/availability statistics. By pinning the random dist
weight to a small range of (-0.475, -0.525], we preserve the stochastic
element of the sorting algorithm (in case load/availability stats aren't
populated), while making sure that any other known statistics over power the
distance weight for calculating server priority.

I have no solid empirical evidence this is the _right_ range, but running the sort
tests through a loop 10,000 times showed stability, whereas before the change,
I could observe a failure from the random weights every 4-5 runs.
  • Loading branch information
jhiemstrawisc committed Aug 9, 2024
1 parent 9491fce commit 937a1e6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions director/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ func sortServerAds(clientAddr netip.Addr, ads []server_structs.ServerAd, availab
if clientCoordOk {
distance, isRand = distanceWeight(clientCoord.Lat, clientCoord.Long, ad.Latitude, ad.Longitude, true)
if isRand {
// We'll set weight to negative, but still perform the load weight calculation
// This way, if the client or multiple servers result in null lat/long, we'll still
// prefer whichever server has the lowest load.
weight = 0 - rand.Float64()
// In distanceAndLoad/adaptive modes, pin random distance weights to the range [-0.475, -0.525)] in an attempt
// to make sure the weights from availability/load overpower the random distance weights while
// still having a stochastic element. We do this instead of ignoring the distance weight entirely, because
// it's possible load information and or availability information is not available for all servers.
weight = 0 - (0.475+rand.Float64())*(0.05)
} else {
dWeighted := gatedHalvingMultiplier(distance, distanceHalvingThreshold, distanceHalvingFactor)
weight *= dWeighted
Expand All @@ -259,7 +260,7 @@ func sortServerAds(clientAddr netip.Addr, ads []server_structs.ServerAd, availab
if clientCoordOk {
distance, isRand = distanceWeight(clientCoord.Lat, clientCoord.Long, ad.Latitude, ad.Longitude, true)
if isRand {
weight = 0 - rand.Float64()
weight = 0 - (0.475+rand.Float64())*(0.05)
} else {
dWeighted := gatedHalvingMultiplier(distance, distanceHalvingThreshold, distanceHalvingFactor)
weight *= dWeighted
Expand Down

0 comments on commit 937a1e6

Please sign in to comment.