2

I am trying to disable Java's HTTP keep-alive for performance testing. I am assuming that if I disable the keep-alives, Java should do less handshakes. However, after adding -Dhttp.keepalive=false to the JVM args (which should disable the keep-alive), I see no difference when tracing the packets in wireshark.

I made a small java code to test it:

public static void main(String[] args) throws Exception {
        String httpsURL = "https://www.google.com";
        URL myUrl = new URL(httpsURL);

        for(int i = 0; i < 3; i++) {
            System.out.println("Sending packet");
            HttpsURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
            InputStream is = conn.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            Thread.sleep(10000);
        }

    }

I was testing it on the JDK I got from here: https://adoptopenjdk.net/releases.html?variant=openjdk11&jvmVariant=openj9#x64_mac

So I tried running with the following 2 commands:

  • openj9-11/Contents/Home/bin/java HelloWorld
  • openj9-11/Contents/Home/bin/java -Dhttp.keepAlive=false HelloWorld

The results from Wireshark (when filtering by ip == 172.217.10.100; i.e.: Google's IP) for both runs are identical. - Wireshark (tracing first command) screenshot: https://i.stack.imgur.com/2at6l.jpg - Wireshark (tracing second command) screenshot: https://i.stack.imgur.com/zT24V.jpg

I was expecting to get less handshakes when tracing the second command. Am I doing something wrong or are the results expected?

Samer
  • 21
  • 4
  • It looks like you are using the [Java 8 parameter](https://docs.oracle.com/javase/8/docs/technotes/guides/net/http-keepalive.html) instead of the [Java 11](https://stackoverflow.com/questions/53617574/how-to-keep-connection-alive-in-java-11-http-client). Also you seem to have the wrong assumption about HTTP persistent connections. Please read through the Java 8 link. – Sascha May 21 '19 at 13:16

0 Answers0