Skip to content

Commit

Permalink
feature: implement minrate option for dfget when downloading a file (d…
Browse files Browse the repository at this point in the history
…ragonflyoss#664)

* feature: implement minrate option for dfget when downloading a file

Signed-off-by: yizheng <yizheng@cs.unc.edu>

* remove short flag for minRate

Signed-off-by: yizheng <yizheng@cs.unc.edu>
  • Loading branch information
jyizheng authored and lowzj committed Jul 9, 2019
1 parent 99e6a96 commit 138bc70
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
13 changes: 12 additions & 1 deletion cmd/dfget/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
var (
localLimit string
totalLimit string
minRate string
filter string
)

Expand Down Expand Up @@ -132,6 +133,10 @@ func initProperties() {
cfg.LocalLimit = properties.LocalLimit
}

if cfg.MinRate == 0 {
cfg.MinRate = properties.MinRate
}

if cfg.TotalLimit == 0 {
cfg.TotalLimit = properties.TotalLimit
}
Expand All @@ -151,6 +156,10 @@ func transParams() error {
return errHandler.Wrapf(errors.ErrConvertFailed, "locallimit: %v", err)
}

if cfg.MinRate, err = transLimit(minRate); err != nil {
return errHandler.Wrapf(errors.ErrConvertFailed, "minrate: %v", err)
}

if cfg.TotalLimit, err = transLimit(totalLimit); err != nil {
return errHandler.Wrapf(errors.ErrConvertFailed, "totallimit: %v", err)
}
Expand Down Expand Up @@ -184,9 +193,11 @@ func initFlags() {
flagSet.StringVarP(&cfg.Output, "output", "o", "",
"Destination path which is used to store the requested downloading file. It must contain detailed directory and specific filename, for example, '/tmp/file.mp4'")

// localLimit & totalLimit & timeout
// localLimit & minRate & totalLimit & timeout
flagSet.StringVarP(&localLimit, "locallimit", "s", "",
"network bandwidth rate limit for single download task, in format of 20M/m/K/k")
flagSet.StringVar(&minRate, "minrate", "",
"minimal network bandwidth rate for downloading a file, in format of 20M/m/K/k")
flagSet.StringVar(&totalLimit, "totallimit", "",
"network bandwidth rate limit for the whole host, in format of 20M/m/K/k")
flagSet.IntVarP(&cfg.Timeout, "timeout", "e", 0,
Expand Down
7 changes: 7 additions & 0 deletions dfget/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type Properties struct {
// LocalLimit rate limit about a single download task,format: 20M/m/K/k.
LocalLimit int `yaml:"localLimit"`

// Minimal rate about a single download task,format: 20M/m/K/k.
MinRate int `yaml:"minRate"`

// TotalLimit rate limit about the whole host,format: 20M/m/K/k.
TotalLimit int `yaml:"totalLimit"`

Expand All @@ -75,6 +78,7 @@ func NewProperties() *Properties {
return &Properties{
Nodes: []string{DefaultNode},
LocalLimit: DefaultLocalLimit,
MinRate: DefaultMinRate,
ClientQueueSize: DefaultClientQueueSize,
}
}
Expand Down Expand Up @@ -139,6 +143,9 @@ type Config struct {
// LocalLimit rate limit about a single download task,format: 20M/m/K/k.
LocalLimit int `json:"localLimit,omitempty"`

// Minimal rate about a single download task,format: 20M/m/K/k.
MinRate int `json:"minRate,omitempty"`

// TotalLimit rate limit about the whole host,format: 20M/m/K/k.
TotalLimit int `json:"totalLimit,omitempty"`

Expand Down
1 change: 1 addition & 0 deletions dfget/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
DefaultIniConfigFile = "/etc/dragonfly.conf"
DefaultNode = "127.0.0.1"
DefaultLocalLimit = 20 * 1024 * 1024
DefaultMinRate = 64 * 1024
DefaultClientQueueSize = 6
)

Expand Down
6 changes: 3 additions & 3 deletions dfget/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func downloadFile(cfg *config.Config, supernodeAPI api.SupernodeAPI,
getter = p2pDown.NewP2PDownloader(cfg, supernodeAPI, register, result)
}

timeout := calculateTimeout(cfg.RV.FileLength, cfg.Timeout)
timeout := calculateTimeout(cfg.RV.FileLength, cfg.Timeout, cfg.MinRate)
err := downloader.DoDownloadTimeout(getter, timeout)
success := "SUCCESS"
if err != nil {
Expand Down Expand Up @@ -260,13 +260,13 @@ func checkConnectSupernode(nodes []string) (localIP string) {
return ""
}

func calculateTimeout(fileLength int64, defaultTimeoutSecond int) time.Duration {
func calculateTimeout(fileLength int64, defaultTimeoutSecond int, minRate int) time.Duration {
timeout := 5 * 60

if defaultTimeoutSecond > 0 {
timeout = defaultTimeoutSecond
} else if fileLength > 0 {
timeout = int(fileLength/(64*1024) + 10)
timeout = int(fileLength/int64(minRate) + 10)
}
return time.Duration(timeout) * time.Second
}

0 comments on commit 138bc70

Please sign in to comment.