Skip to content

Commit

Permalink
Remove scenario specific VU IDs
Browse files Browse the repository at this point in the history
We might want to eventually add this back once we determine the
usefulness of it, possibly with a global (across instances) variant.

Resolves #1863 (comment)
  • Loading branch information
Ivan Mirić committed Jun 21, 2021
1 parent b515245 commit 0279c67
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 56 deletions.
9 changes: 0 additions & 9 deletions js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ func (r *Runner) newVU(idLocal, idGlobal uint64, samplesOut chan<- stats.SampleC
Console: r.console,
BPool: bpool.NewBufferPool(100),
Samples: samplesOut,
scenarioID: make(map[string]uint64),
scenarioIter: make(map[string]uint64),
}

Expand Down Expand Up @@ -547,8 +546,6 @@ type VU struct {
setupData goja.Value

state *lib.State
// ID of this VU in each scenario
scenarioID map[string]uint64
// count of iterations executed by this VU in each scenario
scenarioIter map[string]uint64
}
Expand Down Expand Up @@ -616,12 +613,6 @@ func (u *VU) Activate(params *lib.VUActivationParams) lib.ActiveVU {
ctx = lib.WithState(ctx, u.state)
params.RunContext = ctx
*u.Context = ctx
if params.GetNextScVUID != nil {
if _, ok := u.scenarioID[params.Scenario]; !ok {
u.state.VUIDScenario = params.GetNextScVUID()
u.scenarioID[params.Scenario] = u.state.VUIDScenario
}
}

u.state.GetScenarioVUIter = func() uint64 {
return u.scenarioIter[params.Scenario]
Expand Down
9 changes: 0 additions & 9 deletions lib/executor/base_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"context"
"strconv"
"sync"
"sync/atomic"

"github.com/sirupsen/logrus"

Expand All @@ -40,7 +39,6 @@ import (
type BaseExecutor struct {
config lib.ExecutorConfig
executionState *lib.ExecutionState
VUIDLocal *uint64 // counter for assigning executor-specific VU IDs
iterSegIndexMx *sync.Mutex
iterSegIndex *lib.SegmentedIndex
logger *logrus.Entry
Expand All @@ -53,7 +51,6 @@ func NewBaseExecutor(config lib.ExecutorConfig, es *lib.ExecutionState, logger *
return &BaseExecutor{
config: config,
executionState: es,
VUIDLocal: new(uint64),
logger: logger,
iterSegIndexMx: new(sync.Mutex),
iterSegIndex: segIdx,
Expand Down Expand Up @@ -83,12 +80,6 @@ func (bs *BaseExecutor) GetConfig() lib.ExecutorConfig {
return bs.config
}

// getNextLocalVUID increments and returns the next VU ID that's specific for
// this executor (i.e. not global like __VU).
func (bs *BaseExecutor) getNextLocalVUID() uint64 {
return atomic.AddUint64(bs.VUIDLocal, 1)
}

// GetLogger returns the executor logger entry.
func (bs *BaseExecutor) GetLogger() *logrus.Entry {
return bs.logger
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/constant_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (car ConstantArrivalRate) Run(parentCtx context.Context, out chan<- stats.S
activeVUsWg.Add(1)
activeVU := initVU.Activate(getVUActivationParams(
maxDurationCtx, car.config.BaseConfig, returnVU,
car.getNextLocalVUID, car.nextIterationCounters,
car.nextIterationCounters,
))
car.executionState.ModCurrentlyActiveVUsCount(+1)
atomic.AddUint64(&activeVUsCount, 1)
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/constant_vus.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (clv ConstantVUs) Run(parentCtx context.Context, out chan<- stats.SampleCon

activeVU := initVU.Activate(
getVUActivationParams(ctx, clv.config.BaseConfig, returnVU,
clv.getNextLocalVUID, clv.nextIterationCounters))
clv.nextIterationCounters))

for {
select {
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/externally_controlled.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (rs *externallyControlledRunState) newManualVUHandle(
ctx, cancel := context.WithCancel(rs.ctx)
return &manualVUHandle{
vuHandle: newStoppedVUHandle(ctx, getVU, returnVU,
rs.executor.getNextLocalVUID, rs.executor.nextIterationCounters,
rs.executor.nextIterationCounters,
&rs.executor.config.BaseConfig, logger),
initVU: initVU,
wg: &wg,
Expand Down
3 changes: 1 addition & 2 deletions lib/executor/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func getArrivalRatePerSec(scaledArrivalRate *big.Rat) *big.Rat {
// TODO: Refactor this, maybe move all scenario things to an embedded struct?
func getVUActivationParams(
ctx context.Context, conf BaseConfig, deactivateCallback func(lib.InitializedVU),
getNextScVUID func() uint64, nextIterationCounters func() (uint64, uint64),
nextIterationCounters func() (uint64, uint64),
) *lib.VUActivationParams {
return &lib.VUActivationParams{
RunContext: ctx,
Expand All @@ -234,7 +234,6 @@ func getVUActivationParams(
Env: conf.GetEnv(),
Tags: conf.GetTags(),
DeactivateCallback: deactivateCallback,
GetNextScVUID: getNextScVUID,
GetNextIterationCounters: nextIterationCounters,
}
}
2 changes: 1 addition & 1 deletion lib/executor/per_vu_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (pvi PerVUIterations) Run(parentCtx context.Context, out chan<- stats.Sampl
vuID := initVU.GetID()
activeVU := initVU.Activate(
getVUActivationParams(ctx, pvi.config.BaseConfig, returnVU,
pvi.getNextLocalVUID, pvi.nextIterationCounters))
pvi.nextIterationCounters))

for i := int64(0); i < iterations; i++ {
select {
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/ramping_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func (varr RampingArrivalRate) Run(parentCtx context.Context, out chan<- stats.S
activeVU := initVU.Activate(
getVUActivationParams(
maxDurationCtx, varr.config.BaseConfig, returnVU,
varr.getNextLocalVUID, varr.nextIterationCounters))
varr.nextIterationCounters))
varr.executionState.ModCurrentlyActiveVUsCount(+1)
atomic.AddUint64(&activeVUsCount, 1)

Expand Down
5 changes: 2 additions & 3 deletions lib/executor/ramping_vus.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,8 @@ func (vlv RampingVUs) Run(parentCtx context.Context, out chan<- stats.SampleCont
vuHandles := make([]*vuHandle, maxVUs)
for i := uint64(0); i < maxVUs; i++ {
vuHandle := newStoppedVUHandle(
maxDurationCtx, getVU, returnVU, vlv.getNextLocalVUID,
vlv.nextIterationCounters, &vlv.config.BaseConfig,
vlv.logger.WithField("vuNum", i))
maxDurationCtx, getVU, returnVU, vlv.nextIterationCounters,
&vlv.config.BaseConfig, vlv.logger.WithField("vuNum", i))
go vuHandle.runLoopsIfPossible(runIteration)
vuHandles[i] = vuHandle
}
Expand Down
4 changes: 1 addition & 3 deletions lib/executor/shared_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ func (si SharedIterations) Run(parentCtx context.Context, out chan<- stats.Sampl
defer cancel()

activeVU := initVU.Activate(getVUActivationParams(
ctx, si.config.BaseConfig, returnVU, si.getNextLocalVUID,
si.nextIterationCounters,
))
ctx, si.config.BaseConfig, returnVU, si.nextIterationCounters))

for {
select {
Expand Down
7 changes: 2 additions & 5 deletions lib/executor/vu_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ type vuHandle struct {
parentCtx context.Context
getVU func() (lib.InitializedVU, error)
returnVU func(lib.InitializedVU)
getScenarioVUID func() uint64
nextIterationCounters func() (uint64, uint64)
config *BaseConfig

Expand All @@ -110,7 +109,7 @@ type vuHandle struct {

func newStoppedVUHandle(
parentCtx context.Context, getVU func() (lib.InitializedVU, error),
returnVU func(lib.InitializedVU), getScenarioVUID func() uint64,
returnVU func(lib.InitializedVU),
nextIterationCounters func() (uint64, uint64),
config *BaseConfig, logger *logrus.Entry,
) *vuHandle {
Expand All @@ -120,7 +119,6 @@ func newStoppedVUHandle(
mutex: &sync.Mutex{},
parentCtx: parentCtx,
getVU: getVU,
getScenarioVUID: getScenarioVUID,
nextIterationCounters: nextIterationCounters,
config: config,

Expand Down Expand Up @@ -153,8 +151,7 @@ func (vh *vuHandle) start() (err error) {
}

vh.activeVU = vh.initVU.Activate(getVUActivationParams(
vh.ctx, *vh.config, vh.returnVU, vh.getScenarioVUID,
vh.nextIterationCounters))
vh.ctx, *vh.config, vh.returnVU, vh.nextIterationCounters))
close(vh.canStartIter)
vh.changeState(starting)
}
Expand Down
12 changes: 6 additions & 6 deletions lib/executor/vu_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestVUHandleRace(t *testing.T) {
}
}

vuHandle := newStoppedVUHandle(ctx, getVU, returnVU, nil, mockNextIterations, &BaseConfig{}, logEntry)
vuHandle := newStoppedVUHandle(ctx, getVU, returnVU, mockNextIterations, &BaseConfig{}, logEntry)
go vuHandle.runLoopsIfPossible(runIter)
var wg sync.WaitGroup
wg.Add(3)
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestVUHandleStartStopRace(t *testing.T) {
}
}

vuHandle := newStoppedVUHandle(ctx, getVU, returnVU, nil, mockNextIterations, &BaseConfig{}, logEntry)
vuHandle := newStoppedVUHandle(ctx, getVU, returnVU, mockNextIterations, &BaseConfig{}, logEntry)
go vuHandle.runLoopsIfPossible(runIter)
for i := 0; i < testIterations; i++ {
err := vuHandle.start()
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestVUHandleSimple(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

vuHandle := newStoppedVUHandle(ctx, test.getVU, test.returnVU, nil, mockNextIterations, &BaseConfig{}, logEntry)
vuHandle := newStoppedVUHandle(ctx, test.getVU, test.returnVU, mockNextIterations, &BaseConfig{}, logEntry)
var wg sync.WaitGroup
wg.Add(1)
go func() {
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestVUHandleSimple(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

vuHandle := newStoppedVUHandle(ctx, test.getVU, test.returnVU, nil, mockNextIterations, &BaseConfig{}, logEntry)
vuHandle := newStoppedVUHandle(ctx, test.getVU, test.returnVU, mockNextIterations, &BaseConfig{}, logEntry)
var wg sync.WaitGroup
wg.Add(1)
go func() {
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestVUHandleSimple(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

vuHandle := newStoppedVUHandle(ctx, test.getVU, test.returnVU, nil, mockNextIterations, &BaseConfig{}, logEntry)
vuHandle := newStoppedVUHandle(ctx, test.getVU, test.returnVU, mockNextIterations, &BaseConfig{}, logEntry)
var wg sync.WaitGroup
wg.Add(1)
go func() {
Expand Down Expand Up @@ -395,7 +395,7 @@ func BenchmarkVUHandleIterations(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

vuHandle := newStoppedVUHandle(ctx, getVU, returnVU, nil, mockNextIterations, &BaseConfig{}, logEntry)
vuHandle := newStoppedVUHandle(ctx, getVU, returnVU, mockNextIterations, &BaseConfig{}, logEntry)
var wg sync.WaitGroup
wg.Add(1)
go func() {
Expand Down
1 change: 0 additions & 1 deletion lib/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ type VUActivationParams struct {
DeactivateCallback func(InitializedVU)
Env, Tags map[string]string
Exec, Scenario string
GetNextScVUID func() uint64
GetNextIterationCounters func() (uint64, uint64)
}

Expand Down
6 changes: 3 additions & 3 deletions lib/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ type State struct {
// TODO: maybe use https://golang.org/pkg/sync/#Pool ?
BPool *bpool.BufferPool

VUID, VUIDGlobal, VUIDScenario uint64
Iteration int64
Tags map[string]string
VUID, VUIDGlobal uint64
Iteration int64
Tags map[string]string
// These will be assigned on VU activation.
// Returns the iteration number of this VU in the current scenario.
GetScenarioVUIter func() uint64
Expand Down
10 changes: 0 additions & 10 deletions lib/testutils/minirunner/minirunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (r *MiniRunner) NewVU(idLocal, idGlobal uint64, out chan<- stats.SampleCont
ID: idLocal,
IDGlobal: idGlobal,
state: state,
scenarioID: make(map[string]uint64),
scenarioIter: make(map[string]uint64),
}, nil
}
Expand Down Expand Up @@ -137,8 +136,6 @@ type VU struct {
ID, IDGlobal uint64
Iteration int64
state *lib.State
// ID of this VU in each scenario
scenarioID map[string]uint64
// count of iterations executed by this VU in each scenario
scenarioIter map[string]uint64
}
Expand All @@ -163,13 +160,6 @@ func (vu *VU) GetID() uint64 {
func (vu *VU) Activate(params *lib.VUActivationParams) lib.ActiveVU {
ctx := lib.WithState(params.RunContext, vu.state)

if params.GetNextScVUID != nil {
if _, ok := vu.scenarioID[params.Scenario]; !ok {
vu.state.VUIDScenario = params.GetNextScVUID()
vu.scenarioID[params.Scenario] = vu.state.VUIDScenario
}
}

vu.state.GetScenarioVUIter = func() uint64 {
return vu.scenarioIter[params.Scenario]
}
Expand Down

0 comments on commit 0279c67

Please sign in to comment.