2

I would like to use K6 in order to measure the time it takes to proces 1.000.000 requests (in total) by an API.

Scenario

Execute 1.000.000 (1 million in total) get requests by 50 concurrent users/theads, so every user/thread executes 20.000 requests.

I've managed to create such a scenario with Artillery.io, but I'm not sure how to create the same one while using K6. Could you point me in the right direction in order to create the scenario? (Most examples are using a pre-defined duration, but in this case I don't know the duration -> this is exactly what I want to measure).

Artillery yml

config:
  target: 'https://localhost:44000'
  phases:
    - duration: 1
      arrivalRate: 50
scenarios:
  - flow:
      - loop:
          - get:
              url: "/api/Test"
        count: 20000

K6 js

import http from 'k6/http';
import {check, sleep} from 'k6';
export let options = {
  iterations: 1000000,
  vus: 50
};

export default function() {
  let res = http.get('https://localhost:44000/api/Test');
    check(res, { 'success': (r) => r.status === 200 });
}
Odrai
  • 2,163
  • 2
  • 31
  • 62

1 Answers1

1

The iterations + vus you've specified in your k6 script options would result in a shared-iterations executor, where VUs will "steal" iterations from the common pile of 1m iterations. So, the faster VUs will complete slightly more than 20k requests, while the slower ones will complete slightly less, but overall you'd still get 1 million requests. And if you want to see how quickly you can complete 1m requests, that's arguably the better way to go about it...

However, if having exactly 20k requests per VU is a strict requirement, you can easily do that with the aptly named per-vu-iterations executor:

export let options = {
    discardResponseBodies: true,
    scenarios: {
        'million_hits': {
            executor: 'per-vu-iterations',
            vus: 50,
            iterations: 20000,
            maxDuration: '2h',
        },
    },
};

In any case, I strongly suggest setting maxDuration to a high value, since the default value is only 10 minutes for either executor. And discardResponseBodies will probably help with the performance, if you don't care about the response body contents.

btw you can also do in k6 what you've done in Artillery, have 50 VUs start a single iteration each and then just loop the http.get() call 20000 times inside of that one single iteration... You won't get a very nice UX that way, the k6 progressbars will be frozen until the very end, since k6 will have no idea of your actual progress inside of each iteration, but it will also work.

na--
  • 1,016
  • 7
  • 9