diff --git a/db/iterator.go b/db/iterator.go index 6fa3f0e1..338aac38 100644 --- a/db/iterator.go +++ b/db/iterator.go @@ -232,14 +232,16 @@ func (i *iterator) checkState(ctx context.Context) bool { func (i *iterator) setupWorkers(ctx context.Context) { + count := ints.Between(1, maxWorkers, workerCount) + if i.checkState(ctx) { switch { case i.tasks == 0: - for w := 1; w <= workerCount; w++ { + for w := 1; w <= count; w++ { go i.setupWorker(ctx, i.jobs, i.vals) } default: - for w := 1; w <= ints.Between(1, workerCount, i.tasks); w++ { + for w := 1; w <= ints.Between(1, count, i.tasks); w++ { go i.setupWorker(ctx, i.jobs, i.vals) } } diff --git a/db/vars.go b/db/vars.go index 5b2f1a85..efd33505 100644 --- a/db/vars.go +++ b/db/vars.go @@ -63,6 +63,10 @@ const ( ) var ( + // maxWorkers enables limiting the maximum number of + // workers to start, regardless of the CPU count. + maxWorkers = 1 + // workerCount specifies how many workers should be used // to process each query statement concurrently. workerCount = runtime.NumCPU() * 2