feat: improve http download strategy to prevent speed drops near completion (#969)

This commit is contained in:
Levi authored and GitHub committed 2025-04-05 22:20:35 +08:00
1 parent bfad91dcab
commit 50bc9ab129
4 files changed
+263 -134

No files matched your search

+11 -12
View File
@@ -148,6 +148,7 @@ func (d *Downloader) Setup() error {
tasks = append(tasks[:i], tasks[i+1:]...)
continue
}
d.assignFetcherManager(task)
initTask(task)
if task.Status != base.DownloadStatusDone && task.Status != base.DownloadStatusError {
task.Status = base.DownloadStatusPause
@@ -892,18 +893,7 @@ func (d *Downloader) restoreTask(task *Task) error {
}
func (d *Downloader) restoreFetcher(task *Task) error {
var fm fetcher.FetcherManager
for _, f := range d.cfg.FetchManagers {
if f.Name() == task.Protocol {
fm = f
break
}
}
if fm == nil {
return ErrUnSupportedProtocol
}
task.fetcherManager = fm
v, f := fm.Restore()
v, f := task.fetcherManager.Restore()
if v != nil {
err := d.storage.Pop(bucketSave, task.ID, v)
if err != nil {
@@ -1145,6 +1135,15 @@ func logPanic(logDir string) {
debug.SetCrashOutput(f, debug.CrashOptions{})
}
func (d *Downloader) assignFetcherManager(task *Task) error {
fm, err := d.parseFm(task.Meta.Req.URL)
if err != nil {
return err
}
task.fetcherManager = fm
return nil
}
func (d *Downloader) buildFetcher(url string) (fetcher.Fetcher, error) {
fm, err := d.parseFm(url)
if err != nil {
+8 -2
View File
@@ -14,6 +14,12 @@ type OptsExtra struct {
// Stats for download
type Stats struct {
// http stats
// health indicators of http
Connections []*StatsConnection `json:"connections"`
}
type StatsConnection struct {
Downloaded int64 `json:"downloaded"`
Completed bool `json:"completed"`
Failed bool `json:"failed"`
RetryTimes int `json:"retryTimes"`
}