Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate rate limiter #1392

Merged
merged 4 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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