feat(download): implement rate limiting with --rate flag #152
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/pget!152
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/rate-limiting"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Add
--rateflag to limit download speed (e.g.,500k,2M,1G). Rate limiter is shared globally across all workers using a time-based approach.Why
Users on bandwidth-constrained links need to control download speed to avoid saturating the connection.
Implementation
internal/rate/rate.go—Limitertracks total bytes read by all workers vs elapsed time. Sleeps when ahead of schedule. Thread-safe via mutex.internal/config/config.go—--rateflag,parseRate()helper for suffix parsing (k/K, M, G),PGET_RATEenv overrideinternal/downloader/download.go—rateReaderwraps body reader, callslim.Wait(n)on eachRead(). Shared*rate.Limitercreated inDownload()and passed through the call chain.Testing
--rate=500klimits download to ~500KB/sPGET_RATE=2Mworks via envgo build ./...,go vet ./...,golangci-lint run— all cleanBreaking Changes
None
Closes #86, #83, #84, #85
Review: APPROVED
Verification
go vet ./...— ✅ passesgo build ./...— ✅ passesgolangci-lint v2 run ./...— ✅ 0 issuesChanges
internal/rate/rate.go(rewritten) — Global rate limiter: tracks bytes + elapsed time, sleeps when ahead of schedule. Thread-safe via mutex.internal/config/config.go—Rate int64,--rateflag,parseRate()(k/K/M/G suffixes),PGET_RATEenv varinternal/downloader/download.go—rateReaderwrapper, shared*rate.Limiterpassed through workerscmd/pget/main.go— passescfg.RatetoDownload()Key behavior
--rate=500klimits total to 500KB/s)--rateis unset or 0rateReaderwrapperCloses #83, #84, #85, #86 on merge.