From acfe91038a5cc5c7432cda9e2f0af5990f357b40 Mon Sep 17 00:00:00 2001 From: Gaius Date: Thu, 16 Jun 2022 15:21:00 +0800 Subject: [PATCH] fix: rate limiter burst size Signed-off-by: Gaius --- client/daemon/daemon.go | 5 +++-- client/daemon/peer/peertask_conductor.go | 3 ++- client/daemon/upload/upload_manager.go | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client/daemon/daemon.go b/client/daemon/daemon.go index 44b1f4e8591..1c1057fc0e2 100644 --- a/client/daemon/daemon.go +++ b/client/daemon/daemon.go @@ -48,6 +48,7 @@ import ( "d7y.io/dragonfly/v2/client/daemon/storage" "d7y.io/dragonfly/v2/client/daemon/upload" logger "d7y.io/dragonfly/v2/internal/dflog" + "d7y.io/dragonfly/v2/internal/util" "d7y.io/dragonfly/v2/pkg/dfnet" "d7y.io/dragonfly/v2/pkg/dfpath" "d7y.io/dragonfly/v2/pkg/idgen" @@ -178,7 +179,7 @@ func New(opt *config.DaemonOption, d dfpath.Dfpath) (Daemon, error) { pieceManager, err := peer.NewPieceManager( opt.Download.PieceDownloadTimeout, - peer.WithLimiter(rate.NewLimiter(opt.Download.TotalRateLimit.Limit, int(opt.Download.TotalRateLimit.Limit))), + peer.WithLimiter(rate.NewLimiter(opt.Download.TotalRateLimit.Limit, util.DefaultPieceSizeLimit)), peer.WithCalculateDigest(opt.Download.CalculateDigest), peer.WithTransportOption(opt.Download.TransportOption), ) if err != nil { @@ -220,7 +221,7 @@ func New(opt *config.DaemonOption, d dfpath.Dfpath) (Daemon, error) { } uploadManager, err := upload.NewUploadManager(storageManager, - upload.WithLimiter(rate.NewLimiter(opt.Upload.RateLimit.Limit, int(opt.Upload.RateLimit.Limit)))) + upload.WithLimiter(rate.NewLimiter(opt.Upload.RateLimit.Limit, upload.DefaultBurstSize))) if err != nil { return nil, err } diff --git a/client/daemon/peer/peertask_conductor.go b/client/daemon/peer/peertask_conductor.go index 362eabe21c2..d193d438a67 100644 --- a/client/daemon/peer/peertask_conductor.go +++ b/client/daemon/peer/peertask_conductor.go @@ -37,6 +37,7 @@ import ( "d7y.io/dragonfly/v2/client/daemon/storage" "d7y.io/dragonfly/v2/internal/dferrors" logger "d7y.io/dragonfly/v2/internal/dflog" + "d7y.io/dragonfly/v2/internal/util" "d7y.io/dragonfly/v2/pkg/idgen" "d7y.io/dragonfly/v2/pkg/rpc/base" "d7y.io/dragonfly/v2/pkg/rpc/scheduler" @@ -229,7 +230,7 @@ func (ptm *peerTaskManager) newPeerTaskConductor( totalPiece: atomic.NewInt32(-1), digest: atomic.NewString(""), schedulerOption: ptm.schedulerOption, - limiter: rate.NewLimiter(limit, int(limit)), + limiter: rate.NewLimiter(limit, util.DefaultPieceSizeLimit), completedLength: atomic.NewInt64(0), usedTraffic: atomic.NewUint64(0), SugaredLoggerOnWith: log, diff --git a/client/daemon/upload/upload_manager.go b/client/daemon/upload/upload_manager.go index 570096f450d..fb8f288e985 100644 --- a/client/daemon/upload/upload_manager.go +++ b/client/daemon/upload/upload_manager.go @@ -33,6 +33,11 @@ import ( logger "d7y.io/dragonfly/v2/internal/dflog" ) +const ( + // DefaultBurstSize is default burst size of rate limiter + DefaultBurstSize = 1 * 1024 * 1024 * 1024 +) + // Manager is the interface used for upload task. type Manager interface { // Started upload manager server.