Avoid using up the bandwidth of the CDN (#801)
* rename getdistance to getAffinity Signed-off-by: 孙伟鹏 <weipeng.swp@alibaba-inc.com> * CDN has the lowest priority among all peers with the same number of pieces Signed-off-by: 孙伟鹏 <weipeng.swp@alibaba-inc.com>
This commit is contained in:
parent
558782af00
commit
dc2835a454
|
|
@ -96,7 +96,7 @@ func (eval *baseEvaluator) Evaluate(parent *supervisor.Peer, child *supervisor.P
|
||||||
|
|
||||||
load := getHostLoad(parent.Host)
|
load := getHostLoad(parent.Host)
|
||||||
|
|
||||||
dist := getDistance(parent, child)
|
dist := getAffinity(parent, child)
|
||||||
|
|
||||||
return profits * load * dist
|
return profits * load * dist
|
||||||
}
|
}
|
||||||
|
|
@ -128,8 +128,8 @@ func getHostLoad(host *supervisor.Host) float64 {
|
||||||
return 1.0 - host.GetUploadLoadPercent()
|
return 1.0 - host.GetUploadLoadPercent()
|
||||||
}
|
}
|
||||||
|
|
||||||
// getDistance 0.0~1.0 larger and better
|
// getAffinity 0.0~1.0 larger and better
|
||||||
func getDistance(dst *supervisor.Peer, src *supervisor.Peer) float64 {
|
func getAffinity(dst *supervisor.Peer, src *supervisor.Peer) float64 {
|
||||||
hostDist := 40.0
|
hostDist := 40.0
|
||||||
if dst.Host == src.Host {
|
if dst.Host == src.Host {
|
||||||
hostDist = 0.0
|
hostDist = 0.0
|
||||||
|
|
|
||||||
|
|
@ -404,8 +404,12 @@ func (peer *Peer) SortedValue() int {
|
||||||
defer peer.lock.RUnlock()
|
defer peer.lock.RUnlock()
|
||||||
|
|
||||||
pieceCount := peer.TotalPieceCount.Load()
|
pieceCount := peer.TotalPieceCount.Load()
|
||||||
hostLoad := peer.getFreeLoad()
|
freeLoad := peer.getFreeLoad()
|
||||||
return int(pieceCount*HostMaxLoad + hostLoad)
|
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 {
|
func (peer *Peer) getFreeLoad() int32 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue