e2-micro e2-small e2-mediumのCPU性能【Google Compute Engine】

# TL;DR
コンソールで**vCPU x 2**と表示されるが、同じ性能ではない
![Screenshot from 2022-04-22 14-48-27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208363/bd082ebb-d26e-f5d3-70d6-459ea6bf6ac7.png)

# UnixBench
UnixBenchで計測してみました

```bash
sudo apt update \
  && sudo apt -y install git build-essential \
  && git clone https://github.com/kdlucas/byte-unixbench \
  && cd byte-unixbench/UnixBench \
  && make \
  && ./Run
```

## e2-micro

https://storage.googleapis.com/reckix.appspot.com/instance-1-2022-04-22-01.html

```bash
------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 04:41:03 - 05:10:42
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables        9984986.9 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                      661.9 MWIPS (11.9 s, 7 samples)
Execl Throughput                                458.7 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks         61112.5 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks           17225.9 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks        164151.9 KBps  (30.1 s, 2 samples)
Pipe Throughput                              111139.6 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  10156.3 lps   (10.1 s, 7 samples)
Process Creation                                832.9 lps   (30.1 s, 2 samples)
Shell Scripts (1 concurrent)                   1106.9 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    158.8 lpm   (60.2 s, 2 samples)
System Call Overhead                          67891.9 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0    9984986.9    855.6
Double-Precision Whetstone                       55.0        661.9    120.3
Execl Throughput                                 43.0        458.7    106.7
File Copy 1024 bufsize 2000 maxblocks          3960.0      61112.5    154.3
File Copy 256 bufsize 500 maxblocks            1655.0      17225.9    104.1
File Copy 4096 bufsize 8000 maxblocks          5800.0     164151.9    283.0
Pipe Throughput                               12440.0     111139.6     89.3
Pipe-based Context Switching                   4000.0      10156.3     25.4
Process Creation                                126.0        832.9     66.1
Shell Scripts (1 concurrent)                     42.4       1106.9    261.1
Shell Scripts (8 concurrent)                      6.0        158.8    264.6
System Call Overhead                          15000.0      67891.9     45.3
                                                                   ========
System Benchmarks Index Score                                         130.1

------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 05:10:42 - 05:40:33
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables        9120934.3 lps   (10.1 s, 7 samples)
Double-Precision Whetstone                     1178.2 MWIPS (11.6 s, 7 samples)
Execl Throughput                                646.3 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks         78689.7 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks           22067.0 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks        225430.9 KBps  (30.0 s, 2 samples)
Pipe Throughput                              152743.6 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  42581.6 lps   (10.0 s, 7 samples)
Process Creation                               1617.9 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   1281.2 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    174.4 lpm   (60.2 s, 2 samples)
System Call Overhead                          88979.1 lps   (10.1 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0    9120934.3    781.6
Double-Precision Whetstone                       55.0       1178.2    214.2
Execl Throughput                                 43.0        646.3    150.3
File Copy 1024 bufsize 2000 maxblocks          3960.0      78689.7    198.7
File Copy 256 bufsize 500 maxblocks            1655.0      22067.0    133.3
File Copy 4096 bufsize 8000 maxblocks          5800.0     225430.9    388.7
Pipe Throughput                               12440.0     152743.6    122.8
Pipe-based Context Switching                   4000.0      42581.6    106.5
Process Creation                                126.0       1617.9    128.4
Shell Scripts (1 concurrent)                     42.4       1281.2    302.2
Shell Scripts (8 concurrent)                      6.0        174.4    290.7
System Call Overhead                          15000.0      88979.1     59.3
                                                                   ========
System Benchmarks Index Score                                         190.4
```

## e2-small

https://storage.googleapis.com/reckix.appspot.com/instance-1-2022-04-22-02.html

```bash
------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 05:50:47 - 06:23:18
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       33838412.5 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     1446.5 MWIPS (35.1 s, 7 samples)
Execl Throughput                                932.9 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        152013.5 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks           40890.3 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks        441683.7 KBps  (30.0 s, 2 samples)
Pipe Throughput                              223233.2 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  22075.0 lps   (10.0 s, 7 samples)
Process Creation                               1685.9 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   2305.9 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    357.9 lpm   (60.0 s, 2 samples)
System Call Overhead                         138463.6 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   33838412.5   2899.6
Double-Precision Whetstone                       55.0       1446.5    263.0
Execl Throughput                                 43.0        932.9    217.0
File Copy 1024 bufsize 2000 maxblocks          3960.0     152013.5    383.9
File Copy 256 bufsize 500 maxblocks            1655.0      40890.3    247.1
File Copy 4096 bufsize 8000 maxblocks          5800.0     441683.7    761.5
Pipe Throughput                               12440.0     223233.2    179.4
Pipe-based Context Switching                   4000.0      22075.0     55.2
Process Creation                                126.0       1685.9    133.8
Shell Scripts (1 concurrent)                     42.4       2305.9    543.8
Shell Scripts (8 concurrent)                      6.0        357.9    596.4
System Call Overhead                          15000.0     138463.6     92.3
                                                                   ========
System Benchmarks Index Score                                         297.2

------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 06:23:18 - 06:54:50
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables       18546171.3 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     2587.7 MWIPS (28.7 s, 7 samples)
Execl Throughput                               1287.3 lps   (30.1 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        207261.6 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks           54169.8 KBps  (30.1 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks        623682.5 KBps  (30.0 s, 2 samples)
Pipe Throughput                              311152.7 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  84897.7 lps   (10.0 s, 7 samples)
Process Creation                               3357.9 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   2631.4 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    360.4 lpm   (60.0 s, 2 samples)
System Call Overhead                         180316.3 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   18546171.3   1589.2
Double-Precision Whetstone                       55.0       2587.7    470.5
Execl Throughput                                 43.0       1287.3    299.4
File Copy 1024 bufsize 2000 maxblocks          3960.0     207261.6    523.4
File Copy 256 bufsize 500 maxblocks            1655.0      54169.8    327.3
File Copy 4096 bufsize 8000 maxblocks          5800.0     623682.5   1075.3
Pipe Throughput                               12440.0     311152.7    250.1
Pipe-based Context Switching                   4000.0      84897.7    212.2
Process Creation                                126.0       3357.9    266.5
Shell Scripts (1 concurrent)                     42.4       2631.4    620.6
Shell Scripts (8 concurrent)                      6.0        360.4    600.7
System Call Overhead                          15000.0     180316.3    120.2
                                                                   ========
System Benchmarks Index Score                                         415.1
```

## e2-medium

https://storage.googleapis.com/reckix.appspot.com/instance-1-2022-04-22-03.html

```bash
------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 07:00:53 - 07:28:54
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       34231912.4 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     5880.4 MWIPS (9.0 s, 7 samples)
Execl Throughput                               1906.5 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        366144.0 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          100804.0 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1074262.2 KBps  (30.0 s, 2 samples)
Pipe Throughput                              457348.4 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  45239.5 lps   (10.0 s, 7 samples)
Process Creation                               3341.0 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   4565.0 lpm   (60.1 s, 2 samples)
Shell Scripts (8 concurrent)                    684.7 lpm   (60.0 s, 2 samples)
System Call Overhead                         275127.3 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   34231912.4   2933.3
Double-Precision Whetstone                       55.0       5880.4   1069.2
Execl Throughput                                 43.0       1906.5    443.4
File Copy 1024 bufsize 2000 maxblocks          3960.0     366144.0    924.6
File Copy 256 bufsize 500 maxblocks            1655.0     100804.0    609.1
File Copy 4096 bufsize 8000 maxblocks          5800.0    1074262.2   1852.2
Pipe Throughput                               12440.0     457348.4    367.6
Pipe-based Context Switching                   4000.0      45239.5    113.1
Process Creation                                126.0       3341.0    265.2
Shell Scripts (1 concurrent)                     42.4       4565.0   1076.7
Shell Scripts (8 concurrent)                      6.0        684.7   1141.1
System Call Overhead                          15000.0     275127.3    183.4
                                                                   ========
System Benchmarks Index Score                                         625.7

------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 07:28:54 - 07:58:01
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables       37336998.3 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     6080.6 MWIPS (15.8 s, 7 samples)
Execl Throughput                               2668.4 lps   (29.9 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        509982.8 KBps  (30.1 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          134638.3 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1550728.8 KBps  (30.1 s, 2 samples)
Pipe Throughput                              627817.8 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 166689.9 lps   (10.0 s, 7 samples)
Process Creation                               6862.8 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   5363.3 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    734.7 lpm   (60.1 s, 2 samples)
System Call Overhead                         359977.7 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   37336998.3   3199.4
Double-Precision Whetstone                       55.0       6080.6   1105.6
Execl Throughput                                 43.0       2668.4    620.6
File Copy 1024 bufsize 2000 maxblocks          3960.0     509982.8   1287.8
File Copy 256 bufsize 500 maxblocks            1655.0     134638.3    813.5
File Copy 4096 bufsize 8000 maxblocks          5800.0    1550728.8   2673.7
Pipe Throughput                               12440.0     627817.8    504.7
Pipe-based Context Switching                   4000.0     166689.9    416.7
Process Creation                                126.0       6862.8    544.7
Shell Scripts (1 concurrent)                     42.4       5363.3   1264.9
Shell Scripts (8 concurrent)                      6.0        734.7   1224.5
System Call Overhead                          15000.0     359977.7    240.0
                                                                   ========
System Benchmarks Index Score                                         894.3
```

## Cloud Shell

https://storage.googleapis.com/reckix.appspot.com/cs-796895957213-default-2022-04-22-02.html

```bash
------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 05:52:55 - 06:21:01
4 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       33462334.9 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     5562.1 MWIPS (9.9 s, 7 samples)
Execl Throughput                               2596.8 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        400966.8 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          114552.5 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1046512.3 KBps  (30.0 s, 2 samples)
Pipe Throughput                              630958.7 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  68609.8 lps   (10.0 s, 7 samples)
Process Creation                               4495.3 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   4845.2 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1293.1 lpm   (60.0 s, 2 samples)
System Call Overhead                         372575.4 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   33462334.9   2867.4
Double-Precision Whetstone                       55.0       5562.1   1011.3
Execl Throughput                                 43.0       2596.8    603.9
File Copy 1024 bufsize 2000 maxblocks          3960.0     400966.8   1012.5
File Copy 256 bufsize 500 maxblocks            1655.0     114552.5    692.2
File Copy 4096 bufsize 8000 maxblocks          5800.0    1046512.3   1804.3
Pipe Throughput                               12440.0     630958.7    507.2
Pipe-based Context Switching                   4000.0      68609.8    171.5
Process Creation                                126.0       4495.3    356.8
Shell Scripts (1 concurrent)                     42.4       4845.2   1142.7
Shell Scripts (8 concurrent)                      6.0       1293.1   2155.2
System Call Overhead                          15000.0     372575.4    248.4
                                                                   ========
System Benchmarks Index Score                                         767.9

------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 06:21:01 - 06:49:13
4 CPUs in system; running 4 parallel copies of tests

Dhrystone 2 using register variables       84832106.0 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                    18908.4 MWIPS (10.0 s, 7 samples)
Execl Throughput                               6240.8 lps   (29.9 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        567585.6 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          153013.6 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1559305.4 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1515460.8 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 294635.8 lps   (10.0 s, 7 samples)
Process Creation                              12238.6 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                  10081.1 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1369.8 lpm   (60.1 s, 2 samples)
System Call Overhead                         865986.1 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   84832106.0   7269.2
Double-Precision Whetstone                       55.0      18908.4   3437.9
Execl Throughput                                 43.0       6240.8   1451.4
File Copy 1024 bufsize 2000 maxblocks          3960.0     567585.6   1433.3
File Copy 256 bufsize 500 maxblocks            1655.0     153013.6    924.6
File Copy 4096 bufsize 8000 maxblocks          5800.0    1559305.4   2688.5
Pipe Throughput                               12440.0    1515460.8   1218.2
Pipe-based Context Switching                   4000.0     294635.8    736.6
Process Creation                                126.0      12238.6    971.3
Shell Scripts (1 concurrent)                     42.4      10081.1   2377.6
Shell Scripts (8 concurrent)                      6.0       1369.8   2283.0
System Call Overhead                          15000.0     865986.1    577.3
                                                                   ========
System Benchmarks Index Score                                        1630.5
```

## Google Colaboratory

https://storage.googleapis.com/reckix.appspot.com/e22211d7b8de-2022-04-22-02%20(2).html

```bash
------------------------------------------------------------------------
Benchmark Run: Fri Apr 22 2022 07:10:20 - 07:38:35
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       33695633.2 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     4508.9 MWIPS (10.6 s, 7 samples)
Execl Throughput                                547.2 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        557139.4 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          148951.5 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1473819.1 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1374264.5 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  76479.2 lps   (10.0 s, 7 samples)
Process Creation                               2298.3 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   2566.0 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    390.5 lpm   (60.1 s, 2 samples)
System Call Overhead                        1101692.4 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   33695633.2   2887.4
Double-Precision Whetstone                       55.0       4508.9    819.8
Execl Throughput                                 43.0        547.2    127.3
File Copy 1024 bufsize 2000 maxblocks          3960.0     557139.4   1406.9
File Copy 256 bufsize 500 maxblocks            1655.0     148951.5    900.0
File Copy 4096 bufsize 8000 maxblocks          5800.0    1473819.1   2541.1
Pipe Throughput                               12440.0    1374264.5   1104.7
Pipe-based Context Switching                   4000.0      76479.2    191.2
Process Creation                                126.0       2298.3    182.4
Shell Scripts (1 concurrent)                     42.4       2566.0    605.2
Shell Scripts (8 concurrent)                      6.0        390.5    650.8
System Call Overhead                          15000.0    1101692.4    734.5
                                                                   ========
System Benchmarks Index Score                                         685.7
```

# CPU性能

0.25 0.5 1のように性能があがってます

|               | 1CPU   | MultiCPU |
| ------------- | -----: | -------: |
| e2-micro      | 130.1  | 190.4    |
| e2-small      | 297.2  | 415.1    |
| e2-medium     | 625.7  | 894.3    |
| f1-micro      | 301.1[^1]  |          |
| g1-small      | 931.3[^1]  |          |
| n1-standard-1 | 1495.6[^1] |          |
| Cloud Shell   | 767.9  | 1630.5   |
| Google Colab  | 685.7  |

[^1]: https://a-tak.com/blog/2015/11/gce-benchmark/

![1CPU と MultiCPU.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208363/3d880543-4572-5ead-97c0-e2a08a18a0a7.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208363/4e880d15-0a9c-e08a-ee5d-c2c66731cf22.png)

# まとめ
- **e2-micro**でCPU100%になり性能がでないと感じたら、**e2-small**にしてみるのがいいのかもしれません
- コンソールに惑わされないようにしましょう

# 参考
https://cloud.google.com/compute/vm-instance-pricing?hl=ja#e2_sharedcore_machine_types

https://cloud.google.com/blog/ja/products/compute/google-compute-engine-gets-new-e2-vm-machine-types

https://satoh.dev/blog/which-is-the-best-always-free-vps/