Android サーバーが HTTP よりも HTTPS で非常に遅い理由を理解できません。以下のカールからわかるように、握手は比較的迅速に行われるため、握手によるものではないと思います
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 秒もかからないのに 1 秒もかからないとは信じられません。特に、HTTPS は HTTP に比べてそれほど遅くはないとどこでも言われている場合はなおさらです。