Skip to content

Commit

Permalink
WIP Examples restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić committed Jul 2, 2020
1 parent 95f1187 commit bf41ee7
Showing 1 changed file with 125 additions and 66 deletions.
191 changes: 125 additions & 66 deletions src/data/markdown/docs/01 guides/02 Using k6/14 Executors.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ executes faster will complete more iterations than others.
| `iterations` | integer | Total number of script iterations to execute across all VUs. | `1` |
| `maxDuration` | string | Maximum test duration before it's forcibly stopped (excluding `gracefulStop`). | `"10m"` |

#### Examples

- Execute 200 total iterations shared by 10 VUs with a maximum duration of 10 seconds.

<div class="code-group" data-props='{"labels": [ "shared-iters.js" ], "lineNumbers": "[true]"}'>

```js
import http from 'k6/http';

export let options = {
discardResponseBodies: true,
scenarios: {
contacts: { // arbitrary scenario name
executor: 'shared-iterations',
vus: 10,
iterations: 200,
maxDuration: '10s',
}
}
};

export default function() {
http.get('https://test.k6.io/contacts.php');
}
```

</div>

### Per VU iterations

Expand All @@ -71,6 +98,35 @@ Each VU executes an exact number of iterations.
| `iterations` | integer | Number of script iterations to execute with each VU. | `1` |
| `maxDuration` | string | Maximum test duration before it's forcibly stopped (excluding `gracefulStop`). | `"10m"` |

#### Examples

- Execute 20 iterations by 10 VUs *each*, for a total of 200 iterations, with a
maximum duration of 5 seconds.

<div class="code-group" data-props='{"labels": [ "shared-iters.js" ], "lineNumbers": "[true]"}'>

```js
import http from 'k6/http';

export let options = {
discardResponseBodies: true,
scenarios: {
contacts: {
executor: 'per-vu-iterations',
vus: 10,
iterations: 20,
maxDuration: '10s',
}
}
};

export default function() {
http.get('https://test.k6.io/contacts.php');
}
```

</div>


### Constant VUs

Expand Down Expand Up @@ -114,6 +170,39 @@ See the [arrival rate](#arrival-rate) section for details.
| `preAllocatedVUs` | integer | Number of VUs to pre-allocate before test start in order to preserve runtime resources. | - |
| `maxVUs` | integer | Maximum number of VUs to allow during the test run. | - |

#### Examples

- Execute a constant 200 RPS for 1 minute, allowing k6 to dynamically schedule up to 100 VUs.

Note that in order to reliably achieve a fixed request rate, it's recommended to keep
the function being executed very simple, with preferably only a single request call,
and no additional processing or `sleep()` calls.

<div class="code-group" data-props='{"labels": [ "constant-arr-rate.js" ], "lineNumbers": "[true]"}'>

```js
import http from 'k6/http';

export let options = {
discardResponseBodies: true,
scenarios: {
contacts: { // arbitrary scenario name
executor: 'constant-arrival-rate',
rate: 200, // 200 RPS, since timeUnit is the default 1s
duration: '1m',
preAllocatedVUs: 50,
maxVUs: 100,
}
}
};

export default function() {
http.get('https://test.k6.io/contacts.php');
}
```

</div>


### Ramping arrival rate

Expand All @@ -132,6 +221,41 @@ See the [arrival rate](#arrival-rate) section for details.
| `maxVUs` | integer | Maximum number of VUs to allow during the test run. | - |


#### Examples

- Execute a variable RPS test, starting at 50, ramping up to 200 and then back to 0,
over a 1 minute period:

<div class="code-group" data-props='{"labels": [ "ramping-arr-rate.js" ], "lineNumbers": "[true]"}'>

```js
import http from 'k6/http';

export let options = {
discardResponseBodies: true,
scenarios: {
contacts: {
executor: 'ramping-arrival-rate',
startRate: 50,
timeUnit: '1s',
preAllocatedVUs: 50,
maxVUs: 100,
stages: [
{ target: 200, duration: '30s' },
{ target: 0, duration: '30s' },
],
}
}
};

export default function() {
http.get('https://test.k6.io/contacts.php');
}
```

</div>


### Externally controlled

Control and scale execution at runtime via k6's REST API or the CLI.
Expand Down Expand Up @@ -210,72 +334,7 @@ because of `gracefulStop`, and some iterations were interrupted since they excee
the configured 3s of both `gracefulStop` and `gracefulRampDown`.


## Examples

- Execute a constant 200 RPS for 1 minute, allowing k6 to dynamically schedule up to 100 VUs.

Note that in order to reliably achieve a fixed request rate, it's recommended to keep
the function being executed very simple, with preferably only a single request call,
and no additional processing or `sleep()` calls.

<div class="code-group" data-props='{"labels": [ "constant-arr-rate.js" ], "lineNumbers": "[true]"}'>

```js
import http from 'k6/http';

export let options = {
discardResponseBodies: true,
scenarios: {
contacts: { // arbitrary scenario name
executor: 'constant-arrival-rate',
rate: 200, // 200 RPS, since timeUnit is the default 1s
duration: '1m',
preAllocatedVUs: 50,
maxVUs: 100,
}
}
};

export default function() {
http.get('https://test.k6.io/contacts.php');
}
```

</div>


- Execute a variable RPS test, starting at 50, ramping up to 200 and then back to 0,
over a 1 minute period:

<div class="code-group" data-props='{"labels": [ "ramping-arr-rate.js" ], "lineNumbers": "[true]"}'>

```js
import http from 'k6/http';

export let options = {
discardResponseBodies: true,
scenarios: {
contacts: {
executor: 'ramping-arrival-rate',
startRate: 50,
timeUnit: '1s',
preAllocatedVUs: 50,
maxVUs: 100,
stages: [
{ target: 200, duration: '30s' },
{ target: 0, duration: '30s' },
],
}
}
};

export default function() {
http.get('https://test.k6.io/contacts.php');
}
```

</div>

## Advanced examples

- Run as many iterations as possible with 50 VUs for 30s, and then run 100 iterations
per VU of another scenario.
Expand Down

0 comments on commit bf41ee7

Please sign in to comment.