Amazon CloudFront で TLS 1.2 と TLS 1.3 の速度の違いを簡易的に測定してみたら、ちょっとだけ速かった

2024.03.02

いわさです。

TLS1.2 と TLS 1.3 の違いやメリットについて語られる時、よく「より高速で安全だ」と説明されていることが多いです。
「なるほど、高速なのか。であれば TLS 1.3 のほうがいいのか」なんて思うわけですが、ちょっとだけ速いのか、とんでもなく速いのか実は私はよくわかっていません。

そこで本日は、非常に簡易的な方法で TLS 1.2 と TLS 1.3 でのパフォーマンスを測定をしてみましたので行ったことや結果などを紹介したいと思います。

Amazon CloudFront に Apache Bench で大量リクエストを送信することにした

E2E の速度を比較したいなと思いつつ、評価のたびにオリジンの処理速度が影響するのも違うよなぁと思い、今回は CloudFront で TLS 1.2 と TLS 1.3 が使用可能なセキュリティポリシーを構成し、エッジキャッシュを有効化した状態でオリジンレスポンスが影響しないような構成を評価環境としてみました。
CloudFront は HTTP/3 もサポートしているのですが、こちらは今回は有効化しません。

TLS サポート状況はこんな感じです。
暗号スイートによる比較をしても良いなと思ったのですが、今回は特に指定せずに行ってみます。

% sslscan https://hoge0302.tak1wa.com/
Version: 2.1.3
OpenSSL 3.2.1 30 Jan 2024

Connected to 18.65.141.187

Testing SSL server hoge0302.tak1wa.com on port 443 using SNI name hoge0302.tak1wa.com

  SSL/TLS Protocols:
SSLv2     disabled
SSLv3     disabled
TLSv1.0   disabled
TLSv1.1   disabled
TLSv1.2   enabled
TLSv1.3   enabled

検証結果

10 回リクエスト送信での比較

そして、リクエスト送信は Apache Bench で行ってみたいと思います。
abコマンドのオプションで TLS バージョンを指定することが出来ます。
使い方はこんな感じです。

以下は TLS 1.3 を指定する場合です。

[cloudshell-user@ip-10-134-14-164 ~]$ ab -n 10 -c 1 -f TLS1.3 https://hoge0302.tak1wa.com/
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking hoge0302.tak1wa.com (be patient).....done


Server Software:        AmazonS3
Server Hostname:        hoge0302.tak1wa.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.3,TLS_AES_128_GCM_SHA256,2048,128
Server Temp Key:        X25519 253 bits
TLS Server Name:        hoge0302.tak1wa.com

Document Path:          /
Document Length:        10 bytes

Concurrency Level:      1
Time taken for tests:   0.110 seconds
Complete requests:      10
Failed requests:        0
Total transferred:      4420 bytes
HTML transferred:       100 bytes
Requests per second:    91.01 [#/sec] (mean)
Time per request:       10.988 [ms] (mean)
Time per request:       10.988 [ms] (mean, across all concurrent requests)
Transfer rate:          39.28 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        7    9   2.5      9      15
Processing:     1    2   0.6      2       3
Waiting:        1    2   0.6      2       3
Total:          8   11   2.5     11      17

Percentage of the requests served within a certain time (ms)
  50%     11
  66%     11
  75%     11
  80%     14
  90%     17
  95%     17
  98%     17
  99%     17
 100%     17 (longest request)

平均 10.988 ms か。
TLS 1.2 でも試してみましょう。

[cloudshell-user@ip-10-134-14-164 ~]$ ab -n 10 -c 1 -f TLS1.2 https://hoge0302.tak1wa.com/
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking hoge0302.tak1wa.com (be patient).....done


Server Software:        AmazonS3
Server Hostname:        hoge0302.tak1wa.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Server Temp Key:        X25519 253 bits
TLS Server Name:        hoge0302.tak1wa.com

Document Path:          /
Document Length:        10 bytes

Concurrency Level:      1
Time taken for tests:   0.119 seconds
Complete requests:      10
Failed requests:        0
Total transferred:      4420 bytes
HTML transferred:       100 bytes
Requests per second:    84.14 [#/sec] (mean)
Time per request:       11.885 [ms] (mean)
Time per request:       11.885 [ms] (mean, across all concurrent requests)
Transfer rate:          36.32 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        6   10   2.7     11      14
Processing:     1    2   0.5      1       3
Waiting:        1    1   0.4      1       2
Total:          7   12   3.0     12      16
ERROR: The median and mean for the processing time are more than twice the standard
       deviation apart. These results are NOT reliable.

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     13
  75%     14
  80%     16
  90%     16
  95%     16
  98%     16
  99%     16
 100%     16 (longest request)

TLS 1.3 が平均 10.988 ms であったのに対して、TLS 1.2 は平均 11.885 ms でした。ちょっと速い気がしますが、この時点だとまだよくわからないな。

100 回リクエスト送信での比較

もう少しリクエスト数を増やしてみます。100 回でいきましょう。
先ほどの結果を見て頂くと、「Percentage of the requests served within a certain time」という出力欄があり、リクエストのうちの何 % がどの程度の時間だったのか分布みたいなものがわかります。
そして、abコマンドのオプションでこの結果をより詳細(0 % から 100 % まで)に CSV 形式でファイル出力することが出来ます。この出力ファイルをグラフなどで比較してやると、よりわかりやすい分析が出来るかもしれなんなと思い、やってみることに。

まずは計測を行います。TLS 1.2 から。

[cloudshell-user@ip-10-134-14-164 ~]$ ab -n 100 -c 1 -e tlsv12-0.csv -f TLS1.2 https://hoge0302.tak1wa.com/
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking hoge0302.tak1wa.com (be patient).....done


Server Software:        AmazonS3
Server Hostname:        hoge0302.tak1wa.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Server Temp Key:        X25519 253 bits
TLS Server Name:        hoge0302.tak1wa.com

Document Path:          /
Document Length:        10 bytes

Concurrency Level:      1
Time taken for tests:   0.713 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      44300 bytes
HTML transferred:       1000 bytes
Requests per second:    140.17 [#/sec] (mean)
Time per request:       7.134 [ms] (mean)
Time per request:       7.134 [ms] (mean, across all concurrent requests)
Transfer rate:          60.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4    6   1.4      5      12
Processing:     1    1   0.5      1       3
Waiting:        1    1   0.6      1       3
Total:          5    7   1.6      6      16

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      7
  75%      7
  80%      8
  90%      9
  95%     10
  98%     11
  99%     16
 100%     16 (longest request)

ちなみに TLS 1.2 の暗号スイートはECDHE-RSA-AES128-GCM-SHA256が使われていますね。
このあたりでもちょっと違ったかもなと後から気が付きましたが、まぁ今回はこのままいくことに。

続いて TLS 1.3 です。

[cloudshell-user@ip-10-134-14-164 ~]$ ab -n 100 -c 1 -e tlsv13-0.csv -f TLS1.3 https://hoge0302.tak1wa.com/
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking hoge0302.tak1wa.com (be patient).....done


Server Software:        AmazonS3
Server Hostname:        hoge0302.tak1wa.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.3,TLS_AES_128_GCM_SHA256,2048,128
Server Temp Key:        X25519 253 bits
TLS Server Name:        hoge0302.tak1wa.com

Document Path:          /
Document Length:        10 bytes

Concurrency Level:      1
Time taken for tests:   0.660 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      44300 bytes
HTML transferred:       1000 bytes
Requests per second:    151.60 [#/sec] (mean)
Time per request:       6.596 [ms] (mean)
Time per request:       6.596 [ms] (mean, across all concurrent requests)
Transfer rate:          65.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4    5   1.5      4      17
Processing:     1    2   1.0      1       7
Waiting:        1    2   1.0      1       7
Total:          5    6   1.8      6      18
WARNING: The median and mean for the processing time are not within a normal deviation
        These results are probably not that reliable.
WARNING: The median and mean for the waiting time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      6
  75%      7
  80%      7
  90%      9
  95%     10
  98%     13
  99%     18
 100%     18 (longest request)

コマンドの実行結果から、TLS 1.2 が平均 7.134 ms、TLS 1.3 が平均 6.596 ms であることがわかります。
こちらもちょっとだけ TLS 1.3 のほうが速そうです。1 ms 以下の世界か。

CloudShell から実行していたので、この出力ファイルを適当な S3 バケットにアップロードしておきます。

[cloudshell-user@ip-10-134-14-164 ~]$ aws s3 cp ./tlsv13-0.csv s3://hoge0302tls/
upload: ./tlsv13-0.csv to s3://hoge0302tls/tlsv13-0.csv                
[cloudshell-user@ip-10-134-14-164 ~]$ aws s3 cp ./tlsv12-0.csv s3://hoge0302tls/
upload: ./tlsv12-0.csv to s3://hoge0302tls/tlsv12-0.csv

QuicSight のデータセットへこの 2 つのファイルをアップロードして結合したデータセットを作成します。

このデータセットをビジュアルで表示したところ次のようになりました。
回数があまり多くないのでちょっとまばらなのですが、TLS 1.3 のほうが少しだけ速そうだなということがわかります。

100,000 回リクエスト送信での比較

もっと母数が増えると安定したグラフになるのではないかと思い、10 万回づつリクエストを送信してみることにしました。
同じようにデータセットに取り込んで QuickSight で可視化してみると次のようになりました。一部レスポンスに時間がかかっている部分がありました。

測定時間も数分かかったので、おそらく途中でキャッシュの更新がされておりオリジンリクエストが発生していそうな気がします。

うまいことやるべきな気がしますが、今回は QuickSight のビジュアルの Y 軸のオプションでレンジを指定してやることにしました。
調整した結果がこちらです。

微妙に TLS 1.3 のほうが速いですね。本当に微妙です。
1 ms 以下の世界か。

さいごに

本日は Amazon CloudFront で TLS 1.2 と TLS 1.3 の速度の違いを簡易的に測定してみました。

今回は単純に同じクライアントからリクエストを送信し、レスポンスまでの時間を計測してみました。
数 ms の差が出るとかなのかなと思ったのですが、今回の測定結果からだと思ったよりも差が出ませんでした。TLS 1.3 のほうが速いには速いのですが。
ただ、今回はあまり条件を指定せずにほぼツールのデフォルトでリクエストを送信しただけなので、もう少し条件を見直して測定し直してみると色々と見えてきそうな気もします。