Search code examples
apachehttpsslhttpspage-load-time

Why https is faster than http in my apache server?


Server information:

$ httpd -v 
Server version: Apache/2.2.24 (Unix)
Server built:   May  8 2013 15:17:37

I create a self-signed SSL Certificate with openssl.

Test Code(Java with selenium webdriver):

      long startTime, useTime = 0, t;
      int count = 10;
      for (int i = 0; i < count; i++) {
         ChromeDriver driver = new ChromeDriver(capabilities);
         startTime = System.nanoTime();
         driver.get("https://*.*.*.*/pic.html");
         //When testing Http,it will be:driver.get("http://*.*.*.*/pic.html");
         //pic.html is a simple page with many images.
         t = System.nanoTime() - startTime;
         useTime += t;
         driver.quit();
      }
      System.out.println("Average Time: " + useTime/1000000.0/count +" ms");

Result:

HTTPs:Average Time: 1718.13659 ms
HTTP:Average Time: 2484.122677 ms

Thanks in advance.


Solution

  • It might be that using https also enables transparent compression of the content. The time added for compression and encryption (and back of course) might be less than the time saved by transferring less content over a slow link.

    You can verify this by:

    • Using incompressible content (e.g. a large JPEG image)
    • Speeding up the transfer link significantly (e.g. by using "localhost")