How to use GetMaxVUs method of executor Package

Best K6 code snippet using executor.GetMaxVUs

constant_arrival_rate.go

Source:constant_arrival_rate.go Github

copy

Full Screen

...68// GetPreAllocatedVUs is just a helper method that returns the scaled pre-allocated VUs.69func (carc ConstantArrivalRateConfig) GetPreAllocatedVUs(et *lib.ExecutionTuple) int64 {70 return et.ScaleInt64(carc.PreAllocatedVUs.Int64)71}72// GetMaxVUs is just a helper method that returns the scaled max VUs.73func (carc ConstantArrivalRateConfig) GetMaxVUs(et *lib.ExecutionTuple) int64 {74 return et.ScaleInt64(carc.MaxVUs.Int64)75}76// GetDescription returns a human-readable description of the executor options77func (carc ConstantArrivalRateConfig) GetDescription(et *lib.ExecutionTuple) string {78 preAllocatedVUs, maxVUs := carc.GetPreAllocatedVUs(et), carc.GetMaxVUs(et)79 maxVUsRange := fmt.Sprintf("maxVUs: %d", preAllocatedVUs)80 if maxVUs > preAllocatedVUs {81 maxVUsRange += fmt.Sprintf("-%d", maxVUs)82 }83 timeUnit := carc.TimeUnit.TimeDuration()84 var arrRatePerSec float6485 if maxVUs != 0 { // TODO: do something better?86 ratio := big.NewRat(maxVUs, carc.MaxVUs.Int64)87 arrRate := big.NewRat(carc.Rate.Int64, int64(timeUnit))88 arrRate.Mul(arrRate, ratio)89 arrRatePerSec, _ = getArrivalRatePerSec(arrRate).Float64()90 }91 return fmt.Sprintf("%.2f iterations/s for %s%s", arrRatePerSec, carc.Duration.Duration,92 carc.getBaseInfo(maxVUsRange))93}94// Validate makes sure all options are configured and valid95func (carc *ConstantArrivalRateConfig) Validate() []error {96 errors := carc.BaseConfig.Validate()97 if !carc.Rate.Valid {98 errors = append(errors, fmt.Errorf("the iteration rate isn't specified"))99 } else if carc.Rate.Int64 <= 0 {100 errors = append(errors, fmt.Errorf("the iteration rate must be more than 0"))101 }102 if carc.TimeUnit.TimeDuration() <= 0 {103 errors = append(errors, fmt.Errorf("the timeUnit must be more than 0"))104 }105 if !carc.Duration.Valid {106 errors = append(errors, fmt.Errorf("the duration is unspecified"))107 } else if carc.Duration.TimeDuration() < minDuration {108 errors = append(errors, fmt.Errorf(109 "the duration must be at least %s, but is %s", minDuration, carc.Duration,110 ))111 }112 if !carc.PreAllocatedVUs.Valid {113 errors = append(errors, fmt.Errorf("the number of preAllocatedVUs isn't specified"))114 } else if carc.PreAllocatedVUs.Int64 < 0 {115 errors = append(errors, fmt.Errorf("the number of preAllocatedVUs can't be negative"))116 }117 if !carc.MaxVUs.Valid {118 // TODO: don't change the config while validating119 carc.MaxVUs.Int64 = carc.PreAllocatedVUs.Int64120 } else if carc.MaxVUs.Int64 < carc.PreAllocatedVUs.Int64 {121 errors = append(errors, fmt.Errorf("maxVUs can't be less than preAllocatedVUs"))122 }123 return errors124}125// GetExecutionRequirements returns the number of required VUs to run the126// executor for its whole duration (disregarding any startTime), including the127// maximum waiting time for any iterations to gracefully stop. This is used by128// the execution scheduler in its VU reservation calculations, so it knows how129// many VUs to pre-initialize.130func (carc ConstantArrivalRateConfig) GetExecutionRequirements(et *lib.ExecutionTuple) []lib.ExecutionStep {131 return []lib.ExecutionStep{132 {133 TimeOffset: 0,134 PlannedVUs: uint64(et.ScaleInt64(carc.PreAllocatedVUs.Int64)),135 MaxUnplannedVUs: uint64(et.ScaleInt64(carc.MaxVUs.Int64) - et.ScaleInt64(carc.PreAllocatedVUs.Int64)),136 }, {137 TimeOffset: carc.Duration.TimeDuration() + carc.GracefulStop.TimeDuration(),138 PlannedVUs: 0,139 MaxUnplannedVUs: 0,140 },141 }142}143// NewExecutor creates a new ConstantArrivalRate executor144func (carc ConstantArrivalRateConfig) NewExecutor(145 es *lib.ExecutionState, logger *logrus.Entry,146) (lib.Executor, error) {147 return &ConstantArrivalRate{148 BaseExecutor: NewBaseExecutor(&carc, es, logger),149 config: carc,150 }, nil151}152// HasWork reports whether there is any work to be done for the given execution segment.153func (carc ConstantArrivalRateConfig) HasWork(et *lib.ExecutionTuple) bool {154 return carc.GetMaxVUs(et) > 0155}156// ConstantArrivalRate tries to execute a specific number of iterations for a157// specific period.158type ConstantArrivalRate struct {159 *BaseExecutor160 config ConstantArrivalRateConfig161 et *lib.ExecutionTuple162}163// Make sure we implement the lib.Executor interface.164var _ lib.Executor = &ConstantArrivalRate{}165// Init values needed for the execution166func (car *ConstantArrivalRate) Init(ctx context.Context) error {167 // err should always be nil, because Init() won't be called for executors168 // with no work, as determined by their config's HasWork() method.169 et, err := car.BaseExecutor.executionState.ExecutionTuple.GetNewExecutionTupleFromValue(car.config.MaxVUs.Int64)170 car.et = et171 car.iterSegIndex = lib.NewSegmentedIndex(et)172 return err173}174// Run executes a constant number of iterations per second.175//176// TODO: Split this up and make an independent component that can be reused177// between the constant and ramping arrival rate executors - that way we can178// keep the complexity in one well-architected part (with short methods and few179// lambdas :D), while having both config frontends still be present for maximum180// UX benefits. Basically, keep the progress bars and scheduling (i.e. at what181// time should iteration X begin) different, but keep everything else the same.182// This will allow us to implement https://github.com/k6io/k6/issues/1386183// and things like all of the TODOs below in one place only.184//nolint:funlen,cyclop185func (car ConstantArrivalRate) Run(parentCtx context.Context, out chan<- metrics.SampleContainer) (err error) {186 gracefulStop := car.config.GetGracefulStop()187 duration := car.config.Duration.TimeDuration()188 preAllocatedVUs := car.config.GetPreAllocatedVUs(car.executionState.ExecutionTuple)189 maxVUs := car.config.GetMaxVUs(car.executionState.ExecutionTuple)190 // TODO: refactor and simplify191 arrivalRate := getScaledArrivalRate(car.et.Segment, car.config.Rate.Int64, car.config.TimeUnit.TimeDuration())192 tickerPeriod := getTickerPeriod(arrivalRate).TimeDuration()193 arrivalRatePerSec, _ := getArrivalRatePerSec(arrivalRate).Float64()194 // Make sure the log and the progress bar have accurate information195 car.logger.WithFields(logrus.Fields{196 "maxVUs": maxVUs, "preAllocatedVUs": preAllocatedVUs, "duration": duration,197 "tickerPeriod": tickerPeriod, "type": car.config.GetType(),198 }).Debug("Starting executor run...")199 activeVUsWg := &sync.WaitGroup{}200 returnedVUs := make(chan struct{})201 startTime, maxDurationCtx, regDurationCtx, cancel := getDurationContexts(parentCtx, duration, gracefulStop)202 vusPool := newActiveVUPool()203 defer func() {...

Full Screen

Full Screen

GetMaxVUs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 exec := executor.NewConstantVUsConfig()4 exec.Duration = types.NullDurationFrom(10 * time.Second)5 exec.VUs = null.NewInt(100, false)6 exec.MaxVUs = null.NewInt(100, false)7 exe := executor.NewConstantVUs(exec, lib.GetState)8 fmt.Println(exe.GetMaxVUs())9}10import (11func main() {12 exec := executor.NewConstantVUsConfig()13 exec.Duration = types.NullDurationFrom(10 * time.Second)14 exec.VUs = null.NewInt(100, false)15 exec.MaxVUs = null.NewInt(100, false)16 exe := executor.NewConstantVUs(exec, lib.GetState)17 fmt.Println(exe.GetMaxDuration())18}19import (20func main() {21 exec := executor.NewConstantVUsConfig()22 exec.Duration = types.NullDurationFrom(10 * time.Second)23 exec.VUs = null.NewInt(100, false)24 exec.MaxVUs = null.NewInt(100, false)25 exe := executor.NewConstantVUs(exec, lib.GetState)26 fmt.Println(exe.GetStartVUs())27}

Full Screen

Full Screen

GetMaxVUs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r, err := lib.NewRunner(lib.Options{})4 if err != nil {5 panic(err)6 }7 script := []byte(`8 import { sleep } from "k6";9 export let options = {10 executors: {11 "constant-vus": {12 },13 "per-vu-iterations": {14 },15 "shared-iterations": {16 },17 "constant-arrival-rate": {18 },19 "ramping-arrival-rate": {20 { target: 20, duration: "10s" },21 { target: 0, duration: "10s" },22 },

Full Screen

Full Screen

GetMaxVUs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 logger := log.New(&testutils.SimpleLogWriter{Logger: log.NewLogger()}, "", 0)4 ctx, cancel := context.WithCancel(context.Background())5 defer cancel()6 executorConfig := executor.ConstantArrivalRateConfig{7 BaseConfig: executor.BaseConfig{8 GracefulStop: types.NullDurationFrom(10 * time.Second),9 StartTime: types.NullDurationFrom(5 * time.Second),10 Duration: types.NullDurationFrom(30 * time.Second),11 },12 TimeUnit: types.NullDurationFrom(1 * time.Second),13 }14 executor, err := executor.NewConstantArrivalRate(logger, executorConfig)15 if err != nil {16 fmt.Println("Error creating executor: ", err)17 }18 executorConfig1 := executor.ConstantArrivalRateConfig{19 BaseConfig: executor.BaseConfig{20 GracefulStop: types.NullDurationFrom(10 * time.Second),21 StartTime: types.NullDurationFrom(5 * time.Second),22 Duration: types.NullDurationFrom(30 * time.Second),23 },24 TimeUnit: types.NullDurationFrom(1 * time.Second),25 }26 executor1, err := executor.NewConstantArrivalRate(logger, executorConfig1)27 if err != nil {28 fmt.Println("Error creating executor: ", err)29 }30 executorConfig2 := executor.ConstantArrivalRateConfig{31 BaseConfig: executor.BaseConfig{32 GracefulStop: types.NullDurationFrom(10 * time.Second),33 StartTime: types.NullDurationFrom(5 * time.Second),34 Duration: types.NullDurationFrom(30 * time.Second),35 },36 TimeUnit: types.NullDurationFrom(1 * time.Second),37 }

Full Screen

Full Screen

GetMaxVUs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 e := executor.NewConstantVUs(1, 5)4 maxVUs, err := e.GetMaxVUs()5 if err != nil {6 fmt.Println(errors.Wrap(err, "error"))7 }8 fmt.Println(maxVUs)9}10import (11func main() {12 e := executor.NewConstantVUs(1, 5)13 VUs, err := e.GetVUs()14 if err != nil {15 fmt.Println(errors.Wrap(err, "error"))16 }17 fmt.Println(VUs)18}19import (20func main() {21 e := executor.NewConstantVUs(1, 5)22 duration, err := e.GetDuration()23 if err != nil {24 fmt.Println(errors.Wrap(err, "error"))25 }26 fmt.Println(duration)27}

Full Screen

Full Screen

GetMaxVUs

Using AI Code Generation

copy

Full Screen

1func main() {2 executor := GetMaxVUs()3 fmt.Println(executor)4}5func main() {6 executor := GetMaxVUs()7 fmt.Println(executor)8}9func main() {10 executor := GetMaxVUs()11 fmt.Println(executor)12}13func main() {14 executor := GetMaxVUs()15 fmt.Println(executor)16}17func main() {18 executor := GetMaxVUs()19 fmt.Println(executor)20}21func main() {22 executor := GetMaxVUs()23 fmt.Println(executor)24}25func main() {26 executor := GetMaxVUs()27 fmt.Println(executor)28}29func main() {30 executor := GetMaxVUs()31 fmt.Println(executor)32}33func main() {34 executor := GetMaxVUs()35 fmt.Println(executor)36}37func main() {38 executor := GetMaxVUs()39 fmt.Println(executor)40}41func main() {42 executor := GetMaxVUs()43 fmt.Println(executor)44}45func main() {46 executor := GetMaxVUs()47 fmt.Println(executor)48}49func main() {50 executor := GetMaxVUs()51 fmt.Println(executor)52}

Full Screen

Full Screen

GetMaxVUs

Using AI Code Generation

copy

Full Screen

1import(2func main(){3 fmt.Println(executor.GetMaxVUs())4}5import(6func main(){7 fmt.Println(executor.GetMaxVUs())8}9import(10func main(){11 fmt.Println(executor.GetMaxVUs())12}13import(14func main(){15 fmt.Println(executor.GetMaxVUs())16}17import(18func main(){19 fmt.Println(executor.GetMaxVUs())20}21import(22func main(){23 fmt.Println(executor.GetMaxVUs())24}25import(26func main(){27 fmt.Println(executor.GetMaxVUs())28}29import(

Full Screen

Full Screen

GetMaxVUs

Using AI Code Generation

copy

Full Screen

1func main() {2 executor := &lib.Executor{}3 executor.SetVUsMax(10)4 fmt.Println(executor.GetVUsMax())5}6GoLang GetVUsMax() Method7func (e *Executor) GetVUsMax() int8func main() {9 executor := &lib.Executor{}10 executor.SetVUsMax(10)11 fmt.Println(executor.GetVUsMax())12}13GoLang GetVUsInitialized() Method14func (e *Executor) GetVUsInitialized() int15func main() {16 executor := &lib.Executor{}17 executor.SetVUsInitialized(10)18 fmt.Println(executor.GetVUsInitialized())19}20GoLang GetVUsInitializedMax() Method21func (e *Executor) GetVUsInitializedMax() int22func main() {23 executor := &lib.Executor{}24 executor.SetVUsInitializedMax(10)25 fmt.Println(executor.GetVUsInitializedMax())26}27GoLang GetVUsInitializedMaxDuration() Method28func (e *Executor) GetVUsInitializedMaxDuration() time.Duration

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful