mirror and cp support set the maximum number of threads (#5220)
This commit is contained in:
+5
-1
@@ -97,6 +97,10 @@ var (
|
||||
Name: "zip",
|
||||
Usage: "Extract from remote zip file (MinIO server source only)",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "max-workers",
|
||||
Usage: "maximum number of concurrent copies (default: autodetect)",
|
||||
},
|
||||
checksumFlag,
|
||||
}
|
||||
)
|
||||
@@ -366,7 +370,7 @@ func doCopySession(ctx context.Context, cancelCopy context.CancelFunc, cli *cli.
|
||||
|
||||
quitCh := make(chan struct{})
|
||||
statusCh := make(chan URLs)
|
||||
parallel := newParallelManager(statusCh)
|
||||
parallel := newParallelManager(statusCh, cli.Int("max-workers"))
|
||||
|
||||
go func() {
|
||||
gracefulStop := func() {
|
||||
|
||||
+6
-1
@@ -144,6 +144,10 @@ var (
|
||||
Name: "skip-errors",
|
||||
Usage: "skip any errors when mirroring",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "max-workers",
|
||||
Usage: "maximum number of concurrent copies (default: autodetect)",
|
||||
},
|
||||
checksumFlag,
|
||||
}
|
||||
)
|
||||
@@ -907,7 +911,7 @@ func newMirrorJob(srcURL, dstURL string, opts mirrorOptions) *mirrorJob {
|
||||
watcher: NewWatcher(UTCNow()),
|
||||
}
|
||||
|
||||
mj.parallel = newParallelManager(mj.statusCh)
|
||||
mj.parallel = newParallelManager(mj.statusCh, opts.maxWorkers)
|
||||
|
||||
// we'll define the status to use here,
|
||||
// do we want the quiet status? or the progressbar
|
||||
@@ -1025,6 +1029,7 @@ func runMirror(ctx context.Context, srcURL, dstURL string, cli *cli.Context, enc
|
||||
userMetadata: userMetadata,
|
||||
encKeyDB: encKeyDB,
|
||||
activeActive: isActiveActive,
|
||||
maxWorkers: cli.Int("max-workers"),
|
||||
}
|
||||
|
||||
// If we are not using active/active and we are not removing
|
||||
|
||||
@@ -278,6 +278,7 @@ type mirrorOptions struct {
|
||||
userMetadata map[string]string
|
||||
checksum minio.ChecksumType
|
||||
sourceListingOnly bool
|
||||
maxWorkers int
|
||||
}
|
||||
|
||||
// Prepares urls that need to be copied or removed based on requested options.
|
||||
|
||||
+10
-2
@@ -76,11 +76,18 @@ type ParallelManager struct {
|
||||
|
||||
// The maximum memory to use
|
||||
maxMem uint64
|
||||
|
||||
// The maximum workers will be created
|
||||
maxWorkers int
|
||||
}
|
||||
|
||||
// addWorker creates a new worker to process tasks
|
||||
func (p *ParallelManager) addWorker() {
|
||||
if atomic.LoadUint32(&p.workersNum) >= maxParallelWorkers {
|
||||
maxWorkers := maxParallelWorkers
|
||||
if p.maxWorkers > 0 {
|
||||
maxWorkers = p.maxWorkers
|
||||
}
|
||||
if int(atomic.LoadUint32(&p.workersNum)) >= maxWorkers {
|
||||
// Number of maximum workers is reached, no need to
|
||||
// to create a new one.
|
||||
return
|
||||
@@ -266,7 +273,7 @@ func availableMemory() (available uint64) {
|
||||
}
|
||||
|
||||
// newParallelManager starts new workers waiting for executing tasks
|
||||
func newParallelManager(resultCh chan URLs) *ParallelManager {
|
||||
func newParallelManager(resultCh chan URLs, maxWorkers int) *ParallelManager {
|
||||
p := &ParallelManager{
|
||||
wg: &sync.WaitGroup{},
|
||||
workersNum: 0,
|
||||
@@ -274,6 +281,7 @@ func newParallelManager(resultCh chan URLs) *ParallelManager {
|
||||
queueCh: make(chan task),
|
||||
resultCh: resultCh,
|
||||
maxMem: availableMemory(),
|
||||
maxWorkers: maxWorkers,
|
||||
}
|
||||
|
||||
// Start with runtime.NumCPU().
|
||||
|
||||
Reference in New Issue
Block a user