Merge pull request #1112 from zhy2006/master

fix: calculate expected cost for sorting peers
This commit is contained in:
Jakub Sztandera 2020-01-19 16:00:48 +01:00 committed by GitHub
commit 8224aab851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -455,7 +455,7 @@ func (bpt *bsPeerTracker) prefSortedPeers() []peer.ID {
getPeerInitLat := func(p peer.ID) float64 { getPeerInitLat := func(p peer.ID) float64 {
var res float64 var res float64
if bpt.pmgr != nil { if bpt.pmgr != nil {
if lat, ok := bpt.pmgr.GetPeerLatency(out[i]); ok { if lat, ok := bpt.pmgr.GetPeerLatency(p); ok {
res = float64(lat) res = float64(lat)
} }
} }
@ -476,7 +476,7 @@ func (bpt *bsPeerTracker) prefSortedPeers() []peer.ID {
failRateJ := float64(pj.failures) / float64(pj.failures+pj.successes) failRateJ := float64(pj.failures) / float64(pj.failures+pj.successes)
costJ = float64(pj.averageTime) + failRateJ*float64(bpt.avgGlobalTime) costJ = float64(pj.averageTime) + failRateJ*float64(bpt.avgGlobalTime)
} else { } else {
costI = getPeerInitLat(out[i]) costJ = getPeerInitLat(out[j])
} }
return costI < costJ return costI < costJ