background
開発

ApacheとnginxとLiteSpeedで性能測定してみた!①

2021/07/26公開
ApacheとnginxとLiteSpeedで性能測定してみた!

WEBサイトに欠かせないWEBサーバですが、そのミドルウェア選定の1つのポイントとして性能があります。
今回は、シェアの多いWEBサーバであるApacheとnginx、ここ数年で大きくシェアを伸ばしているLiteSpeed(OpenLiteSpeed)について、それぞれの性能を測定してみました。

計測環境にはAmazonLinux2を使用しました。
ApacheとnginxとLiteSpeedのバージョンは以下です。

      [root@ip-XXX-XXX-XXX-XXX ~]# apachectl -version
      Server version: Apache/2.4.41 ()
      Server built:   Oct 22 2019 22:59:04
      [root@ip-XXX-XXX-XXX-XXX ~]# 
      [root@ip-XXX-XXX-XXX-XXX ~]# nginx -v
      nginx version: nginx/1.18.0
      [root@ip-XXX-XXX-XXX-XXX ~]# 
      [root@ip-XXX-XXX-XXX-XXX html]# cat /usr/local/lsws/VERSION
      1.7.8
      [root@ip-XXX-XXX-XXX-XXX html]# 

計測にはお手軽にApacheBenchを使用しました。
ではさっそく計測していきます。計測に使用するのは以下の小さいサイズの画像ファイル(約8K)です。

      [root@ip-XXX-XXX-XXX-XXX html]# ll test.png
      -rw-rw-r-- 1 root root 8106 Feb  2 10:03 test.png
      [root@ip-XXX-XXX-XXX-XXX html]# 

まずはApachから。同時接続100人で10000リクエストを処理する性能を測定します。
※ Apacheのポートは8080へ変更しています。

      [root@ip-XXX-XXX-XXX-XXX html]# ab -n 10000 -c 100 http://localhost:8080/test.png
      This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
      Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
      Licensed to The Apache Software Foundation, http://www.apache.org/
      
      Benchmarking localhost (be patient)
      Completed 1000 requests
      Completed 2000 requests
      Completed 3000 requests
      Completed 4000 requests
      Completed 5000 requests
      Completed 6000 requests
      Completed 7000 requests
      Completed 8000 requests
      Completed 9000 requests
      Completed 10000 requests
      Finished 10000 requests
      
      
      Server Software:        Apache/2.4.41
      Server Hostname:        localhost
      Server Port:            8080
      
      Document Path:          /test.png
      Document Length:        8106 bytes
      
      Concurrency Level:      100
      Time taken for tests:   0.946 seconds
      Complete requests:      10000
      Failed requests:        0
      Total transferred:      83760000 bytes
      HTML transferred:       81060000 bytes
      Requests per second:    10571.27 [#/sec] (mean)
      Time per request:       9.460 [ms] (mean)
      Time per request:       0.095 [ms] (mean, across all concurrent requests)
      Transfer rate:          86469.70 [Kbytes/sec] received
      
      Connection Times (ms)
      min  mean[+/-sd] median   max
      Connect:        0    0   0.4      0       7
      Processing:     2    9   2.8      8      40
      Waiting:        0    9   2.8      8      39
      Total:          4    9   2.8      9      40
      
      Percentage of the requests served within a certain time (ms)
      50%      9
      66%      9
      75%      9
      80%     10
      90%     11
      95%     15
      98%     19
      99%     22
      100%     40 (longest request)
      [root@ip-XXX-XXX-XXX-XXX html]# 

次にnginxです。

      [root@ip-XXX-XXX-XXX-XXX html]# ab -n 10000 -c 100 http://localhost:80/test.png
      This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
      Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
      Licensed to The Apache Software Foundation, http://www.apache.org/
      
      Benchmarking localhost (be patient)
      Completed 1000 requests
      Completed 2000 requests
      Completed 3000 requests
      Completed 4000 requests
      Completed 5000 requests
      Completed 6000 requests
      Completed 7000 requests
      Completed 8000 requests
      Completed 9000 requests
      Completed 10000 requests
      Finished 10000 requests
      
      
      Server Software:        nginx/1.18.0
      Server Hostname:        localhost
      Server Port:            80
      
      Document Path:          /test.png
      Document Length:        8106 bytes
      
      Concurrency Level:      100
      Time taken for tests:   0.611 seconds
      Complete requests:      10000
      Failed requests:        0
      Total transferred:      83410000 bytes
      HTML transferred:       81060000 bytes
      Requests per second:    16379.67 [#/sec] (mean)
      Time per request:       6.105 [ms] (mean)
      Time per request:       0.061 [ms] (mean, across all concurrent requests)
      Transfer rate:          133420.71 [Kbytes/sec] received
      
      Connection Times (ms)
                  min  mean[+/-sd] median   max
      Connect:        0    2   1.1      2      10
      Processing:     1    4   1.6      4      16
      Waiting:        0    2   1.2      2      10
      Total:          2    6   2.1      5      18
      
      Percentage of the requests served within a certain time (ms)
      50%      5
      66%      6
      75%      6
      80%      7
      90%      9
      95%     10
      98%     13
      99%     14
      100%     18 (longest request)
      [root@ip-XXX-XXX-XXX-XXX html]# 

最後にLiteSpeedです。

      [root@ip-XXX-XXX-XXX-XXX html]# ab -n 10000 -c 100 http://localhost:8088/test.png
      This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
      Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
      Licensed to The Apache Software Foundation, http://www.apache.org/
      
      Benchmarking localhost (be patient)
      Completed 1000 requests
      Completed 2000 requests
      Completed 3000 requests
      Completed 4000 requests
      Completed 5000 requests
      Completed 6000 requests
      Completed 7000 requests
      Completed 8000 requests
      Completed 9000 requests
      Completed 10000 requests
      Finished 10000 requests
      
      
      Server Software:        LiteSpeed
      Server Hostname:        localhost
      Server Port:            8088
      
      Document Path:          /test.png
      Document Length:        8106 bytes
      
      Concurrency Level:      100
      Time taken for tests:   0.634 seconds
      Complete requests:      10000
      Failed requests:        0
      Total transferred:      84270000 bytes
      HTML transferred:       81060000 bytes
      Requests per second:    15764.86 [#/sec] (mean)
      Time per request:       6.343 [ms] (mean)
      Time per request:       0.063 [ms] (mean, across all concurrent requests)
      Transfer rate:          129736.82 [Kbytes/sec] received
      
      Connection Times (ms)
      min  mean[+/-sd] median   max
      Connect:        0    1   0.7      1       5
      Processing:     0    5   2.8      5      18
      Waiting:        0    5   2.8      4      17
      Total:          0    6   2.8      6      18
      
      Percentage of the requests served within a certain time (ms)
      50%      6
      66%      7
      75%      8
      80%      9
      90%     10
      95%     11
      98%     13
      99%     14
      100%     18 (longest request)
      [root@ip-XXX-XXX-XXX-XXX html]# 

WEBサーバの処理性能をみる場合には、「TPS=1秒あたりに処理できたリクエスト数」「平均リクエスト処理時間」「99パーセンタイル=全リクエストのうち99%が処理できた時間」を参考にすることが多いので、 「Requests per second」「Time per request:」「Percentage of the requests served within a certain time の 99%」を比較してみます。

TPS

Apache 10571.27
nginx 16379.67
LiteSpeed 15764.86

平均リクエスト処理時間

Apache 9.46
nginx 6.105
LiteSpeed 6.343

パーセンタイル

Apache nginx LiteSpeed
99% 22 99% 14 99% 14

Apacheと比較して、nginx・LiteSpeedの方が1.5倍程度性能がよさそうにみえます。

今回は8Kの画像ファイルに同時接続100人で10000リクエストを処理し、各種Webサーバソフトウェアの性能を測定しました。
次回は5倍の負荷に変更して測定します!
最後までご確認頂きありがとうございました。