Enable limiting the maximum number of query workers

This commit is contained in:
Tobie Morgan Hitchcock 2018-04-18 15:49:32 +01:00
parent 3bc445ac05
commit e8accd1b8e
2 changed files with 8 additions and 2 deletions

View file

@ -232,14 +232,16 @@ func (i *iterator) checkState(ctx context.Context) bool {
func (i *iterator) setupWorkers(ctx context.Context) { func (i *iterator) setupWorkers(ctx context.Context) {
count := ints.Between(1, maxWorkers, workerCount)
if i.checkState(ctx) { if i.checkState(ctx) {
switch { switch {
case i.tasks == 0: case i.tasks == 0:
for w := 1; w <= workerCount; w++ { for w := 1; w <= count; w++ {
go i.setupWorker(ctx, i.jobs, i.vals) go i.setupWorker(ctx, i.jobs, i.vals)
} }
default: 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) go i.setupWorker(ctx, i.jobs, i.vals)
} }
} }

View file

@ -63,6 +63,10 @@ const (
) )
var ( 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 // workerCount specifies how many workers should be used
// to process each query statement concurrently. // to process each query statement concurrently.
workerCount = runtime.NumCPU() * 2 workerCount = runtime.NumCPU() * 2