diff --git a/scheduler/core/evaluator/basic/basic_evaluator.go b/scheduler/core/evaluator/basic/basic_evaluator.go index f48fae00e..9e9462e53 100644 --- a/scheduler/core/evaluator/basic/basic_evaluator.go +++ b/scheduler/core/evaluator/basic/basic_evaluator.go @@ -96,7 +96,7 @@ func (eval *baseEvaluator) Evaluate(parent *supervisor.Peer, child *supervisor.P load := getHostLoad(parent.Host) - dist := getDistance(parent, child) + dist := getAffinity(parent, child) return profits * load * dist } @@ -128,8 +128,8 @@ func getHostLoad(host *supervisor.Host) float64 { return 1.0 - host.GetUploadLoadPercent() } -// getDistance 0.0~1.0 larger and better -func getDistance(dst *supervisor.Peer, src *supervisor.Peer) float64 { +// getAffinity 0.0~1.0 larger and better +func getAffinity(dst *supervisor.Peer, src *supervisor.Peer) float64 { hostDist := 40.0 if dst.Host == src.Host { hostDist = 0.0 diff --git a/scheduler/supervisor/peer.go b/scheduler/supervisor/peer.go index 45dd6dec5..b9638177d 100644 --- a/scheduler/supervisor/peer.go +++ b/scheduler/supervisor/peer.go @@ -404,8 +404,12 @@ func (peer *Peer) SortedValue() int { defer peer.lock.RUnlock() pieceCount := peer.TotalPieceCount.Load() - hostLoad := peer.getFreeLoad() - return int(pieceCount*HostMaxLoad + hostLoad) + freeLoad := peer.getFreeLoad() + if peer.Host.IsCDN { + // if peer's host is CDN, peer has the lowest priority among all peers with the same number of pieces + return int(pieceCount * HostMaxLoad) + } + return int(pieceCount*HostMaxLoad + freeLoad) } func (peer *Peer) getFreeLoad() int32 {