From 4bb561d7a1240b671536cc48abe66b57ed9314c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 18 Nov 2021 18:42:34 +0300 Subject: [PATCH] Move runLoopsIfPossible goroutine creation to a function --- lib/executor/ramping_vus.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/executor/ramping_vus.go b/lib/executor/ramping_vus.go index 40bd422fea0..18a07b60306 100644 --- a/lib/executor/ramping_vus.go +++ b/lib/executor/ramping_vus.go @@ -551,10 +551,9 @@ func (vlv *RampingVUs) Run(ctx context.Context, _ chan<- stats.SampleContainer, go trackProgress(ctx, maxDurationCtx, regularDurationCtx, vlv, progressFn) defer runState.wg.Wait() - runState.populateVUHandles(maxDurationCtx, cancel) - for i := uint64(0); i < runState.maxVUs; i++ { - go runState.vuHandles[i].runLoopsIfPossible(runState.runIteration) - } + // this will populate stopped VUs and run runLoopsIfPossible on each VU + // handle in a new goroutine + runState.runLoopsIfPossible(maxDurationCtx, cancel) var ( handleNewMaxAllowedVUs = runState.maxAllowedVUsHandlerStrategy() @@ -603,7 +602,7 @@ func (rs *rampingVUsRunState) makeProgressFn(regular time.Duration) (progressFn } } -func (rs *rampingVUsRunState) populateVUHandles(ctx context.Context, cancel func()) { +func (rs *rampingVUsRunState) runLoopsIfPossible(ctx context.Context, cancel func()) { getVU := func() (lib.InitializedVU, error) { pvu, err := rs.executor.executionState.GetPlannedVU(rs.executor.logger, false) if err != nil { @@ -626,6 +625,7 @@ func (rs *rampingVUsRunState) populateVUHandles(ctx context.Context, cancel func rs.vuHandles[i] = newStoppedVUHandle( ctx, getVU, returnVU, rs.executor.nextIterationCounters, &rs.executor.config.BaseConfig, rs.executor.logger.WithField("vuNum", i)) + go rs.vuHandles[i].runLoopsIfPossible(rs.runIteration) } }