No results for

Powered byAlgolia

Scenarios

Scenarios make in-depth configurations to how VUs and iterations are scheduled. This makes it possible to model diverse traffic patterns in load tests. Benefits of using scenarios include:

  • Multiple scenarios can be declared in the same script, and each one can independently execute a different JavaScript function, which makes organizing tests easier and more flexible.
  • Every scenario can use a distinct VU and iteration scheduling pattern, powered by a purpose-built executor. This enables modeling of advanced execution patterns which can better simulate real-world traffic.
  • Scenarios are independent from each other and run in parallel, though they can be made to appear sequential by setting the startTime property of each carefully.
  • Different environment variables and metric tags can be set per scenario.

Configuration

Execution scenarios are primarily configured via the scenarios key of the exported options object in your test scripts. The key for each scenario can be an arbitrary, but unique, scenario name. It will appear in the result summary, tags, etc.

1export const options = {
2 scenarios: {
3 example_scenario: {
4 // name of the executor to use
5 executor: 'shared-iterations',
6
7 // common scenario configuration
8 startTime: '10s',
9 gracefulStop: '5s',
10 env: { EXAMPLEVAR: 'testing' },
11 tags: { example_tag: 'testing' },
12
13 // executor-specific configuration
14 vus: 10,
15 iterations: 200,
16 maxDuration: '10s',
17 },
18 another_scenario: {
19 /*...*/
20 },
21 },
22};

Executors

Executors are the workhorses of the k6 execution engine. Each one schedules VUs and iterations differently, and you'll choose one depending on the type of traffic you want to model to test your services.

Possible values for executor are the executor name separated by hyphens.

NameValueDescription
Shared iterationsshared-iterationsA fixed amount of iterations are
"shared" between a number of VUs.
Per VU iterationsper-vu-iterationsEach VU executes an exact number of iterations.
Constant VUsconstant-vusA fixed number of VUs execute as many
iterations as possible for a specified amount of time.
Ramping VUsramping-vusA variable number of VUs execute as many
iterations as possible for a specified amount of time.
Constant Arrival Rateconstant-arrival-rateA fixed number of iterations are executed
in a specified period of time.
Ramping Arrival Rateramping-arrival-rateA variable number of iterations are
executed in a specified period of time.
Externally Controlledexternally-controlledControl and scale execution at runtime
via k6's REST API or the CLI.

Common options

OptionTypeDescriptionDefault
executor(required)stringUnique executor name. See the list of possible values in the executors section.-
startTimestringTime offset since the start of the test, at which point this scenario should begin execution."0s"
gracefulStopstringTime to wait for iterations to finish executing before stopping them forcefully. Read more about gracefully stopping a test run here."30s"
execstringName of exported JS function to execute."default"
envobjectEnvironment variables specific to this scenario.{}
tagsobjectTags specific to this scenario.{}

Example

The following script defines two minimal scenarios:

1import http from 'k6/http';
2
3export const options = {
4 scenarios: {
5 example_scenario: {
6 executor: 'shared-iterations',
7 startTime: '0s'
8 },
9 another_scenario: {
10 executor: 'shared-iterations',
11 startTime: '5s'
12 },
13 },
14};
15
16export default function () {
17 http.get('https://google.com/');
18}

Running the above script with k6 run script.js, additional information is added to the output as follows:

1 /\ |‾‾| /‾‾/ /‾‾/
2 /\ / \ | |/ / / /
3 / \/ \ | ( / ‾‾\
4 / \ | |\ \ | () |
5 / __________ \ |__| \__\ \_____/ .io
6
7 execution: local
8 script: .\scenario_example.js
9 output: -
10
11 scenarios: (100.00%) 2 scenarios, 2 max VUs, 10m35s max duration (incl. graceful stop):
12 * example_scenario: 1 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
13 * another_scenario: 1 iterations shared among 1 VUs (maxDuration: 10m0s, startTime: 5s, gracefulStop: 30s)
14
15
16running (00m05.2s), 0/2 VUs, 2 complete and 0 interrupted iterations
17example_scenario ✓ [======================================] 1 VUs 00m00.2s/10m0s 1/1 shared iters
18another_scenario ✓ [======================================] 1 VUs 00m00.2s/10m0s 1/1 shared iters
19
20 data_received..................: 54 kB 11 kB/s
21 data_sent......................: 2.5 kB 486 B/s
22 http_req_blocked...............: avg=53.45ms min=46.56ms med=48.42ms max=70.4ms p(90)=64.25ms p(95)=67.32ms
23 http_req_connecting............: avg=19.95ms min=18.62ms med=19.93ms max=21.3ms p(90)=21.26ms p(95)=21.28ms
24 http_req_duration..............: avg=46.16ms min=25.82ms med=45.6ms max=67.6ms p(90)=65.63ms p(95)=66.61ms
25 { expected_response:true }...: avg=46.16ms min=25.82ms med=45.6ms max=67.6ms p(90)=65.63ms p(95)=66.61ms
26 http_req_failed................: 0.00% ✓ 04
27 http_req_receiving.............: avg=3.56ms min=305.8µs med=3.05ms max=7.84ms p(90)=7.01ms p(95)=7.43ms
28 http_req_sending...............: avg=132.85µs min=0s med=0s max=531.4µs p(90)=371.98µs p(95)=451.68µs
29 http_req_tls_handshaking.......: avg=32.68ms min=27.63ms med=27.99ms max=47.09ms p(90)=41.43ms p(95)=44.26ms
30 http_req_waiting...............: avg=42.46ms min=24.78ms med=42.64ms max=59.75ms p(90)=58.45ms p(95)=59.1ms
31 http_reqs......................: 4 0.771306/s
32 iteration_duration.............: avg=199.23ms min=182.79ms med=199.23ms max=215.67ms p(90)=212.38ms p(95)=214.03ms
33 iterations.....................: 2 0.385653/s
34 vus............................: 0 min=0 max=0
35 vus_max........................: 2 min=2 max=2