dockerでパフォーマンスは低下するのか?

はじめに

仮想環境ではパフォーマンスが低下する傾向があります。
これはVMwareやKVMでも発生しており、dockerでもこの現象が発生すると言われていますが、実際に性能が低下するのか調べてみました。

調査方法はUnixBenchです。CPU/Mem/Storageの試験を行います。

環境

Cloud: ConoHa 512GB (最安モデル)
OS: Rocky Linux 8.6

実行

docker無し(ネイティブのLinux):

yum install -y perl gcc git 
mkdir unixbench
cd unixbench/
git clone https://github.com/kdlucas/byte-unixbench.git .
cd UnixBench/
./Run

docker有り:

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl start docker
docker run -it tukiyo3/centos7-unixbench

結果・まとめ

早速ですが結果です。実行結果は別にまとめています。

環境総合スコア浮動小数点ファイルコピーShell
docker無し(native)1568.711194.3 MWIPS2466821.1 KBps6103.0 lpm
docker有り1372.88911.4 MWIPS1852100.6 KBps6056.8 lpm
低下率12.5%20.4%24.9%0.8%

見ての通り、dockerを使用すると総合スコアで約12.5%のパフォーマンス低下があるようです。
しかし、計測項目によって大きく異なります。浮動小数点計算(CPU性能)では20.4%の低下となっており、ファイルコピー(ストレージ性能)に至っては24.9%とかなり大きなパフォーマンス低下が確認できます。

一方で、shellスクリプトの実行などでは0.8%の低下となっており、ほぼパフォーマン低下はありません。

とはいえ、CPUやストレージ周りなど頻繁に使用する機能が20%を超えるパフォーマンス低下があるのはよろしくありません。
動作環境として、dockerにしなければならない必要性が無い場合は必ずしも使う必要はないと思います。

参考:UnixBenchデータ

docker無し(native):

========================================================================
   BYTE UNIX Benchmarks (Version 5.1.3)

   System: 160-251-15-80: GNU/Linux
   OS: GNU/Linux -- 4.18.0-372.26.1.el8_6.x86_64 -- #1 SMP Tue Sep 13 18:09:48 UTC 2022
   Machine: x86_64 (x86_64)
   Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
   CPU 0: Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz (4794.4 bogomips)
          x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
   CPU 1: Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz (4794.4 bogomips)
          x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
   05:00:56 up 317 days, 11:23,  1 user,  load average: 0.00, 0.54, 1.96; runlevel 2022-10-30

------------------------------------------------------------------------
Benchmark Run: Wed Sep 13 2023 05:00:56 - 05:28:51
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       31240199.1 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     5566.0 MWIPS (9.1 s, 7 samples)
Execl Throughput                               2394.5 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        553399.8 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          148977.3 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1245792.3 KBps  (30.0 s, 2 samples)
Pipe Throughput                              827851.3 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  90528.9 lps   (10.0 s, 7 samples)
Process Creation                               6200.1 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   4455.0 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    856.2 lpm   (60.1 s, 2 samples)
System Call Overhead                         588730.3 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   31240199.1   2677.0
Double-Precision Whetstone                       55.0       5566.0   1012.0
Execl Throughput                                 43.0       2394.5    556.9
File Copy 1024 bufsize 2000 maxblocks          3960.0     553399.8   1397.5
File Copy 256 bufsize 500 maxblocks            1655.0     148977.3    900.2
File Copy 4096 bufsize 8000 maxblocks          5800.0    1245792.3   2147.9
Pipe Throughput                               12440.0     827851.3    665.5
Pipe-based Context Switching                   4000.0      90528.9    226.3
Process Creation                                126.0       6200.1    492.1
Shell Scripts (1 concurrent)                     42.4       4455.0   1050.7
Shell Scripts (8 concurrent)                      6.0        856.2   1427.0
System Call Overhead                          15000.0     588730.3    392.5
                                                                   ========
System Benchmarks Index Score                                         865.9

------------------------------------------------------------------------
Benchmark Run: Wed Sep 13 2023 05:28:51 - 05:56:47
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables       61493628.5 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                    11194.3 MWIPS (9.1 s, 7 samples)
Execl Throughput                               3516.1 lps   (29.7 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        977039.7 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          264470.4 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2466821.1 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1641487.2 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 367545.8 lps   (10.0 s, 7 samples)
Process Creation                               9572.6 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   6103.0 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    927.9 lpm   (60.1 s, 2 samples)
System Call Overhead                        1104965.1 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   61493628.5   5269.4
Double-Precision Whetstone                       55.0      11194.3   2035.3
Execl Throughput                                 43.0       3516.1    817.7
File Copy 1024 bufsize 2000 maxblocks          3960.0     977039.7   2467.3
File Copy 256 bufsize 500 maxblocks            1655.0     264470.4   1598.0
File Copy 4096 bufsize 8000 maxblocks          5800.0    2466821.1   4253.1
Pipe Throughput                               12440.0    1641487.2   1319.5
Pipe-based Context Switching                   4000.0     367545.8    918.9
Process Creation                                126.0       9572.6    759.7
Shell Scripts (1 concurrent)                     42.4       6103.0   1439.4
Shell Scripts (8 concurrent)                      6.0        927.9   1546.5
System Call Overhead                          15000.0    1104965.1    736.6
                                                                   ========
System Benchmarks Index Score                                        1568.7

docker:

========================================================================
   BYTE UNIX Benchmarks (Version 5.1.3)

   System: : GNU/Linux
   OS: GNU/Linux -- 4.18.0-372.26.1.el8_6.x86_64 -- #1 SMP Tue Sep 13 18:09:48 UTC 2022
   Machine: x86_64 (x86_64)
   Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
   CPU 0: Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz (4794.4 bogomips)
          x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
   CPU 1: Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz (4794.4 bogomips)
          x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
   19:51:09 up 317 days, 10:13,  0 users,  load average: 0.84, 0.37, 0.14; runlevel 

------------------------------------------------------------------------
Benchmark Run: Tue Sep 12 2023 19:51:09 - 20:19:12
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       28929058.3 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     4451.5 MWIPS (9.8 s, 7 samples)
Execl Throughput                               2270.9 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        406495.7 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          111727.8 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks        959760.1 KBps  (30.0 s, 2 samples)
Pipe Throughput                              739111.4 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  80833.2 lps   (10.0 s, 7 samples)
Process Creation                               5819.1 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   4382.8 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    864.3 lpm   (60.0 s, 2 samples)
System Call Overhead                         585703.5 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   28929058.3   2478.9
Double-Precision Whetstone                       55.0       4451.5    809.4
Execl Throughput                                 43.0       2270.9    528.1
File Copy 1024 bufsize 2000 maxblocks          3960.0     406495.7   1026.5
File Copy 256 bufsize 500 maxblocks            1655.0     111727.8    675.1
File Copy 4096 bufsize 8000 maxblocks          5800.0     959760.1   1654.8
Pipe Throughput                               12440.0     739111.4    594.1
Pipe-based Context Switching                   4000.0      80833.2    202.1
Process Creation                                126.0       5819.1    461.8
Shell Scripts (1 concurrent)                     42.4       4382.8   1033.7
Shell Scripts (8 concurrent)                      6.0        864.3   1440.5
System Call Overhead                          15000.0     585703.5    390.5
                                                                   ========
System Benchmarks Index Score                                         763.4

------------------------------------------------------------------------
Benchmark Run: Tue Sep 12 2023 20:19:12 - 20:47:15
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables       57873095.9 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     8911.4 MWIPS (9.8 s, 7 samples)
Execl Throughput                               3441.8 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        736707.9 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          192650.5 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1852100.6 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1478410.2 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 292767.1 lps   (10.0 s, 7 samples)
Process Creation                               8627.3 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   6056.8 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    961.9 lpm   (60.0 s, 2 samples)
System Call Overhead                        1108283.9 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   57873095.9   4959.1
Double-Precision Whetstone                       55.0       8911.4   1620.3
Execl Throughput                                 43.0       3441.8    800.4
File Copy 1024 bufsize 2000 maxblocks          3960.0     736707.9   1860.4
File Copy 256 bufsize 500 maxblocks            1655.0     192650.5   1164.1
File Copy 4096 bufsize 8000 maxblocks          5800.0    1852100.6   3193.3
Pipe Throughput                               12440.0    1478410.2   1188.4
Pipe-based Context Switching                   4000.0     292767.1    731.9
Process Creation                                126.0       8627.3    684.7
Shell Scripts (1 concurrent)                     42.4       6056.8   1428.5
Shell Scripts (8 concurrent)                      6.0        961.9   1603.1
System Call Overhead                          15000.0    1108283.9    738.9
                                                                   ========
System Benchmarks Index Score                                        1372.8

参考

What is the runtime performance cost of a Docker container?
I'd like to comprehensively understand the run-time performance cost of a Docker container. I've found references to net...

→この記事によるとネットワークコストは50%程度のレイテンシーの低下があるようです。

コメント

タイトルとURLをコピーしました