Skip to content

Commit

Permalink
Change defer order in variable-arrival-rate executor
Browse files Browse the repository at this point in the history
This does the same changes as the commit before for the
constant-arrival-rate executor, to avoid any potential hanging, since
both executors behave similarly.
  • Loading branch information
Ivan Mirić committed Apr 24, 2020
1 parent eb13303 commit d01e2c1
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/executor/variable_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,30 +292,29 @@ func (varr VariableArrivalRate) Run(ctx context.Context, out chan<- stats.Sample
maxArrivalRatePerSec, _ := getArrivalRatePerSec(getScaledArrivalRate(segment, maxUnscaledRate, timeUnit)).Float64()
startTickerPeriod := getTickerPeriod(startArrivalRate)

startTime, maxDurationCtx, regDurationCtx, cancel := getDurationContexts(ctx, duration, gracefulStop)
defer cancel()

// Make sure the log and the progress bar have accurate information
varr.logger.WithFields(logrus.Fields{
"maxVUs": maxVUs, "preAllocatedVUs": preAllocatedVUs, "duration": duration, "numStages": len(varr.config.Stages),
"startTickerPeriod": startTickerPeriod.Duration, "type": varr.config.GetType(),
}).Debug("Starting executor run...")

activeVUsWg := &sync.WaitGroup{}
defer activeVUsWg.Wait()

startTime, maxDurationCtx, regDurationCtx, cancel := getDurationContexts(ctx, duration, gracefulStop)
defer cancel()

// Pre-allocate the VUs local shared buffer
activeVUs := make(chan lib.ActiveVU, maxVUs)
activeVUsCount := uint64(0)
// Make sure we put planned and unplanned VUs back in the global buffer
// Make sure all VUs aren't executing iterations anymore, for the cancel()
// above to deactivate them.
defer func() {
currActiveVUs := atomic.LoadUint64(&activeVUsCount)
for i := uint64(0); i < currActiveVUs; i++ {
vu := <-activeVUs
varr.executionState.ReturnVU(vu.(lib.InitializedVU), false)
for i := uint64(0); i < activeVUsCount; i++ {
<-activeVUs
}
}()

activeVUsWg := &sync.WaitGroup{}
defer activeVUsWg.Wait()

activateVU := func(initVU lib.InitializedVU) lib.ActiveVU {
activeVUsWg.Add(1)
activeVU := initVU.Activate(&lib.VUActivationParams{
Expand Down Expand Up @@ -377,10 +376,7 @@ func (varr VariableArrivalRate) Run(ctx context.Context, out chan<- stats.Sample
regDurationDone := regDurationCtx.Done()
runIterationBasic := getIterationRunner(varr.executionState, varr.logger)
runIteration := func(vu lib.ActiveVU) {
ctx, cancel := context.WithCancel(maxDurationCtx)
defer cancel()

runIterationBasic(ctx, vu)
runIterationBasic(maxDurationCtx, vu)
activeVUs <- vu
}

Expand Down

0 comments on commit d01e2c1

Please sign in to comment.