From ddfdb24dbfe2c9fb535175024ee32a9c49e2c15a Mon Sep 17 00:00:00 2001 From: Jim Ma Date: Mon, 1 Aug 2022 17:07:33 +0800 Subject: [PATCH] fix: auto switch to concurrent back source (#1507) Signed-off-by: Jim Ma --- client/daemon/peer/piece_manager.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/daemon/peer/piece_manager.go b/client/daemon/peer/piece_manager.go index 17a600125..1ff48597c 100644 --- a/client/daemon/peer/piece_manager.go +++ b/client/daemon/peer/piece_manager.go @@ -469,8 +469,9 @@ func (pm *pieceManager) downloadKnownLengthSource(ctx context.Context, pt Task, pt.ReportPieceResult(request, result, nil) pt.PublishPieceInfo(pieceNum, uint32(result.Size)) if supportConcurrent { - speed := int64(pieceSize) / (result.FinishTime - result.BeginTime) - if speed < int64(pm.concurrentOption.ThresholdSpeed) { + // the time unit of FinishTime and BeginTime is ns + speed := float64(pieceSize) / float64((result.FinishTime-result.BeginTime)/1000000) + if speed < float64(pm.concurrentOption.ThresholdSpeed) { err = pt.GetStorage().UpdateTask(ctx, &storage.UpdateTaskRequest{ PeerTaskMetadata: storage.PeerTaskMetadata{ @@ -768,7 +769,7 @@ func (pm *pieceManager) concurrentDownloadSource(ctx context.Context, pt Task, p wg := sync.WaitGroup{} wg.Add(int(pieceCount - startPieceNum)) - downloadedPieceCount := atomic.NewInt32(0) + downloadedPieceCount := atomic.NewInt32(startPieceNum) for i := 0; i < con; i++ { go func(i int) {