Hi I am having the following scenario
I have to two end points. i want to send 100 requests to the first end point for a duration of 60 seconds. After 30 seconds I want to hit the second endpoint with 150 requests for 30 seconds.
any idea how to achieve this using k6 thank you
Use a ramping arrival rate executor to have the second scenario start after 30 seconds:
export const options = {
scenarios: {
first: {
exec: 'first_endpoint',
executor: 'constant-arrival-rate',
duration: '1m',
preAllocatedVUs: 10,
rate: 100, // 100 requests per second
},
second: {
exec: 'second_endpoint',
executor: 'ramping-arrival-rate',
duration: '1m',
preAllocatedVUs: 10,
stages: [
{ target: 0, duration: '29s' }, // start with 0 requests
{ target: 150, duration: '1s' }, // jump to 150 rps
{ target: 150, duration: '30s' }, // run with 150 rps for another 30 seconds
{ target: 0, duration: '1s' }, // stop requests
]
}
}
};
export function first_endpoint() {
// function will be called for the initial 60 seconds
http.get('http://example.com/1');
}
export function second_endpoint() {
// function will be called after 30 seconds for 30 seconds
http.get('http://example.com/2');
}
Alternatively, you could switch the endpoint based on the current ramping stage, but this will only work if both endpoints should be hit mutually exclusively and not at the same time. To do that, use the getCurrentStageIndex
function of https://jslib.k6.io/k6-utils/1.3.0/index.js (there is a code sample on the linked executor page).