k6

Displaying requests per second in Grafana

I’ve started with the default sample Grafana dashboard offered by k6. It’s great! In my tests I’m sending traffic to two different hosts and I want to show the requests per second going to each and the total. In my test I’m tagging the request with the hostname so I can query on it.

In Grafana I setup two queries: one to show the total RPS throughput and one to show by host. The results are confusing. The RPS numbers are much higher than anything else reported (such as checks per second) and the total is less than the RPS of each host. I must be doing something wrong.

49

Update: I may have solved my own problem by changing from count to sum. At least in normal SQL that wouldn’t have made a difference since the value is always 1, but maybe it’s doing a count(distinct value) internally?

I wasn’t allowed to put two images in my post, so here’s the result:

rps_k6

I can’t reproduce your problem … for me the total is the sum of the two. With sum or count. I tried with random sleeps, one of the request taking random amount of time and so on and so forth, but nothing :(.
Can you provide us with some code sample?

I would also argue that this is a influxdb question. So maybe for better explanation/understanding you should try the influxdb community as they will probably have much better idea what could be going wrong …

What sort of code sample? My javascript file for the benching? I’ve added it below.

I was also thinking this may be more of an influx question. Things like grouping by time intervals are foreign to me as that’s not a thing in standard SQL databases, so I may need to understand the internals of how that works. I’ve seen a bunch of erratic results like the exact same query in two different views (like a Single State + Sparline right next to a line graph) having wildly different numbers. There seems to be a lot of jitter in the data, so maybe the 1 second time granularity is too much? I’ll have to play around with it more.

import { check, fail } from "k6";
import http from "k6/http";

export let options = {
  stages: [
    { duration: "1m", target: 10 },

    { duration: "2m",  target: 20 },

    { duration: "2m",  target: 50 },

    { duration: "1m", target:  10 },

    { duration: "1m", target:  0 }
  ],
  thresholds: {
    http_req_duration: ["avg<500", "p(95)<100"]
  },
}

function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

const hosts = [
  "rest.api.env1.com",
  "rest.api.env2.com"
]

export default function(data) {
  let host = __ENV.HOST || hosts[getRandomInt(0, hosts.length - 1)]

  // each request will be for a new user, being rather brutal on caching
  uid = getRandomInt(1, 1000);

  let res = http.get(`http://${host}/rest/users/${uid}/properties`, {
    tags: {name: 'UserFeatures', host: host}
  })

  check(res, {
    "is status 200": (r) => r.status === 200,
    "transaction time OK": (r) => r.timings.duration < 100
  })
}

Still, no idea:


The one on the left is with count, the on the right is with sum.
I guess you somehow get http_reqs records with values bigger than 1 in which case I expect there will be a difference between counting them and summing them. But looking at the code, there is no way for this to happen ;(. We always set http_reqs to 1 as we emit metrics per each request.

I tested with older versions and looked at the code history - nothing to indicate we have ever send anything but 1 as a value for http_reqs… I dunnot if you are having some aggregation before that this could happen but otherwise I am out of ideas. Better try the influxdb community forum :slight_smile: .

Hi,

I still see some differences depending on 302 redirect requests.
As it’s http requests per sec, request with redirect counts double (or more) depending how many of redirect you have in your request.

@Claudio this is intentional, after all, when you have redirects, the client actually performs multiple HTTP requests, so we measure them. You could probably filter these out, if you’re not interested in them, by ignoring metrics that have the status=302 metric tag attached to them

Thanks, that’s work perfectly.
I change the grafana dashboard query to influxdb like this:
SELECT sum(“value”) / 10 FROM “http_reqs” WHERE (“status” != ‘302’) AND $timeFilter GROUP BY time(10s), “group” fill(null)