Search code examples
jettyhttp2

Jetty's HTTP/2 client slow?


Doing simple GET requests over a high speed internet connection (within an AWS EC2 instance), the throughput seems to be really low. I've tried this with multiple servers.

Here's the code that I'm using:

HTTP2Client http2Client = new HTTP2Client();
http2Client.start();
SslContextFactory ssl = new SslContextFactory(true);

HttpClient client = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), ssl);
client.start();
long start = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
      System.out.println("i" + i);
      ContentResponse response = client.GET("https://http2.golang.org/");
      System.out.println(response.getStatus());
}
System.out.println(System.currentTimeMillis() - start);

The throughput I get is about 8 requests per second.

This seems to be pretty low (as compared to curl on the command line).

Is there anything that I'm missing? Any way to turbo-charge this?

EDIT: How do I get Jetty to use multiple streams?


Solution

  • That is not the right way to measure throughput.

    Depending where you are geographically, you will be dominated by the latency between your client and the server. If the latency is 125 ms, you can only make 8 requests/s. For example, from my location, the ping to http2.golang.org is 136 ms.

    Even if your latency is less, there are good chances that the server is throttling you: I don't think that http2.golang.org will be happy to see you making 10k requests in a tight loop.

    I'll be curious to know what is the curl or nghttp latency in the same test, but I guess won't be much different (or probably worse if they close the connection after each request).

    This test in the Jetty test suite, which is not a proper benchmark either, shows around 500 requests/s on my laptop; without TLS, goes to around 2500 requests/s.

    I don't know exactly what you're trying to do, but your test does not tell you anything about the performance of Jetty's HttpClient.