mirror of
https://github.com/restic/restic.git
synced 2025-12-04 01:11:56 +00:00
adapt workers based on whether an operation is CPU or IO-bound
Use runtime.GOMAXPROCS(0) as worker count for CPU-bound tasks, repo.Connections() for IO-bound task and a combination if a task can be both. Streaming packs is treated as IO-bound as adding more worker cannot provide a speedup. Typical IO-bound tasks are download / uploading / deleting files. Decoding / Encoding / Verifying are usually CPU-bound. Several tasks are a combination of both, e.g. for combined download and decode functions. In the latter case add both limits together. As the backends have their own concurrency limits restic still won't download more than repo.Connections() files in parallel, but the additional workers can decode already downloaded data in parallel.
This commit is contained in:
@@ -12,8 +12,6 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
const numRepackWorkers = 8
|
||||
|
||||
// Repack takes a list of packs together with a list of blobs contained in
|
||||
// these packs. Each pack is loaded and the blobs listed in keepBlobs is saved
|
||||
// into a new pack. Returned is the list of obsolete packs which can then
|
||||
@@ -107,11 +105,10 @@ func repack(ctx context.Context, repo restic.Repository, dstRepo restic.Reposito
|
||||
return nil
|
||||
}
|
||||
|
||||
connectionLimit := dstRepo.Backend().Connections() - 1
|
||||
if connectionLimit > numRepackWorkers {
|
||||
connectionLimit = numRepackWorkers
|
||||
}
|
||||
for i := 0; i < int(connectionLimit); i++ {
|
||||
// as packs are streamed the concurrency is limited by IO
|
||||
// reduce by one to ensure that uploading is always possible
|
||||
repackWorkerCount := int(repo.Connections() - 1)
|
||||
for i := 0; i < repackWorkerCount; i++ {
|
||||
wg.Go(worker)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user