Skip to content

Commit

Permalink
Use uint64 for iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić committed Jun 21, 2021
1 parent 58946f2 commit a459dda
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 49 deletions.
18 changes: 10 additions & 8 deletions js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (r *Runner) newVU(id uint64, samplesOut chan<- stats.SampleContainer) (*VU,
BPool: bpool.NewBufferPool(100),
Samples: samplesOut,
scenarioID: make(map[string]uint64),
scenarioIter: make(map[string]int64),
scenarioIter: make(map[string]uint64),
***REMOVED***

vu.state = &lib.State***REMOVED***
Expand Down Expand Up @@ -547,7 +547,7 @@ type VU struct ***REMOVED***
// ID of this VU in each scenario
scenarioID map[string]uint64
// count of iterations executed by this VU in each scenario
scenarioIter map[string]int64
scenarioIter map[string]uint64
***REMOVED***

// Verify that interfaces are implemented
Expand Down Expand Up @@ -628,7 +628,7 @@ func (u *VU) Activate(params *lib.VUActivationParams) lib.ActiveVU ***REMOVED***
***REMOVED***
***REMOVED***

u.state.GetScenarioVUIter = func() int64 ***REMOVED***
u.state.GetScenarioVUIter = func() uint64 ***REMOVED***
return u.scenarioIter[params.Scenario]
***REMOVED***

Expand All @@ -638,17 +638,19 @@ func (u *VU) Activate(params *lib.VUActivationParams) lib.ActiveVU ***REMOVED***
busy: make(chan struct***REMOVED******REMOVED***, 1),
scenarioName: params.Scenario,
iterSync: params.IterSync,
scIterLocal: int64(-1),
scIterGlobal: int64(-1),
scIterLocal: ^uint64(0),
scIterGlobal: ^uint64(0),
getNextScLocalIter: params.GetNextScLocalIter,
getNextScGlobalIter: params.GetNextScGlobalIter,
***REMOVED***

u.state.GetScenarioLocalVUIter = func() int64 ***REMOVED***
u.state.GetScenarioLocalVUIter = func() uint64 ***REMOVED***
return avu.scIterLocal
***REMOVED***
u.state.GetScenarioGlobalVUIter = func() int64 ***REMOVED***
return avu.scIterGlobal
if params.GetNextScGlobalIter != nil ***REMOVED***
u.state.GetScenarioGlobalVUIter = func() uint64 ***REMOVED***
return avu.scIterGlobal
***REMOVED***
***REMOVED***

go func() ***REMOVED***
Expand Down
10 changes: 5 additions & 5 deletions lib/executor/base_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ type BaseExecutor struct ***REMOVED***
VUIDLocal *uint64 // counter for assigning executor-specific VU IDs
// Counter for keeping track of all VU iterations completed by this executor
// in the current (local) k6 instance.
iterLocal *int64
iterLocal *uint64
logger *logrus.Entry
progress *pb.ProgressBar
***REMOVED***

// NewBaseExecutor returns an initialized BaseExecutor
func NewBaseExecutor(config lib.ExecutorConfig, es *lib.ExecutionState, logger *logrus.Entry) *BaseExecutor ***REMOVED***
// Start at -1 so that the first iteration can be 0
startIterLocal := int64(-1)
// Start at max uint64 so that the first iteration can be 0
startIterLocal := ^uint64(0)
return &BaseExecutor***REMOVED***
config: config,
executionState: es,
Expand Down Expand Up @@ -83,8 +83,8 @@ func (bs BaseExecutor) getNextLocalVUID() uint64 ***REMOVED***

// getNextLocalIter increments and returns the next local iteration number, for
// keeping track of total iterations executed by this scenario/executor.
func (bs *BaseExecutor) getNextLocalIter() int64 ***REMOVED***
return atomic.AddInt64(bs.iterLocal, 1)
func (bs *BaseExecutor) getNextLocalIter() uint64 ***REMOVED***
return atomic.AddUint64(bs.iterLocal, 1)
***REMOVED***

// GetLogger returns the executor logger entry.
Expand Down
4 changes: 2 additions & 2 deletions lib/executor/constant_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ func (car *ConstantArrivalRate) Init(ctx context.Context) error ***REMOVED***
// this executor, taking into account the configured execution segment.
// Unlike the local iteration number returned by getNextLocalIter(), this
// iteration number will be unique across k6 instances.
func (car *ConstantArrivalRate) getNextGlobalIter() int64 ***REMOVED***
func (car *ConstantArrivalRate) getNextGlobalIter() uint64 ***REMOVED***
car.iterMx.Lock()
defer car.iterMx.Unlock()
car.segIdx.Next()
// iterations are 0-based
return car.segIdx.GetUnscaled() - 1
return uint64(car.segIdx.GetUnscaled() - 1)
***REMOVED***

// Run executes a constant number of iterations per second.
Expand Down
10 changes: 5 additions & 5 deletions lib/executor/constant_arrival_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ func TestConstantArrivalRateGlobalIters(t *testing.T) ***REMOVED***

testCases := []struct ***REMOVED***
seq, seg string
expIters []int64
expIters []uint64
***REMOVED******REMOVED***
***REMOVED***"0,1/4,3/4,1", "0:1/4", []int64***REMOVED***1, 6, 11, 16, 21***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "1/4:3/4", []int64***REMOVED***0, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19, 20***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "3/4:1", []int64***REMOVED***3, 8, 13, 18***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "0:1/4", []uint64***REMOVED***1, 6, 11, 16, 21***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "1/4:3/4", []uint64***REMOVED***0, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19, 20***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "3/4:1", []uint64***REMOVED***3, 8, 13, 18***REMOVED******REMOVED***,
***REMOVED***

for _, tc := range testCases ***REMOVED***
Expand All @@ -374,7 +374,7 @@ func TestConstantArrivalRateGlobalIters(t *testing.T) ***REMOVED***
ctx, cancel, executor, _ := setupExecutor(t, config, es, runner)
defer cancel()

gotIters := []int64***REMOVED******REMOVED***
gotIters := []uint64***REMOVED******REMOVED***
var mx sync.Mutex
runner.Fn = func(ctx context.Context, _ chan<- stats.SampleContainer) error ***REMOVED***
state := lib.GetState(ctx)
Expand Down
2 changes: 1 addition & 1 deletion 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 ***REMOVED***
// 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, getNextScLocalIter, getNextScGlobalIter func() int64,
getNextScVUID func() uint64, getNextScLocalIter, getNextScGlobalIter func() uint64,
iterSync chan struct***REMOVED******REMOVED***,
) *lib.VUActivationParams ***REMOVED***
return &lib.VUActivationParams***REMOVED***
Expand Down
4 changes: 2 additions & 2 deletions lib/executor/ramping_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ func (varr *RampingArrivalRate) Init(ctx context.Context) error ***REMOVED***
// this executor, taking into account the configured execution segment.
// Unlike the local iteration number returned by getNextLocalIter(), this
// iteration number will be unique across k6 instances.
func (varr *RampingArrivalRate) getNextGlobalIter() int64 ***REMOVED***
func (varr *RampingArrivalRate) getNextGlobalIter() uint64 ***REMOVED***
varr.iterMx.Lock()
defer varr.iterMx.Unlock()
varr.segIdx.Next()
// iterations are 0-based
return varr.segIdx.GetUnscaled() - 1
return uint64(varr.segIdx.GetUnscaled() - 1)
***REMOVED***

// cal calculates the transtitions between stages and gives the next full value produced by the
Expand Down
10 changes: 5 additions & 5 deletions lib/executor/ramping_arrival_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,11 @@ func TestRampingArrivalRateGlobalIters(t *testing.T) ***REMOVED***

testCases := []struct ***REMOVED***
seq, seg string
expIters []int64
expIters []uint64
***REMOVED******REMOVED***
***REMOVED***"0,1/4,3/4,1", "0:1/4", []int64***REMOVED***1, 6, 11, 16***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "1/4:3/4", []int64***REMOVED***0, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19, 20***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "3/4:1", []int64***REMOVED***3, 8, 13***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "0:1/4", []uint64***REMOVED***1, 6, 11, 16***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "1/4:3/4", []uint64***REMOVED***0, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19, 20***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "3/4:1", []uint64***REMOVED***3, 8, 13***REMOVED******REMOVED***,
***REMOVED***

for _, tc := range testCases ***REMOVED***
Expand All @@ -734,7 +734,7 @@ func TestRampingArrivalRateGlobalIters(t *testing.T) ***REMOVED***
ctx, cancel, executor, _ := setupExecutor(t, config, es, runner)
defer cancel()

gotIters := []int64***REMOVED******REMOVED***
gotIters := []uint64***REMOVED******REMOVED***
var mx sync.Mutex
runner.Fn = func(ctx context.Context, _ chan<- stats.SampleContainer) error ***REMOVED***
state := lib.GetState(ctx)
Expand Down
4 changes: 2 additions & 2 deletions lib/executor/shared_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ func (si *SharedIterations) Init(ctx context.Context) error ***REMOVED***
// this executor, taking into account the configured execution segment.
// Unlike the local iteration number returned by getNextLocalIter(), this
// iteration number will be unique across k6 instances.
func (si *SharedIterations) getNextGlobalIter() int64 ***REMOVED***
func (si *SharedIterations) getNextGlobalIter() uint64 ***REMOVED***
si.iterMx.Lock()
defer si.iterMx.Unlock()
si.segIdx.Next()
// iterations are 0-based
return si.segIdx.GetUnscaled() - 1
return uint64(si.segIdx.GetUnscaled() - 1)
***REMOVED***

// Run executes a specific total number of iterations, which are all shared by
Expand Down
10 changes: 5 additions & 5 deletions lib/executor/shared_iterations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ func TestSharedIterationsGlobalIters(t *testing.T) ***REMOVED***

testCases := []struct ***REMOVED***
seq, seg string
expIters []int64
expIters []uint64
***REMOVED******REMOVED***
***REMOVED***"0,1/4,3/4,1", "0:1/4", []int64***REMOVED***1, 6, 11, 16, 21, 26, 31, 36, 41, 46***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "1/4:3/4", []int64***REMOVED***0, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19, 20, 22, 24, 25, 27, 29, 30, 32, 34, 35, 37, 39, 40, 42, 44, 45, 47, 49***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "3/4:1", []int64***REMOVED***3, 8, 13, 18, 23, 28, 33, 38, 43, 48***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "0:1/4", []uint64***REMOVED***1, 6, 11, 16, 21, 26, 31, 36, 41, 46***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "1/4:3/4", []uint64***REMOVED***0, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19, 20, 22, 24, 25, 27, 29, 30, 32, 34, 35, 37, 39, 40, 42, 44, 45, 47, 49***REMOVED******REMOVED***,
***REMOVED***"0,1/4,3/4,1", "3/4:1", []uint64***REMOVED***3, 8, 13, 18, 23, 28, 33, 38, 43, 48***REMOVED******REMOVED***,
***REMOVED***

for _, tc := range testCases ***REMOVED***
Expand All @@ -178,7 +178,7 @@ func TestSharedIterationsGlobalIters(t *testing.T) ***REMOVED***
ctx, cancel, executor, _ := setupExecutor(t, config, es, runner)
defer cancel()

gotIters := []int64***REMOVED******REMOVED***
gotIters := []uint64***REMOVED******REMOVED***
var mx sync.Mutex
runner.Fn = func(ctx context.Context, _ chan<- stats.SampleContainer) error ***REMOVED***
state := lib.GetState(ctx)
Expand Down
4 changes: 2 additions & 2 deletions lib/executor/vu_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type vuHandle struct ***REMOVED***
getVU func() (lib.InitializedVU, error)
returnVU func(lib.InitializedVU)
getScenarioVUID func() uint64
getScenarioLocalIter func() int64
getScenarioLocalIter func() uint64
iterSync chan struct***REMOVED******REMOVED***
config *BaseConfig

Expand All @@ -112,7 +112,7 @@ type vuHandle struct ***REMOVED***
func newStoppedVUHandle(
parentCtx context.Context, getVU func() (lib.InitializedVU, error),
returnVU func(lib.InitializedVU), getScenarioVUID func() uint64,
getScenarioLocalIter func() int64, iterSync chan struct***REMOVED******REMOVED***,
getScenarioLocalIter func() uint64, iterSync chan struct***REMOVED******REMOVED***,
config *BaseConfig, logger *logrus.Entry,
) *vuHandle ***REMOVED***
ctx, cancel := context.WithCancel(parentCtx)
Expand Down
4 changes: 2 additions & 2 deletions lib/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type VUActivationParams struct ***REMOVED***
Exec, Scenario string
GetNextScVUID func() uint64
IterSync chan struct***REMOVED******REMOVED***
GetNextScLocalIter func() int64
GetNextScGlobalIter func() int64
GetNextScLocalIter func() uint64
GetNextScGlobalIter func() uint64
***REMOVED***

// A Runner is a factory for VUs. It should precompute as much as possible upon
Expand Down
20 changes: 10 additions & 10 deletions lib/testutils/minirunner/minirunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *MiniRunner) NewVU(id uint64, out chan<- stats.SampleContainer) (lib.Ini
ID: id,
state: state,
scenarioID: make(map[string]uint64),
scenarioIter: make(map[string]int64),
scenarioIter: make(map[string]uint64),
***REMOVED***, nil
***REMOVED***

Expand Down Expand Up @@ -140,7 +140,7 @@ type VU struct ***REMOVED***
// ID of this VU in each scenario
scenarioID map[string]uint64
// count of iterations executed by this VU in each scenario
scenarioIter map[string]int64
scenarioIter map[string]uint64
***REMOVED***

// ActiveVU holds a VU and its activation parameters
Expand All @@ -151,9 +151,9 @@ type ActiveVU struct ***REMOVED***

scenarioName string
iterSync chan struct***REMOVED******REMOVED***
getNextScLocalIter func() int64
getNextScGlobalIter func() int64
scIterLocal, scIterGlobal int64
getNextScLocalIter func() uint64
getNextScGlobalIter func() uint64
scIterLocal, scIterGlobal uint64
***REMOVED***

// GetID returns the unique VU ID.
Expand All @@ -172,7 +172,7 @@ func (vu *VU) Activate(params *lib.VUActivationParams) lib.ActiveVU ***REMOVED**
***REMOVED***
***REMOVED***

vu.state.GetScenarioVUIter = func() int64 ***REMOVED***
vu.state.GetScenarioVUIter = func() uint64 ***REMOVED***
return vu.scenarioIter[params.Scenario]
***REMOVED***

Expand All @@ -182,16 +182,16 @@ func (vu *VU) Activate(params *lib.VUActivationParams) lib.ActiveVU ***REMOVED**
busy: make(chan struct***REMOVED******REMOVED***, 1),
scenarioName: params.Scenario,
iterSync: params.IterSync,
scIterLocal: int64(-1),
scIterGlobal: int64(-1),
scIterLocal: ^uint64(0),
scIterGlobal: ^uint64(0),
getNextScLocalIter: params.GetNextScLocalIter,
getNextScGlobalIter: params.GetNextScGlobalIter,
***REMOVED***

vu.state.GetScenarioLocalVUIter = func() int64 ***REMOVED***
vu.state.GetScenarioLocalVUIter = func() uint64 ***REMOVED***
return avu.scIterLocal
***REMOVED***
vu.state.GetScenarioGlobalVUIter = func() int64 ***REMOVED***
vu.state.GetScenarioGlobalVUIter = func() uint64 ***REMOVED***
return avu.scIterGlobal
***REMOVED***

Expand Down

0 comments on commit a459dda

Please sign in to comment.