Skip to content

Commit

Permalink
When adding a VU to the pool wait for it the goroutine to starting
Browse files Browse the repository at this point in the history
This helps with the fact that there is no gurantee currently that just
because we have added 100 VUs any of them had actually started wait for
an iteration.

This likely has some downside in creating more channels when adding VUs
back and forth but it should be minimal compared to the amount of work
needed to call a JS function.

This additionally could've meant that for high rate runs it was possible
for not all VUs to be available leading to k6 not actually being able to
run iterations at the given rate even though it should've been able if
all the VUs had actually started.
  • Loading branch information
mstoykov committed May 21, 2021
1 parent db89d21 commit 5df0e6b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/executor/ramping_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,18 @@ func (p *activeVUPool) Running() uint64 {
// When a new request is accepted the runfn function is executed.
func (p *activeVUPool) AddVU(ctx context.Context, avu lib.ActiveVU, runfn func(context.Context, lib.ActiveVU) bool) {
p.wg.Add(1)
ch := make(chan struct{})
go func() {
defer p.wg.Done()

close(ch)
for range p.iterations {
atomic.AddUint64(&p.running, uint64(1))
runfn(ctx, avu)
atomic.AddUint64(&p.running, ^uint64(0))
}
}()
<-ch
}

// Close stops the pool from accepting requests
Expand Down

0 comments on commit 5df0e6b

Please sign in to comment.