Skip to content

Commit

Permalink
fix: rate limiter burst size
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Jun 16, 2022
1 parent bcb9f52 commit acfe910
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions client/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions client/daemon/upload/upload_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit acfe910

Please sign in to comment.