Compare commits

...

2 Commits

Author SHA1 Message Date
Michael Yang
39374984ef set limit to increment 2024-03-07 17:31:45 -08:00
Michael Yang
daf928fe1a tune concurrency manager
- higher initial concurrency
- lower cooldown after ramping up
- lower threshold for ramp up
2024-03-07 16:25:17 -08:00

View File

@ -12,6 +12,7 @@ import (
"net/url"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
@ -151,7 +152,7 @@ func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *regis
_ = file.Truncate(b.Total)
var limit int64 = 2
limit := int64(runtime.NumCPU())
g, inner := NewLimitGroup(ctx, numDownloadParts, limit)
go watchDelta(inner, g, &b.Completed, limit)
@ -424,8 +425,8 @@ func watchDelta(ctx context.Context, g *LimitGroup, c *atomic.Int64, limit int64
var maxDelta float64
var buckets []int64
// 5s ramp up period
nextUpdate := time.Now().Add(5 * time.Second)
// 3s ramp up period
nextUpdate := time.Now().Add(3 * time.Second)
ticker := time.NewTicker(time.Second)
for {
@ -446,17 +447,17 @@ func watchDelta(ctx context.Context, g *LimitGroup, c *atomic.Int64, limit int64
continue
} else if maxDelta > 0 {
x := delta / maxDelta
if x < 1.2 {
if x < 1 {
continue
}
limit += int64(x)
limit += min(int64(x), int64(runtime.NumCPU()))
slog.Debug("setting", "limit", limit)
g.SetLimit(limit)
}
// 3s cooldown period
nextUpdate = time.Now().Add(3 * time.Second)
nextUpdate = time.Now().Add(2 * time.Second)
maxDelta = delta
case <-ctx.Done():