Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8193504

HttpClient very slow if downloading a 160M file with TLS

XMLWordPrintable

    • Verified

      For both HTTP/1.1 and HTTP/2, HttpClient very slow if downloading a 160M file with TLS, it spends only 2 seconds for 8M, but much more time than 2 * (160 / 8) seconds to download the 160M file. And if we use legacy HttpsURLConnection, it spends about 20 seconds.

      The following tes will fail with timeout:
      import static jdk.incubator.http.HttpClient.Version.HTTP_2;
      import static jdk.incubator.http.HttpClient.Version.HTTP_1_1;

      import java.io.InputStream;
      import java.net.URI;
      import java.net.URL;
      import java.security.GeneralSecurityException;
      import java.security.cert.X509Certificate;

      import javax.net.ssl.HttpsURLConnection;
      import javax.net.ssl.SSLContext;
      import javax.net.ssl.TrustManager;
      import javax.net.ssl.X509TrustManager;

      import org.testng.annotations.Test;

      import jdk.incubator.http.HttpClient;
      import jdk.incubator.http.HttpClient.Version;
      import jdk.incubator.http.HttpRequest;
      import jdk.incubator.http.HttpResponse;

      /*
       * @test
       * @compile HttpTestUtils.java
       * @modules jdk.incubator.httpclient
       * @run testng/othervm Test1
       */
      public class Test1 {//-Djdk.internal.httpclient.debug=true
          @Test
          public void testLegacy() throws Exception {
              TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
                  public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                      return new X509Certificate[0];
                  }

                  public void checkClientTrusted(java.security.cert.X509Certificate[] certs,
                          String authType) {
                  }

                  public void checkServerTrusted(java.security.cert.X509Certificate[] certs,
                          String authType) {
                  }
              } };

              try {
                  SSLContext sc = SSLContext.getInstance("SSL");
                  sc.init(null, trustAllCerts, new java.security.SecureRandom());
                  HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
              } catch (GeneralSecurityException e) {
              }

              InputStream in = new URL("https://<host>/yc/data/d1.data").openStream();
              System.out.println(in.readAllBytes().length);
              in.close();
          }
          
          @Test
          public void test1() throws Exception {
              test(HTTP_1_1);
          }
          
          @Test
          public void test2() throws Exception {
              System.setProperty("jdk.httpclient.connectionWindowSize", String.valueOf(1024*1024*32));
              System.setProperty("jdk.httpclient.windowsize", String.valueOf(1024*1024*16));
              test(HTTP_2);
          }

          private static HttpClient getClient(Version v) {
              return HttpTestUtils.clientBuilder().version(v).build();
          }

          private void test(Version v) throws Exception {
              HttpClient client = getClient(v);

              client.sendAsync(HttpRequest
                      .newBuilder(new URI("https://<host>/yc/data/d1.data")).GET().build(),
                          HttpResponse.BodyHandler.asByteArray())
                      .get();
          }
      }

            dfuchs Daniel Fuchs
            fyuan Frank Yuan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: