Skip to content

Commit a7d2866

Browse files
scenarios, rework top-level page (#934)
* scenarios, rework top-level page - Use bulleted description list to list benefits - Summarize executors instead of duplicating table - Add two scenarios to example, to show it's possible - Hide full log output - shorten options slug, and fix all references Early work for #808 Co-authored-by: Paul Balogh <[email protected]>
1 parent b93f5bc commit a7d2866

File tree

9 files changed

+100
-73
lines changed

9 files changed

+100
-73
lines changed

src/data/markdown/docs/07 extensions/01 Get started/04 Create/01 JavaScript Extensions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ INFO[0000] Active VUs: 2, Iteration: 2, VU ID: 2, VU ID from runtime: 2 source=
331331
## Things to keep in mind
332332

333333
- The code in the `default` function (or another function specified by
334-
[`exec`](/using-k6/scenarios/#common-options)) will be executed many
334+
[`exec`](/using-k6/scenarios/#options)) will be executed many
335335
times during a test run and possibly in parallel by thousands of VUs.
336336
Any operation of your extension should therefore be performant
337337
and [thread-safe](https://en.wikipedia.org/wiki/Thread_safety).

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios.md

+92-65
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ excerpt: 'Scenarios allow us to make in-depth configurations to how VUs and iter
44
hideFromSidebar: false
55
---
66

7-
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:
7+
Scenarios configure how VUs and iteration schedules in granular detail.
8+
With scenarios, you can model diverse _workloads_, or traffic patterns in load tests.
89

9-
- Multiple scenarios can be declared in the same script, and each one can
10-
independently execute a different JavaScript function, which makes organizing tests easier
11-
and more flexible.
12-
- Every scenario can use a distinct VU and iteration scheduling pattern,
13-
powered by a purpose-built [executor](#executors). This enables modeling
14-
of advanced execution patterns which can better simulate real-world traffic.
15-
- 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.
16-
- Different environment variables and metric tags can be set per scenario.
10+
Benefits of using scenarios include:
11+
- **Easier, more flexible test organization.** You can declare multiple scenarios in the same script,
12+
and each one can independently execute a different JavaScript function.
13+
- **Simulate more realistic traffic.**
14+
Every scenario can use a distinct VU and iteration scheduling pattern,
15+
powered by a purpose-built [executor](#scenario-executors).
16+
- **Parallel or sequential workloads.** 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.
17+
- **Granular results analysis.** Different environment variables and metric tags can be set per scenario.
1718

18-
## Configuration
19+
## Configure scenarios
1920

20-
Execution scenarios are primarily configured via the `scenarios` key of the exported `options` object
21-
in your test scripts. The key for each scenario can be an arbitrary, but unique, scenario name. It will
22-
appear in the result summary, tags, etc.
21+
To configure scenarios, use the `scenarios` key in the `options` object.
22+
You can give the scenario any name, as long as each scenario name in the script is unique.
23+
24+
The scenario name appears in the result summary, tags, and so on.
2325

2426
<CodeGroup labels={[]} lineNumbers={[true]}>
2527

@@ -50,41 +52,35 @@ export const options = {
5052

5153
</CodeGroup>
5254

53-
## Executors
54-
55-
[Executors](/using-k6/scenarios/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
56-
of traffic you want to model to test your services.
55+
## Scenario executors
5756

58-
Possible values for `executor` are the executor name separated by hyphens.
57+
For each k6 scenario, the VU workload is scheduled by an _executor_.
58+
For example, executors configure:
59+
- Whether VU traffic stays constant or changes
60+
- Whether to model traffic by iteration number or by VU arrival rate.
5961

60-
| Name | Value | Description |
61-
| ---------------------------------------------------------------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
62-
| [Shared iterations](/using-k6/scenarios/executors/shared-iterations) | `shared-iterations` | A fixed amount of iterations are<br/> "shared" between a number of VUs. |
63-
| [Per VU iterations](/using-k6/scenarios/executors/per-vu-iterations) | `per-vu-iterations` | Each VU executes an exact number of iterations. |
64-
| [Constant VUs](/using-k6/scenarios/executors/constant-vus) | `constant-vus` | A fixed number of VUs execute as many<br/> iterations as possible for a specified amount of time. |
65-
| [Ramping VUs](/using-k6/scenarios/executors/ramping-vus) | `ramping-vus` | A variable number of VUs execute as many<br/> iterations as possible for a specified amount of time. |
66-
| [Constant Arrival Rate](/using-k6/scenarios/executors/constant-arrival-rate) | `constant-arrival-rate` | A fixed number of iterations are executed<br/> in a specified period of time. |
67-
| [Ramping Arrival Rate](/using-k6/scenarios/executors/ramping-arrival-rate) | `ramping-arrival-rate` | A variable number of iterations are <br/> executed in a specified period of time. |
68-
| [Externally Controlled](/using-k6/scenarios/executors/externally-controlled) | `externally-controlled` | Control and scale execution at runtime<br/> via [k6's REST API](/misc/k6-rest-api) or the [CLI](https://k6.io/blog/how-to-control-a-live-k6-test). |
62+
Your scenario object must define the `executor` property with one of the predefined executors names.
63+
Along with the generic scenario options, each executor object has additional options specific to its workload.
64+
For the list of the executors, refer to the [Executor guide](/using-k6/scenarios/executors/).
6965

70-
## Common options
66+
## Scenario options {#options}
7167

7268
| Option | Type | Description | Default |
7369
| -------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
74-
| executor<sup>(required)</sup> ️ | string | Unique executor name. See the list of possible values in the [executors](#executors) section. | - |
70+
| executor<sup>(required)</sup> ️ | string | Unique executor name. See the list of possible values in the [executors](/using-k6/scenarios/executors/) section. | - |
7571
| startTime | string | Time offset since the start of the test, at which point this scenario should begin execution. | `"0s"` |
7672
| gracefulStop | string | Time to wait for iterations to finish executing before stopping them forcefully. Read more about gracefully stopping a test run [here](/using-k6/scenarios/graceful-stop/). | `"30s"` |
7773
| exec | string | Name of exported JS function to execute. | `"default"` |
7874
| env | object | Environment variables specific to this scenario. | `{}` |
7975
| tags | object | [Tags](/using-k6/tags-and-groups) specific to this scenario. | `{}` |
8076

81-
## Example
77+
## Scenario example
8278

8379
The following script defines two minimal scenarios:
8480

85-
<CodeGroup labels={[]} lineNumbers={[true]}>
81+
<CodeGroup labels={["scenario-example.js"]} lineNumbers={[true]}>
8682

87-
```bash
83+
```javascript
8884
import http from 'k6/http';
8985

9086
export const options = {
@@ -101,52 +97,83 @@ export const options = {
10197
};
10298

10399
export default function () {
104-
http.get('https://google.com/');
100+
http.get('https://test.k6.io/');
105101
}
106102
```
107103

108104
</CodeGroup>
109105

110-
Running the above script with `k6 run script.js`, additional information is added to the output as follows:
106+
If you run a script with scenarios, k6 output includes high-level information about each one.
107+
For example, if you run the preceding script, `k6 run scenario-example.js`,
108+
then k6 reports the scenarios as follows:
111109

112-
<CodeGroup labels={[]} lineNumbers={[true]}>
110+
<CodeGroup labels={["scenario example output"]} lineNumbers={[false]}>
111+
112+
```bash
113+
execution: local
114+
script: scenario-example.js
115+
output: -
116+
117+
scenarios: (100.00%) 2 scenarios, 30 max VUs, 10m40s max duration (incl. graceful stop):
118+
* shared_iter_scenario: 100 iterations shared among 20 VUs
119+
(maxDuration: 10s, gracefulStop: 30s)
120+
* per_vu_scenario: 20 iterations for each of 10 VUs
121+
(maxDuration: 10m0s, startTime: 10s, gracefulStop: 30s)
122+
123+
124+
running (00m15.1s), 00/30 VUs, 300 complete and 0 interrupted iterations
125+
shared_iter_scenario ✓ [======================================] 20 VUs 03.0s/10s 100/100 shared iters
126+
per_vu_scenario ✓ [======================================] 10 VUs 00m05.1s/10m0s 200/200 iters, 20 per VU
127+
128+
```
129+
130+
</CodeGroup>
131+
132+
The full output includes the summary metrics, like any default end-of-test summary:
133+
134+
<Collapsible title="full scenario-example.js output" isOpen="" tag="">
135+
136+
<CodeGroup>
113137

114138
```bash
115-
/\ |‾‾| /‾‾/ /‾‾/
116-
/\ / \ | |/ / / /
117-
/ \/ \ | ( / ‾‾\
118-
/ \ | |\ \ | (‾) |
139+
/\ |‾‾| /‾‾/ /‾‾/
140+
/\ / \ | |/ / / /
141+
/ \/ \ | ( / ‾‾\
142+
/ \ | |\ \ | (‾) |
119143
/ __________ \ |__| \__\ \_____/ .io
120144

121145
execution: local
122-
script: .\scenario_example.js
146+
script: scenario-example.js
123147
output: -
124148

125-
scenarios: (100.00%) 2 scenarios, 2 max VUs, 10m35s max duration (incl. graceful stop):
126-
* example_scenario: 1 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
127-
* another_scenario: 1 iterations shared among 1 VUs (maxDuration: 10m0s, startTime: 5s, gracefulStop: 30s)
128-
129-
130-
running (00m05.2s), 0/2 VUs, 2 complete and 0 interrupted iterations
131-
example_scenario ✓ [======================================] 1 VUs 00m00.2s/10m0s 1/1 shared iters
132-
another_scenario ✓ [======================================] 1 VUs 00m00.2s/10m0s 1/1 shared iters
133-
134-
data_received..................: 54 kB 11 kB/s
135-
data_sent......................: 2.5 kB 486 B/s
136-
http_req_blocked...............: avg=53.45ms min=46.56ms med=48.42ms max=70.4ms p(90)=64.25ms p(95)=67.32ms
137-
http_req_connecting............: avg=19.95ms min=18.62ms med=19.93ms max=21.3ms p(90)=21.26ms p(95)=21.28ms
138-
http_req_duration..............: avg=46.16ms min=25.82ms med=45.6ms max=67.6ms p(90)=65.63ms p(95)=66.61ms
139-
{ expected_response:true }...: avg=46.16ms min=25.82ms med=45.6ms max=67.6ms p(90)=65.63ms p(95)=66.61ms
140-
http_req_failed................: 0.00% ✓ 0 ✗ 4
141-
http_req_receiving.............: avg=3.56ms min=305.8µs med=3.05ms max=7.84ms p(90)=7.01ms p(95)=7.43ms
142-
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
143-
http_req_tls_handshaking.......: avg=32.68ms min=27.63ms med=27.99ms max=47.09ms p(90)=41.43ms p(95)=44.26ms
144-
http_req_waiting...............: avg=42.46ms min=24.78ms med=42.64ms max=59.75ms p(90)=58.45ms p(95)=59.1ms
145-
http_reqs......................: 4 0.771306/s
146-
iteration_duration.............: avg=199.23ms min=182.79ms med=199.23ms max=215.67ms p(90)=212.38ms p(95)=214.03ms
147-
iterations.....................: 2 0.385653/s
148-
vus............................: 0 min=0 max=0
149-
vus_max........................: 2 min=2 max=2
149+
scenarios: (100.00%) 2 scenarios, 30 max VUs, 10m40s max duration (incl. graceful stop):
150+
* shared_iter_scenario: 100 iterations shared among 20 VUs (maxDuration: 10s, gracefulStop: 30s)
151+
* per_vu_scenario: 20 iterations for each of 10 VUs (maxDuration: 10m0s, startTime: 10s, gracefulStop: 30s)
152+
153+
154+
running (00m15.1s), 00/30 VUs, 300 complete and 0 interrupted iterations
155+
shared_iter_scenario ✓ [======================================] 20 VUs 03.0s/10s 100/100 shared iters
156+
per_vu_scenario ✓ [======================================] 10 VUs 00m05.1s/10m0s 200/200 iters, 20 per VU
157+
158+
data_received..................: 3.6 MB 240 kB/s
159+
data_sent......................: 40 kB 2.6 kB/s
160+
http_req_blocked...............: avg=54.48ms min=4.1µs med=8.23µs max=747.12ms p(90)=47.99ms p(95)=567.6ms
161+
http_req_connecting............: avg=27.62ms min=0s med=0s max=281.12ms p(90)=26.86ms p(95)=279.32ms
162+
http_req_duration..............: avg=210.21ms min=172.25ms med=204.01ms max=1.87s p(90)=206.18ms p(95)=306.99ms
163+
{ expected_response:true }...: avg=210.21ms min=172.25ms med=204.01ms max=1.87s p(90)=206.18ms p(95)=306.99ms
164+
http_req_failed................: 0.00% ✓ 0 ✗ 300
165+
http_req_receiving.............: avg=1.77ms min=82.11µs med=149.11µs max=186.39ms p(90)=233.56µs p(95)=304.91µs
166+
http_req_sending...............: avg=42.26µs min=10.68µs med=37.88µs max=220.62µs p(90)=47.68µs p(95)=70.59µs
167+
http_req_tls_handshaking.......: avg=23.02ms min=0s med=0s max=410.87ms p(90)=20.91ms p(95)=230.64ms
168+
http_req_waiting...............: avg=208.39ms min=172.02ms med=203.78ms max=1.69s p(90)=205.97ms p(95)=233.38ms
169+
http_reqs......................: 300 19.886852/s
170+
iteration_duration.............: avg=264.92ms min=172.48ms med=204.54ms max=1.87s p(90)=680.75ms p(95)=751.6ms
171+
iterations.....................: 300 19.886852/s
172+
vus............................: 1 min=0 max=20
173+
vus_max........................: 30 min=30 max=30
174+
150175
```
151176
152177
</CodeGroup>
178+
179+
</Collapsible>

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios/01 Executors/01 shared-iterations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Note that iterations aren't fairly distributed with this executor, and a VU that
1111

1212
## Options
1313

14-
In addition to the [common configuration options](/using-k6/scenarios#common-options) this executor
14+
In addition to the [common configuration options](/using-k6/scenarios#options) this executor
1515
also adds the following options:
1616

1717
| Option | Type | Description | Default |

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios/01 Executors/02 per-vu-iterations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ iterations will be `vus * iterations`.
1010

1111
## Options
1212

13-
In addition to the [common configuration options](/using-k6/scenarios#common-options) this executor
13+
In addition to the [common configuration options](/using-k6/scenarios#options) this executor
1414
also adds the following options:
1515

1616
| Option | Type | Description | Default |

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios/01 Executors/03 constant-vus.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ of time. This executor is equivalent to the global [vus](/using-k6/options#vus)
1010

1111
## Options
1212

13-
In addition to the [common configuration options](/using-k6/scenarios#common-options) this executor
13+
In addition to the [common configuration options](/using-k6/scenarios#options) this executor
1414
also adds the following options:
1515

1616
| Option | Type | Description | Default |

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios/01 Executors/04 ramping-vus.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ amount of time. This executor is equivalent to the global [stages](/using-k6/opt
1010

1111
## Options
1212

13-
In addition to the [common configuration options](/using-k6/scenarios#common-options) this executor
13+
In addition to the [common configuration options](/using-k6/scenarios#options) this executor
1414
also adds the following options:
1515

1616
| Option | Type | Description | Default |

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios/01 Executors/05 constant-arrival-rate.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See the [arrival rate](/using-k6/scenarios/arrival-rate) section for details.
1717

1818
## Options
1919

20-
In addition to the [common configuration options](/using-k6/scenarios#common-options) this executor
20+
In addition to the [common configuration options](/using-k6/scenarios#options) this executor
2121
also adds the following options:
2222

2323
| Option | Type | Description | Default |

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios/01 Executors/06 ramping-arrival-rate.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the [arrival rate](/using-k6/scenarios/arrival-rate) section for details.
1313

1414
## Options
1515

16-
In addition to the [common configuration options](/using-k6/scenarios#common-options) this executor
16+
In addition to the [common configuration options](/using-k6/scenarios#options) this executor
1717
also adds the following options:
1818

1919
| Option | Type | Description | Default |

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios/01 Executors/07 externally-controlled.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ maximum VUs will only affect the externally controlled executor.
1717

1818
## Options
1919

20-
In addition to the [common configuration options](/using-k6/scenarios#common-options) this executor
20+
In addition to the [common configuration options](/using-k6/scenarios#options) this executor
2121
also adds the following options:
2222

2323
| Option | Type | Description | Default |

0 commit comments

Comments
 (0)