-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic slides for a beginner workshop
- Loading branch information
Showing
15 changed files
with
531 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# k6 checks | ||
|
||
--- | ||
|
||
## Our script | ||
|
||
```js | ||
import http from 'k6/http'; | ||
|
||
export default function() { | ||
let url = 'https://httpbin.test.k6.io/post'; | ||
let response = http.post(url, 'Hello world!'); | ||
|
||
console.log(response.json().data); | ||
} | ||
``` | ||
|
||
--- | ||
|
||
## Add checks to your script | ||
|
||
```js [1|3-6] | ||
import { check } from 'k6'; | ||
|
||
check(response, { | ||
'Application says hello': (r) => r.body.includes('Hello world!') | ||
}); | ||
} | ||
``` | ||
|
||
--- | ||
|
||
## Let's run our test again! | ||
|
||
Do you remember the command to run the test? 👀 | ||
|
||
```shell | ||
✓ Application says hello | ||
|
||
checks.........................: 100.00% ✓ 1 ✗ 0 | ||
``` | ||
|
||
--- | ||
|
||
## Failed checks | ||
|
||
```js | ||
check(response, { | ||
'Application says hello': (r) => r.body.includes('Bonjour!') | ||
}); | ||
} | ||
``` | ||
|
||
--- | ||
|
||
## Let's run our test again! | ||
|
||
```shell | ||
✗ Application says hello | ||
↳ 0% — ✓ 0 / ✗ 1 | ||
|
||
checks.........................: 0.00% ✓ 0 ✗ 1 | ||
``` | ||
|
||
--- | ||
|
||
## Failed checks are not errors! | ||
|
||
> 💡 To make failing checks stop your test, you can [combine them with thresholds](https://k6.io/docs/using-k6/thresholds/#failing-a-load-test-using-checks). | ||
--- | ||
|
||
## Making your scripts realistic with think time | ||
|
||
- Move to: [08-adding-think-time](?p=08-adding-think-time) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Think time | ||
|
||
--- | ||
|
||
## What is think time? | ||
|
||
The amount of time that a script pauses during test execution to simulate delays that real users have in the course of using an application. | ||
|
||
--- | ||
|
||
## When should you use think time? | ||
|
||
- If your test follows a user flow | ||
- If you want to simulate actions that take some time to carry out | ||
- Your load generator, or the machine you're running k6 from, displays high (> 80%) CPU utilization during test execution. | ||
|
||
--- | ||
|
||
## When should you **NOT** use think time? | ||
|
||
- You want to do a [stress test](https://k6.io/docs/test-types/stress-testing/) | ||
- The API endpoint you're testing experiences a high amount of requests per second in production that occur without delays | ||
- Your load generator can run your test script without crossing the 80% CPU utilization mark. | ||
|
||
--- | ||
|
||
## k6 Sleep | ||
|
||
```js [2|11] | ||
import http from 'k6/http'; | ||
import { check, sleep } from 'k6'; | ||
|
||
export default function() { | ||
let url = 'https://httpbin.test.k6.io/post'; | ||
let response = http.post(url, 'Hello world!'); | ||
check(response, { | ||
'Application says hello': (r) => r.body.includes('Hello world!') | ||
}); | ||
|
||
sleep(1); | ||
} | ||
``` | ||
|
||
--- | ||
|
||
**Sleep does not affect the response time (`http_req_duration`); the response time is always reported with sleep removed. Sleep is, however, included in the `iteration_duration`.** | ||
|
||
--- | ||
|
||
## Dynamic think time | ||
|
||
A dynamic think time is more realistic, and simulates real users more accurately. | ||
|
||
--- | ||
|
||
### Random sleep | ||
|
||
One way to implement dynamic think time is to use the JavaScript `Math.random()` function: | ||
|
||
```js | ||
sleep(Math.random() * 5); | ||
``` | ||
|
||
--- | ||
|
||
### Random sleep between | ||
|
||
```js [1|3] | ||
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.0.0/index.js"; | ||
|
||
sleep(randomIntBetween(1,5)); | ||
``` | ||
|
||
--- | ||
|
||
## How much think time should you add? | ||
|
||
The real answer is: it depends. | ||
|
||
--- | ||
|
||
## Let's move to scaling up your test | ||
|
||
- Move to: [09-load-test-options](?p=09-load-test-options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# k6 Load Test Options | ||
|
||
--- | ||
|
||
## Script options | ||
|
||
```js | ||
export let options = { | ||
vus: 10, | ||
iterations: 40, | ||
}; | ||
``` | ||
|
||
--- | ||
|
||
> 💡 If you only define VUs and no other test options, you may get the following error: | ||
```shell | ||
/\ |‾‾| /‾‾/ /‾‾/ | ||
/\ / \ | |/ / / / | ||
/ \/ \ | ( / ‾‾\ | ||
/ \ | |\ \ | (‾) | | ||
/ __________ \ |__| \__\ \_____/ .io | ||
|
||
WARN[0000] the `vus=10` option will be ignored, it only works in conjunction with `iterations`, `duration`, or `stages` | ||
execution: local | ||
script: test.js | ||
output: - | ||
``` | ||
--- | ||
## Iterations | ||
```js | ||
vus: 10, | ||
iterations: 40, | ||
``` | ||
> Setting the number of iterations in test options defines it for **all** users. | ||
--- | ||
## Duration | ||
```js | ||
vus: 10, | ||
duration: '2m' | ||
``` | ||
> Setting the duration instructs k6 to repeat the script for each of the VUs until the duration is reached. | ||
--- | ||
## Iterations and durations | ||
```js | ||
vus: 10, | ||
duration: '5m', | ||
iterations: 40, | ||
``` | ||
> If you set the duration in conjunction with setting the number of iterations, the value that ends earlier is used. | ||
--- | ||
## Stages | ||
Defining iterations and duration creates a _simple load profile_ | ||
![A simple load profile](../../images/load_profile-no_ramp-up_or_ramp-down.png) | ||
<!-- .element class="stretch" --> | ||
--- | ||
## Constand load profile | ||
What if you want to add a ramp-up or ramp-down, so that the profile looks more like this? | ||
![Constant load profile, with ramps](../../images/load_profile-constant.png.png) | ||
<!-- .element class="stretch" --> | ||
--- | ||
In that case, you may want to use [stages](https://k6.io/docs/using-k6/options/#stages). | ||
```js | ||
export let options = { | ||
stages: [ | ||
{ duration: '30m', target: 100 }, | ||
{ duration: '1h', target: 100 }, | ||
{ duration: '5m', target: 0 }, | ||
], | ||
}; | ||
``` | ||
--- | ||
## The full script so far | ||
If you're using stages, here's what your script should look like so far: | ||
```js | ||
import http from 'k6/http'; | ||
import { check, sleep } from 'k6'; | ||
export let options = { | ||
stages: [ | ||
{ duration: '30m', target: 100 }, | ||
{ duration: '1h', target: 100 }, | ||
{ duration: '5m', target: 0 }, | ||
], | ||
}; | ||
export default function() { | ||
let url = 'https://httpbin.test.k6.io/post'; | ||
let response = http.post(url, 'Hello world!'); | ||
check(response, { | ||
'Application says hello': (r) => r.body.includes('Hello world!') | ||
}); | ||
sleep(Math.random() * 5); | ||
} | ||
``` | ||
--- | ||
## Let's set some thresholds | ||
- Move to [10-setting-test-criteria-with-thresholds](?p=10-setting-test-criteria-with-thresholds) |
Oops, something went wrong.