与HTTP相比,HTTPS非常慢(不是握手)

时间:2013-10-03 15:12:22

标签: java android sockets https

我无法理解为什么我的Android服务器在HTTPS中比在HTTP中慢得多。正如您从下面的卷曲中看到的那样,我认为这不是由于握手而发生的相对较快

thomas-mba:thomas$ curl -v --trace-time --insecure https://192.168.1.19:8101/tasks
16:59:10.719547 * About to connect() to 192.168.1.19 port 8101 (#0)
16:59:10.720632 *   Trying 192.168.1.19...
16:59:10.750861 * connected
16:59:10.750952 * Connected to 192.168.1.19 (192.168.1.19) port 8101 (#0)
16:59:10.751810 * SSLv3, TLS handshake, Client hello (1):
16:59:11.666648 * SSLv3, TLS handshake, Server hello (2):
16:59:11.666737 * SSLv3, TLS handshake, CERT (11):
16:59:11.714497 * SSLv3, TLS handshake, Server finished (14):
16:59:11.714822 * SSLv3, TLS handshake, Client key exchange (16):
16:59:11.714887 * SSLv3, TLS change cipher, Client hello (1):
16:59:11.715034 * SSLv3, TLS handshake, Finished (20):
16:59:11.725787 * SSLv3, TLS change cipher, Client hello (1):
16:59:11.725959 * SSLv3, TLS handshake, Finished (20):
16:59:11.726056 * SSL connection using AES128-SHA
16:59:11.726114 * Server certificate:
16:59:11.726184 *    subject: CN=192.168.1.19
16:59:11.726247 *    start date: 2013-10-03 14:58:20 GMT
16:59:11.726302 *    expire date: 2014-10-03 14:59:10 GMT
16:59:11.726362 *    common name: 192.168.1.19 (matched)
16:59:11.726423 *    issuer: CN=My CA name
16:59:11.726472 *    SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
16:59:11.726609 > GET /tasks HTTP/1.1
16:59:11.726609 > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
16:59:11.726609 > Host: 192.168.1.19:8101
16:59:11.726609 > Accept: */*
16:59:11.726609 > 
16:59:22.310511 < HTTP/1.1 200 OK
16:59:22.310610 < Date: Thu, 03 Oct 2013 14:59:21 GMT+00:00
16:59:22.310645 < Server: My HTTP Server
16:59:22.310680 < Content-Length: 4248
16:59:22.310714 < Content-Type: text/html
16:59:22.310749 < 

最长的是绑定套接字:

// Set up HTTP connection
Socket socket = this.mServerSocket.accept();
socket.setKeepAlive(true);

DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
Log.d(TAG,String.format("%s || Incoming connection from %s",
    new Date().toString(),
    socket.getInetAddress()));
conn.bind(socket, mParams);
Log.d(TAG,String.format("%s || Bind finished",
    new Date().toString()));
// Start worker thread
Thread t = new WorkerThread(this.mHttpService, conn, socket);
t.setDaemon(true);
t.start();
Log.d(TAG,String.format("%s || Worker thread started",
    new Date().toString()));

以上输出:

Thu Oct 03 17:10:05 CEST 2013 || Incoming connection from /192.168.1.29
GC_FOR_ALLOC freed 334K, 7% free 8987K/9568K, paused 55ms, total 58ms
Thu Oct 03 17:10:29 CEST 2013 || Bind finished
Thu Oct 03 17:10:29 CEST 2013 || Worker thread started

您认为原因是什么?

修改

HTTP中也是如此:

Thu Oct 03 17:23:25 CEST 2013 || Incoming connection from /192.168.1.29
Thu Oct 03 17:23:25 CEST 2013 || Bind finished
Thu Oct 03 17:23:25 CEST 2013 || Worker thread started

我无法相信加密4KB html页面需要花费25秒而不到一秒钟,特别是当它说到任何地方HTTPS都不再那么慢了。

  1. How much overhead does SSL impose?
  2. https://www.imperialviolet.org/2010/06/25/overclocking-ssl.html

0 个答案:

没有答案