Search code examples
k6

Implementing Throughput controller in K6


Different API's should work with different throughput. In Jmeter we have the option to implement it by using the throughput controller. What is the method to implement the same in K6.


Solution

  • You can use scenarios to call different test functions with different characteristics. Executors define how often a function will be executed (e.g. with a constant rate, a constant number of users, variable rate, variable users, a fixed number of calls, …). You can mix different executor types in a single test.

    For example, a test setup which calls 2 endpoints with different rates could look like the following:

    export const options = {
      scenarios: {
        fast: {
          exec: 'fast_function',
          executor: 'constant-arrival-rate',
          duration: '10m',
          preAllocatedVUs: 10,
          rate: 10 // 10 rps
        },
        slow: {
          exec: 'slow_function',
          executor: 'constant-arrival-rate',
          duration: '10m',
          preAllocatedVUs: 1,
          rate: 1 // 1 rps
        }
      }
    };
    
    export function fast_function() {
      // will be called 10 times per second
      http.get('http://example.com');
    }
    
    export function slow_function() {
      // will be called once per second
      http.get('http://example.com');
    }