Connection Reuse

Hi,
I’m just starting with k6 as I’m trying to load test an app server that supports http/2 and gzipped request bodies (i’m using master since the gzip feature is not in 0.24). I see in the response via the --debug-http option that the server is responding with HTTP/2.0, but I don’t see subsequent requests for the VU being HTTP/2.0. Based on the performance it seems to be equivalent when I was using jmeter with just HTTP/1.1 with KeepAlive enabled and without gzip compression. The traffic is not saturating the network at the moment.

How can I ensure the http transport keeps the connection alive?

How can I ensure that the HTTP/2.0 response will upgrade the connection to HTTP/2.0 for subsequent requests?

Thanks,
Greg

The trouble here probably lies with the --debug-http flag. We recently found out that it’s somewhat buggy and doesn’t accurately report the actual HTTP requests that are being made, especially the HTTP version and the compression. The reason for this bug is that we’re dumping the HTTP requests without knowledge of the underlying transport, so without knowledge of whether HTTP 1.1 or 2 will be used. You can find more information in these GitHub issues: --http-debug incorrectly reports http protocol · Issue #986 · grafana/k6 · GitHub and --http-debug shows incorrect "Accept-Encoding" · Issue #1042 · grafana/k6 · GitHub .

How can I ensure the http transport keeps the connection alive?

This is the default k6 behavior, it can be disabled globally with the noConnectionReuse option and between iterations of a VU with the noVUConnectionReuse option.

How can I ensure that the HTTP/2.0 response will upgrade the connection to HTTP/2.0 for subsequent requests?

k6 tries to upgrade the connection to HTTP/2 whenever possible, but you currently can’t ensure this beforehand. There’s a recent proposal for custom transports that would probably allow forcing (i.e. error when it doesn’t happen) the connection like that, but for now k6 would use HTTP2 if the remote server supports it. And while --http-debug is currently somewhat buggy when dumping the requests, you can check if a request used HTTP2 after the fact. Here’s how that can be done:

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

export default function() {
  check(http.get("https://www.bbc.co.uk/"), {
    "status is 200": (r) => r.status == 200,
    "protocol is HTTP/2": (r) => r.proto == "HTTP/2.0",
  });
}

More info: Response

1 Like

Thanks for the info. I verified with HAProxy in debug mode that subsequent requests were over HTTP/2.0.