My major goal - send (for example) 5 requests at the same moment. I found that I can not only set option vus: 5 and receive 5 simultaneous requests.
Is there a way to do so without tricks like using short duration and without limitations of RPS for VUs?
I just tried to set only option and it does not works properly. (example below)
export const options = {
vus: 5,
};
Also I found that I able to run test for example for 30sec with VUs 5 and that works as the smallest ddos in web history (example below), but I would like to understand if there is a way to send just 5 requests at the same moment and nothing more.
export const options = {
vus: 5,
duration: '30s',
};
The closest funcitonalities in the most popular competitor load testing tools are called:
Quick lookup for both in context of k6 gives this article: Rendezvous with k6 which seems to be exactly what you're looking for.
Implementation example from the above article:
import http from 'k6/http';
import exec from 'k6/execution';
import { sleep } from 'k6';
export const options = {
stages: [
{ duration: '40s', target: 20 },
{ duration: '2m', target: 20 },
{ duration: '5s', target: 0 },
],
};
export default function () {
const rendezPeriod = 30000;
/*Step1*/http.get('https://test-api.k6.io/public/crocodiles/1/');
sleep(Math.random() * 5);
/*Step2*/http.get('https://test-api.k6.io/public/crocodiles/2/');
sleep(Math.random() * 5);
/*Step3*/http.get('https://test-api.k6.io/public/crocodiles/3/');
sleep(Math.random() * 5);
/*Step4*/http.get('https://test-api.k6.io/public/crocodiles/4/');
rendez(rendezPeriod);
/*Step5*/http.get('https://test-api.k6.io/public/crocodiles/');
sleep(Math.random() * 5);
/*Step6*/http.get('https://test-api.k6.io/public/crocodiles/5/');
sleep(Math.random() * 5);
/*Step7*/http.get('https://test-api.k6.io/public/crocodiles/6/');
sleep(Math.random() * 5);
/*Step8*/http.get('https://test-api.k6.io/public/crocodiles/1/');
sleep(Math.random() * 5);
}
// comment: quick implementation of rendezvous function in k6
// stopping at periods, no user count ... yet
function rendez(rendezPeriod) {
//comment: soFar is the time since the test started
let soFar = new Date().getTime() - exec.scenario.startTime;
//comment: calculate how much to wait until next rendez
const waitTime = (rendezPeriod-(soFar%rendezPeriod))/1000;
sleep(waitTime);
}