BT tasks: reported speed (and downloaded) inflated 10–40× for multi-file torrents (v2.0.0-beta.4)

Open
#1,646 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
backend

Research direction

Read pkg/download/downloader.go and internal/protocol/bt/fetcher.go, then inspect how the BitTorrent library reports torrent-level transfer stats and verified completion. Reproduce with a healthy multi-file torrent and compare task API deltas with transfer stats. Done when reported speed and downloaded progress track verified torrent data without multi-file overcounting.

Written by the indexing model from the issue text.

Description

Version: v2.0.0-beta.4 (Docker, linux/amd64; same behaviour on beta.3)
Task type: BitTorrent magnet, multi-file torrent

What happens
The web UI / REST API shows a per-task download speed far above the real transfer rate, and the progress bar barely moves. Upload speed is also reported far above what the uplink can carry.

Measurements (same 2-minute window, polling the task API every 10 s)

  • API progress.speed: 115–335 MB/s
  • Δprogress.downloaded / Δt: 3–15 MB/s
  • Host NIC receive rate: ~9 MB/s
  • In one 0.5 s sample progress.downloaded jumped by +157 MB while the NIC carried ~9 MB/s, so the downloaded counter is also overstated tick-to-tick.

Likely cause
pkg/download/downloader.go computes delta = fetcher.Progress().TotalDownloaded() - Progress.Downloaded every RefreshInterval and derives speed from it. For BT, internal/protocol/bt/fetcher.go builds Progress() by summing file.BytesCompleted() per file. anacrolix File.BytesCompleted() includes dirty chunks of pieces that are not yet verified and counts pieces that span file boundaries in more than one file, so per-tick deltas are heavily overstated on multi-file torrents and can move backwards/forwards as pieces are verified.

Suggestion
Derive BT speed from torrent-level transfer stats (e.g. deltas of torrent.Stats().BytesReadUsefulData / DataBytesRead, and BytesWrittenData for upload), and report progress from verified bytes (torrent.BytesCompleted() at torrent level) rather than the per-file sum.

Steps to reproduce

  1. Add a magnet for a multi-file torrent with a healthy swarm.
  2. Compare the UI/API speed with the host's network receive rate, or with Δdownloaded over a 30 s window.
Dominant language
Dart
Stars
27.7k
Forks
1.8k
Avg merge
3d 3h
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GopeedLab/gopeed

All issues in GopeedLab/gopeed

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.