19 lines
787 B
Go
19 lines
787 B
Go
package download
|
|
|
|
// LimiterBurst returns the token-bucket burst size for a bytes/sec rate limit,
|
|
// as used with golang.org/x/time/rate. The burst is the rate itself, but
|
|
// floored at 256 KiB: with burst==rate a tiny limit (say a few KiB/s) would
|
|
// hand out only a few bytes per refill, so a single read large enough to fill a
|
|
// network buffer could never proceed and throughput would stall well below the
|
|
// limit. The floor guarantees every limit still permits one usefully sized read
|
|
// while the long-run average stays bounded by the rate.
|
|
//
|
|
// This is the single source of truth for the burst calculation; httpdl, bt, and
|
|
// main call it rather than each keeping a private copy.
|
|
func LimiterBurst(bps int64) int {
|
|
if bps < 256*1024 {
|
|
return 256 * 1024
|
|
}
|
|
return int(bps)
|
|
}
|