LoginSignup
6
5

More than 5 years have passed since last update.

EC2のCPUの数を変えたり、Hyper Threadingオフったり

Last updated at Posted at 2018-05-16

2018年5月8日にリリースされたEC2に対する新しい機能。"Introducing Optimize CPUs for Amazon EC2 Instances"とありますが、平たく言えばEC2起動時にCPUの数を調整したり、Hyper Threadingをオフにしたりできます。

HPC/CAE/EDA屋さんは、すごく嬉しい機能。全てのリージョン、t2以外のすべてのインスタンスですでに有効。EDAのライセンスで言えば、マシンのもつコア数で費用払ってるので、ライセンス節約になる非常に重要な機能だと思います。

2018年5月16日現在、この機能はAWSCLIのみで利用可能になっています。やっててよかったAWSCLI。こういった新機能だと3rd party toolsやGUIの対応は少し遅れるのでAWSCLIのありがたみを感じます。

まずは普通にrun-instances。r4.xlarge(デフォルトで、2 CPU core - 4 vCPU)で検証してみます。インスタンスのオプションはjsonで記述しておきます。

AWSCLIのバージョンはこの時点で最新のもの(v1.15.20)を使いました。古いv1.11.13をつかっていたのですが、それだと古すぎて”--cpu-options”の機能が使えませんでした。

bash
$ aws --version
aws-cli/1.15.20 Python/2.7.10 Darwin/17.5.0 botocore/1.10.20
AWSCLI
aws ec2 run-instances --count 1 --cli-input-json file://r4.xlarge.json

ログインしてlscpu、普通に2CPU core, 4vCPU見えます。

bash
$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    2
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
Stepping:              1
CPU MHz:               2300.066
BogoMIPS:              4600.13
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              46080K
NUMA node0 CPU(s):     0-3

次にHTをオフって、CPU coreを2->1にしてみます。run-instancesコマンドに--cpu-optionsを足すだけです。簡単です。

AWSCLI
aws ec2 run-instances --count 1 --cli-input-json file://r4.xlarge.json --cpu-options "CoreCount=1,ThreadsPerCore=1"

coreが1になって、HTもオフになってるのがわかりますね。

bash
$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
Stepping:              1
CPU MHz:               2300.054
BogoMIPS:              4600.10
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              46080K
NUMA node0 CPU(s):     0

変更できるCPUの数はなんでもOKというわけでなく、ある程度数字が決め打ちされていますのでご注意ください。詳細は公式ドキュメント参照。
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-optimize-cpu.html

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5