2&>1

AWSとかGCPとかGolangとかとか

S3からEFSへデータ移行するときの最適解

EC2からS3へマウントして溜め込んだデータをEFSへ移行する必要が出てきたので、どれがいいのか検証してみました。

前提条件

OS : CentOS6

s3fsを使用してS3をマウント

溜め込んだデータ

今回はテストということで

総ファイル数:3500

総ファイル容量:5GB

移行手段

移行手段としては以下が候補になるかと思います。

1.「rsync」コマンド

2.「AWSCLI」コマンド

検証

「rsysnc」コマンド

#time rsync -avp /mnt/s3/ /mnt/efs/

real    3m26.455s
user    0m11.519s
sys     0m3.369s

「AWSCLI」コマンド

#aws s3 sync  s3://hogehoge/ /mnt/efs/

real    1m28.607s
user    0m29.497s
sys     0m16.604s

f:id:piyojir0:20190327174633j:plain
圧倒的じゃないか s3 sync!!!

まとめ

少し雑な検証ですけどrsyncだとファイル数が多ければ多いほど不利です。。

この辺はs3fsを使用してる以上しょうがないきもしますね。

大人しくAWSCLIを使いましょう。

CloudFormation(1)改

dev-error.hatenablog.com

ちょっと修正しました。

改修箇所

1.AMIは最新のAmazonlinux2になる

2.BackendSubnetを追加

3.SubnetのAZを指定

AWSTemplateFormatVersion: '2010-09-09'
Description: VPC,subnetx4(Frontx2,Backx2),Bastion

Parameters:
  # SSH用キーペアの指定
  KeyPair:
    Description: For SSH
    Type: AWS::EC2::KeyPair::KeyName
  BastionAMI:
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Default: "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"

Resources:
  hogehogeVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/21
      EnableDnsSupport: 'true'
      EnableDnsHostnames: 'true'
      Tags:
      - Key: Name
        Value: hogehoge-VPC
  InternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
      - Key: Name
        Value: hogehoge-VPC-IGW
  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref hogehogeVPC
      InternetGatewayId: !Ref InternetGateway

  FrontendRouteTable:
    Type: AWS::EC2::RouteTable
    DependsOn: AttachGateway
    Properties:
      VpcId: !Ref hogehogeVPC
      Tags:
      - Key: Name
        Value: hogehoge-VPC-FrontendRoute
  FrontendRoute:
    Type: AWS::EC2::Route
    DependsOn: AttachGateway
    Properties:
      RouteTableId: !Ref FrontendRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway
  FrontendSubnet01:
    Type: AWS::EC2::Subnet
    DependsOn: AttachGateway
    Properties:
      AvailabilityZone: ap-northeast-1a
      CidrBlock: 10.0.1.0/24
      MapPublicIpOnLaunch: 'false'
      VpcId: !Ref hogehogeVPC
      Tags:
      - Key: Name
        Value: hogehoge-VPC-FrontendSubnet01
  FrontendSubnetRouteTableAssociation01:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref FrontendSubnet01
      RouteTableId: !Ref FrontendRouteTable

  FrontendSubnet02:
    Type: AWS::EC2::Subnet
    DependsOn: AttachGateway
    Properties:
      AvailabilityZone: ap-northeast-1d
      CidrBlock: 10.0.2.0/24
      MapPublicIpOnLaunch: 'false'
      VpcId: !Ref hogehogeVPC
      Tags:
      - Key: Name
        Value: hogehoge-VPC-FrontendSubnet02
  FrontendSubnetRouteTableAssociation02:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref FrontendSubnet02
      RouteTableId: !Ref FrontendRouteTable

  BackendRouteTable:
    Type: AWS::EC2::RouteTable
    DependsOn: AttachGateway
    Properties:
      VpcId: !Ref hogehogeVPC
      Tags:
      - Key: Name
        Value: hogehoge-VPC-BackendRoute
  BackendSubnet01:
    Type: AWS::EC2::Subnet
    DependsOn: AttachGateway
    Properties:
      AvailabilityZone: ap-northeast-1a
      CidrBlock: 10.0.4.0/24
      MapPublicIpOnLaunch: 'false'
      VpcId: !Ref hogehogeVPC
      Tags:
      - Key: Name
        Value: hogehoge-VPC-BackendSubnet01
  BackendSubnetRouteTableAssociation01:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref BackendSubnet01
      RouteTableId: !Ref BackendRouteTable

  BackendSubnet02:
    Type: AWS::EC2::Subnet
    DependsOn: AttachGateway
    Properties:
      AvailabilityZone: ap-northeast-1d
      CidrBlock: 10.0.5.0/24
      MapPublicIpOnLaunch: 'false'
      VpcId: !Ref hogehogeVPC
      Tags:
      - Key: Name
        Value: hogehoge-VPC-BackendSubnet02
  BackendSubnetRouteTableAssociation02:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref BackendSubnet02
      RouteTableId: !Ref BackendRouteTable

  bastionSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: Bastion-SG
      VpcId: !Ref hogehogeVPC
      Tags:
        - Key: 'Name'
          Value: 'bastionSG'
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '22'
        ToPort: '22'
        CidrIp: 1.1.1.1/32
  bastionEC2:
    Type: 'AWS::EC2::Instance'
    Properties:
      # EBS設定
      BlockDeviceMappings:
        - DeviceName: '/dev/xvda'
          Ebs:
            VolumeType: 'gp2'
            VolumeSize: 8
      ImageId: !Ref BastionAMI
      # シャットダウン時の動作
      InstanceInitiatedShutdownBehavior: 'stop'
      # インスタンスタイプ
      InstanceType: 't3.nano'
      # キーペア
      KeyName: !Ref KeyPair
      # 詳細モニタリング設定
      Monitoring: false
      # セキュリティグループ
      SecurityGroupIds:
        - !GetAtt bastionSecurityGroup.GroupId
      # サブネット
      SubnetId: !Ref FrontendSubnet01
      # テナンシー
      Tenancy: 'default'
      # バースト無制限の無効化
      CreditSpecification:
         CPUCredits: 'standard'
      UserData: 
        Fn::Base64: !Sub |
          #!/bin/bash
          yum -y update
          timedatectl set-timezone Asia/Tokyo
          localectl set-locale LANG=ja_JP.UTF-8
          localectl set-keymap jp106
      # タグ
      Tags:
        - Key: 'Name'
          Value: 'hogehoge-bastion'
  bastionEIP:
    Type: "AWS::EC2::EIP"
    Properties:
      Domain: vpc
  bastionEIPAssociate:
    Type: AWS::EC2::EIPAssociation
    Properties: 
      AllocationId: !GetAtt bastionEIP.AllocationId
      InstanceId: !Ref bastionEC2

CloudFormation(1)

CloudFormationのサンプルを公開します。

このシリーズでは私が勉強がてら書いたサンプルだけ載せます。 書き方とか解説はしないです。

今回は以下構成。

f:id:piyojir0:20190322230531j:plain
cfn1

シンプル過ぎますけど最初なので。

VPC作ってサブネット切ってT3インスタンスだけ立ててます。 踏み台インスタンスだけ用意しました。みたいなやつです。

AWSTemplateFormatVersion: '2010-09-09'
Description: aiueo-test

Parameters:
  # SSH用キーペアの指定
  KeyPair:
    Description: test
    Type: AWS::EC2::KeyPair::KeyName

Mappings:
  StackConfig:
    EC2:
      ImageId: 'ami-0f9ae750e8274075b'


Resources:
  aiueoVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/21
      EnableDnsSupport: 'true'
      EnableDnsHostnames: 'true'
      Tags:
      - Key: Name
        Value: aiueo-VPC
  InternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
      - Key: Name
        Value: aiueo-VPC-IGW
  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref aiueoVPC
      InternetGatewayId: !Ref InternetGateway
  FrontendRouteTable:
    Type: AWS::EC2::RouteTable
    DependsOn: AttachGateway
    Properties:
      VpcId: !Ref aiueoVPC
      Tags:
      - Key: Name
        Value: aiueo-VPC-FrontendRoute
  FrontendRoute:
    Type: AWS::EC2::Route
    DependsOn: AttachGateway
    Properties:
      RouteTableId: !Ref FrontendRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway
  FrontendSubnet:
    Type: AWS::EC2::Subnet
    DependsOn: AttachGateway
    Properties:
      CidrBlock: 10.0.1.0/24
      MapPublicIpOnLaunch: 'false'
      VpcId: !Ref aiueoVPC
      Tags:
      - Key: Name
        Value: aiueo-VPC-FrontendSubnet
  FrontendSubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref FrontendSubnet
      RouteTableId: !Ref FrontendRouteTable
  bastionSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: Bastion-SG
      VpcId: !Ref aiueoVPC
      Tags:
        - Key: 'Name'
          Value: 'bastionSG'
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '22'
        ToPort: '22'
        CidrIp: 210.172.143.100/32
  bastionEC2:
    Type: 'AWS::EC2::Instance'
    Properties:
      # EBS設定
      BlockDeviceMappings:
        - DeviceName: '/dev/xvda'
          Ebs:
            VolumeType: 'gp2'
            VolumeSize: 8
      ImageId: !FindInMap [ StackConfig, EC2, ImageId ]
      # シャットダウン時の動作
      InstanceInitiatedShutdownBehavior: 'stop'
      # インスタンスタイプ
      InstanceType: 't3.nano'
      # キーペア
      KeyName: !Ref KeyPair
      # 詳細モニタリング設定
      Monitoring: false
      # セキュリティグループ
      SecurityGroupIds:
        - !GetAtt bastionSecurityGroup.GroupId
      # サブネット
      SubnetId: !Ref FrontendSubnet
      # テナンシー
      Tenancy: 'default'
      # バースト無制限の無効化
      CreditSpecification:
         CPUCredits: 'standard'
      UserData: 
        Fn::Base64: !Sub |
          #!/bin/bash
          yum -y update
          timedatectl set-timezone Asia/Tokyo
          localectl set-locale LANG=ja_JP.UTF-8
          localectl set-keymap jp106
      # タグ
      Tags:
        - Key: 'Name'
          Value: 'aiueo-bastion'
  bastionEIP:
    Type: "AWS::EC2::EIP"
    Properties:
      Domain: vpc
  bastionEIPAssociate:
    Type: AWS::EC2::EIPAssociation
    Properties: 
      AllocationId: !GetAtt bastionEIP.AllocationId
      InstanceId: !Ref bastionEC2

ElasticIPってタグ付けできなかったけ??

もうちょっと調べておきます。

以上

EC2のEIPを動的に取得して接続できるマクロ作った

背景

EC2インスタンスを立ててElasticIPつけてSSHで接続する。

これをよくやるんですけどたまにしか使わないやつだけど消すまでじゃないやつとかシャットダウンするじゃないですか?

そうするとEIPが密かに金取っていくじゃないですか?

だからEIP開放するじゃないですか?

また使うときに違うEIPになるじゃないですか。

EIP書き直すのめんどくせ。

やること

バッチファイルでAWSCLI実行させてEIP取得してteratermマクロで接続する

環境

OS : Windows10

ターミナル ; cmder

SSH Client : TeraTerm

事前準備

1 . AWS CLIをインストール  

docs.aws.amazon.com

2 . IAMでユーザー作成

 既存のでもいいです。「EC2readonly」権限だけあれば良いです。

3 . 2のユーザーでアクセスキーを発行

ソース

EIPを取得するバッチファイル

@echo of
cd /d %~dp0
aws ec2 --profile [アクセスキーファイル] describe-instances --filters "Name=tag:Name,Values=%1" --query "Reservations[*].Instances[*].PublicIpAddress" --output text > ip.txt

バッチはこんな感じで出力されてます

server1     53.xx.xx.xx
server2     10.xx.xx.xx
server3     13.x.x.x

アクセスキーファイルの作り方

aws configure --profile sample
AWS Access Key ID [None]: XXXXXXXXXXXXXXXX 
AWS Secret Access Key [None]: XXXXXXXXXXXXXXXX
Default region name [None]: ap-northeast-1
Default output format [None]: json

TeraTermマクロ

・EIP取得するバッチファイルのパスは適宜変更

・接続するインスタンス名も適宜(インスタンス名はユニークな事

秘密鍵へのパスも適宜変更

; バッチを実行してEIP取得
exec 'cmd /c c:\path\to\bat\get_ec2_ip.bat [接続先インスタンス名] '
; EIP取得までの時間待ち(これないとEIP取得前に接続しようとしてエラー)
;時間は環境によって要調整
pause 2

fileopen FH 'ip.txt' 0 0
filereadln FH HOST_ADDR
fileclose FH

; ユーザ名/秘密鍵を設定
USER_NAME = 'ec2-user'
getenv 'HOME' KEY_FILE
strconcat KEY_FILE 'C:\path\to\key.pem'

strconcat COMMAND ':22 /ssh /2 /auth=publickey /user=' 
strconcat COMMAND USER_NAME 
strconcat COMMAND ' /keyfile="' 

strconcat COMMAND KEY_FILE


; サーバへ接続 
connect COMMAND


end

これでTeraTermマクロ実行するとバッチが実行してEIP取得してそのIPに接続されます。

インスタンスごとにTeraTermマクロを用意します。

ハマったこと

Cmderで作業しててこっちからはバッチを正常に実行できるけどバッチをダブルクリックで実行するとエラーになる状況でした。

原因はバッチ直で実行する場合にアクセスキーが設定されてませんでした。

Cmderではaws configureから設定してたんですけど。。 bash環境との違いですかね。。。

そんなわけで--profileで指定するようにしました。

ソースはココ

GitHub - piyoji333/ssh-teraterm

以上

M5とM5aインスタンスの性能比較を試す

M5aが東京リージョンでもリリースされました。

M5aとはAMD製CPUを使用したインスタンスですけど既存のIntel製CPUと比較してどれくらいなものかきになったので性能比較してみました。

今回の比較対象

・M5.large

・M5a.large

OSは共に「Amazon Linux 2」

準備

定番「UnixBench」を使います。

1 . モジュールをインストール

yum install -y wget gcc make perl perl-Time-HiRes patch

2 . UnixBenchのパッケージファイルダウンロードと展開

wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/byte-unixbench/UnixBench5.1.3.tgz
tar xfz UnixBench5.1.3.tgz

3 . パッチ適応(デフォルトでは16コア以上の測定ができないため。(本検証では不要ですけども))

cd UnixBench/
wget http://storage.googleapis.com/google-code-attachments/byte-unixbench/issue-4/comment-1/fix-limitation.patch
patch Run fix-limitation.patch

UnixBenchのインストール完了

計測

以下コマンドで計測

./Run -i 5

比較

まずはCPU情報の比較(2コアなので2つ分それぞれ出力されてます)

M5.large

# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
stepping        : 4
microcode       : 0x200005a
cpu MHz         : 3110.790
cache size      : 33792 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips        : 5000.00
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
stepping        : 4
microcode       : 0x200005a
cpu MHz         : 3112.951
cache size      : 33792 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips        : 5000.00
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

M5a.large

# cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 23
model           : 1
model name      : AMD EPYC 7571
stepping        : 2
microcode       : 0x8001227
cpu MHz         : 2664.885
cache size      : 512 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch topoext vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero xsaveerptr arat npt nrip_save
bugs            : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips        : 4399.73
TLB size        : 2560 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : AuthenticAMD
cpu family      : 23
model           : 1
model name      : AMD EPYC 7571
stepping        : 2
microcode       : 0x8001227
cpu MHz         : 2538.409
cache size      : 512 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch topoext vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero xsaveerptr arat npt nrip_save
bugs            : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips        : 4399.73
TLB size        : 2560 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management:

実行結果

1CPUの場合

項目 M5インスタンス M5aインスタンス 備考
Dhrystone 2 using register variables 3234.1 2945.1 整数演算処理
Double-Precision Whetstone 852.8 763.3 浮動小数点数演算処理
Execl Throughput 1211.1 1107.7 関数の呼び出し性能
File Copy 1024 bufsize 2000 maxblocks 2081.6 2043.5 ファイルコピー(バッファサイズ1024バイト)
File Copy 256 bufsize 500 maxblocks 1313.4 1324.5 ファイルのコピー(バッファサイズ254バイト)
File Copy 4096 bufsize 8000 maxblocks 4492.7 3980.8 ファイルのコピー(バッファサイズ4096バイト)
Pipe Throughput 912.1 1165 パイプ処理のスループット
Pipe-based Context Switching 196.9 122.7 パイプベースのコンテキストのスイッチング処理
Process Creation 1048.6 806.5 プロセスのフォーク処理
Shell Scripts (1 concurrent) 2032.7 1779.7 システムコールでのオーバーヘッド
Shell Scripts (8 concurrent) 2316.3 2281.5 単体シェルスクリプト処理
System Call Overhead 493 1106 8個でのシェルスクリプト並列処理
項目 M5インスタンス M5aインスタンス
System Benchmarks Index Score 1272 1245.2

2CPUの場合

項目 M5インスタンス M5aインスタンス 備考
Dhrystone 2 using register variables 4246.8 3708.9 整数演算処理
Double-Precision Whetstone 1472.9 1480.1 浮動小数点数演算処理
Execl Throughput 1785 1488.7 関数の呼び出し性能
File Copy 1024 bufsize 2000 maxblocks 3064.9 2701.4 ファイルコピー(バッファサイズ1024バイト)
File Copy 256 bufsize 500 maxblocks 1914.2 1800.7 ファイルのコピー(バッファサイズ254バイト)
File Copy 4096 bufsize 8000 maxblocks 6617.9 5511.4 ファイルのコピー(バッファサイズ4096バイト)
Pipe Throughput 1347.6 1549.6 パイプ処理のスループット
Pipe-based Context Switching 973.1 835 パイプベースのコンテキストのスイッチング処理
Process Creation 1736.1 1795.3 プロセスのフォーク処理
Shell Scripts (1 concurrent) 2398.3 2293.5 システムコールでのオーバーヘッド
Shell Scripts (8 concurrent) 2346.1 2310.5 単体シェルスクリプト処理
System Call Overhead 794.2 1380.8 8個でのシェルスクリプト並列処理
項目 M5インスタンス M5aインスタンス
System Benchmarks Index Score 2012.4 1984.2

まとめ

最終的に「 System Benchmarks Index Score」の値が大きいほうが良いです。

そんなに変わらないですけど若干「M5インスタンス」が優位ですかね。

おまけ

実行結果貼り付け

M5インスタンス

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

   System: ip-172-168-3-51.ap-northeast-1.compute.internal: GNU/Linux
   OS: GNU/Linux -- 4.14.104-95.84.amzn2.x86_64 -- #1 SMP Sat Mar 2 00:40:20 UTC 2019
   Machine: x86_64 (x86_64)
   Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
   CPU 0: Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz (5000.0 bogomips)
          Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
   CPU 1: Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz (5000.0 bogomips)
          Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
   07:01:33 up 4 min,  1 user,  load average: 0.02, 0.03, 0.00; runlevel 5

------------------------------------------------------------------------
Benchmark Run: Tue Mar 19 2019 07:01:33 - 07:18:23
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       37741819.2 lps   (10.0 s, 4 samples)
Double-Precision Whetstone                     4690.4 MWIPS (9.9 s, 4 samples)
Execl Throughput                               5207.8 lps   (29.9 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        824302.2 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          217374.0 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2605794.9 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1134627.7 lps   (10.0 s, 4 samples)
Pipe-based Context Switching                  78779.6 lps   (10.0 s, 4 samples)
Process Creation                              13211.8 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   8618.6 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1389.8 lpm   (60.0 s, 2 samples)
System Call Overhead                         739542.3 lps   (10.0 s, 4 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   37741819.2   3234.1
Double-Precision Whetstone                       55.0       4690.4    852.8
Execl Throughput                                 43.0       5207.8   1211.1
File Copy 1024 bufsize 2000 maxblocks          3960.0     824302.2   2081.6
File Copy 256 bufsize 500 maxblocks            1655.0     217374.0   1313.4
File Copy 4096 bufsize 8000 maxblocks          5800.0    2605794.9   4492.7
Pipe Throughput                               12440.0    1134627.7    912.1
Pipe-based Context Switching                   4000.0      78779.6    196.9
Process Creation                                126.0      13211.8   1048.6
Shell Scripts (1 concurrent)                     42.4       8618.6   2032.7
Shell Scripts (8 concurrent)                      6.0       1389.8   2316.3
System Call Overhead                          15000.0     739542.3    493.0
                                                                   ========
System Benchmarks Index Score                                        1272.0

------------------------------------------------------------------------
Benchmark Run: Tue Mar 19 2019 07:18:23 - 07:35:14
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables       49559728.2 lps   (10.0 s, 4 samples)
Double-Precision Whetstone                     8101.2 MWIPS (10.0 s, 4 samples)
Execl Throughput                               7675.6 lps   (29.6 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1213697.0 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          316806.9 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       3838399.1 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1676385.3 lps   (10.0 s, 4 samples)
Pipe-based Context Switching                 389244.2 lps   (10.0 s, 4 samples)
Process Creation                              21874.5 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                  10168.6 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1407.6 lpm   (60.0 s, 2 samples)
System Call Overhead                        1191333.6 lps   (10.0 s, 4 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   49559728.2   4246.8
Double-Precision Whetstone                       55.0       8101.2   1472.9
Execl Throughput                                 43.0       7675.6   1785.0
File Copy 1024 bufsize 2000 maxblocks          3960.0    1213697.0   3064.9
File Copy 256 bufsize 500 maxblocks            1655.0     316806.9   1914.2
File Copy 4096 bufsize 8000 maxblocks          5800.0    3838399.1   6617.9
Pipe Throughput                               12440.0    1676385.3   1347.6
Pipe-based Context Switching                   4000.0     389244.2    973.1
Process Creation                                126.0      21874.5   1736.1
Shell Scripts (1 concurrent)                     42.4      10168.6   2398.3
Shell Scripts (8 concurrent)                      6.0       1407.6   2346.1
System Call Overhead                          15000.0    1191333.6    794.2
                                                                   ========
System Benchmarks Index Score                                        2012.4

M5aインスタンス

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

   System: ip-172-168-3-208.ap-northeast-1.compute.internal: GNU/Linux
   OS: GNU/Linux -- 4.14.104-95.84.amzn2.x86_64 -- #1 SMP Sat Mar 2 00:40:20 UTC 2019
   Machine: x86_64 (x86_64)
   Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
   CPU 0: AMD EPYC 7571 (4399.7 bogomips)
          Hyper-Threading, x86-64, MMX, AMD MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
   CPU 1: AMD EPYC 7571 (4399.7 bogomips)
          Hyper-Threading, x86-64, MMX, AMD MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
   07:01:27 up 3 min,  1 user,  load average: 0.07, 0.08, 0.03; runlevel 5

------------------------------------------------------------------------
Benchmark Run: Tue Mar 19 2019 07:01:27 - 07:18:25
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       34369205.7 lps   (10.0 s, 4 samples)
Double-Precision Whetstone                     4198.4 MWIPS (11.7 s, 4 samples)
Execl Throughput                               4762.9 lps   (29.6 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        809240.5 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          219205.0 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2308868.3 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1449217.0 lps   (10.0 s, 4 samples)
Pipe-based Context Switching                  49074.0 lps   (10.0 s, 4 samples)
Process Creation                              10161.9 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   7545.8 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1368.9 lpm   (60.0 s, 2 samples)
System Call Overhead                        1659072.6 lps   (10.0 s, 4 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   34369205.7   2945.1
Double-Precision Whetstone                       55.0       4198.4    763.3
Execl Throughput                                 43.0       4762.9   1107.7
File Copy 1024 bufsize 2000 maxblocks          3960.0     809240.5   2043.5
File Copy 256 bufsize 500 maxblocks            1655.0     219205.0   1324.5
File Copy 4096 bufsize 8000 maxblocks          5800.0    2308868.3   3980.8
Pipe Throughput                               12440.0    1449217.0   1165.0
Pipe-based Context Switching                   4000.0      49074.0    122.7
Process Creation                                126.0      10161.9    806.5
Shell Scripts (1 concurrent)                     42.4       7545.8   1779.7
Shell Scripts (8 concurrent)                      6.0       1368.9   2281.5
System Call Overhead                          15000.0    1659072.6   1106.0
                                                                   ========
System Benchmarks Index Score                                        1245.2

------------------------------------------------------------------------
Benchmark Run: Tue Mar 19 2019 07:18:25 - 07:35:16
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables       43282979.7 lps   (10.0 s, 4 samples)
Double-Precision Whetstone                     8140.8 MWIPS (9.9 s, 4 samples)
Execl Throughput                               6401.3 lps   (29.6 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1069771.9 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          298022.9 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       3196602.2 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1927648.8 lps   (10.0 s, 4 samples)
Pipe-based Context Switching                 333996.5 lps   (10.0 s, 4 samples)
Process Creation                              22620.8 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   9724.3 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1386.3 lpm   (60.0 s, 2 samples)
System Call Overhead                        2071274.1 lps   (10.0 s, 4 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   43282979.7   3708.9
Double-Precision Whetstone                       55.0       8140.8   1480.1
Execl Throughput                                 43.0       6401.3   1488.7
File Copy 1024 bufsize 2000 maxblocks          3960.0    1069771.9   2701.4
File Copy 256 bufsize 500 maxblocks            1655.0     298022.9   1800.7
File Copy 4096 bufsize 8000 maxblocks          5800.0    3196602.2   5511.4
Pipe Throughput                               12440.0    1927648.8   1549.6
Pipe-based Context Switching                   4000.0     333996.5    835.0
Process Creation                                126.0      22620.8   1795.3
Shell Scripts (1 concurrent)                     42.4       9724.3   2293.5
Shell Scripts (8 concurrent)                      6.0       1386.3   2310.5
System Call Overhead                          15000.0    2071274.1   1380.8
                                                                   ========
System Benchmarks Index Score                                        1984.2

EFSとS3(s3fs)とS3(goofy)の比較を試す

かなり改めてのなのですがS3マウントさせて利用しているフォルダをEFSへ変更する事情があったので性能比較してみるかとやってみました。

なんだかんだで「s3fs」と「goofy」の比較もついでにしました。

今回は環境構築手順については割愛。

検証条件

リージョン:東京

インスタンスタイプ:M5a.large

EC2からEFS/S3(s3fs)/s3(goofys)をマウント。S3は同一バケットをマウントしている。

EFS/S3ともに暗号化あり

s3fs version : 1.85

goofys version :

検証方法

マウントポジションに対して「fio」「dd」コマンドでの計測と複数個のファイル作成とファイル表示の時間を計測

結果

「fio」コマンド

  1. EFSの場合
# fio --directory=/mnt/efs --name fio_test_file --direct=1 --rw=randread --bs=4k --size=1G --numjobs=4 --time_based --runtime=180 --group_reporting --norandommap
fio_test_file: (g=0): rw=randread, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
...
fio-2.14
Starting 4 processes
fio_test_file: Laying out IO file(s) (1 file(s) / 1024MB)
fio_test_file: Laying out IO file(s) (1 file(s) / 1024MB)
fio_test_file: Laying out IO file(s) (1 file(s) / 1024MB)
fio_test_file: Laying out IO file(s) (1 file(s) / 1024MB)
Jobs: 4 (f=4): [r(4)] [100.0% done] [4376KB/0KB/0KB /s] [1094/0/0 iops] [eta 00m:00s]
fio_test_file: (groupid=0, jobs=4): err= 0: pid=2891: Mon Mar 18 05:58:47 2019
  read : io=778452KB, bw=4324.7KB/s, iops=1081, runt=180005msec
    clat (msec): min=1, max=154, avg= 3.70, stdev= 1.59
     lat (msec): min=1, max=154, avg= 3.70, stdev= 1.59
    clat percentiles (usec):
     |  1.00th=[ 2192],  5.00th=[ 2352], 10.00th=[ 2480], 20.00th=[ 2672],
     | 30.00th=[ 2896], 40.00th=[ 3088], 50.00th=[ 3280], 60.00th=[ 3536],
     | 70.00th=[ 4640], 80.00th=[ 4832], 90.00th=[ 5024], 95.00th=[ 5216],
     | 99.00th=[ 6496], 99.50th=[ 8256], 99.90th=[17280], 99.95th=[27776],
     | 99.99th=[52480]
    lat (msec) : 2=0.02%, 4=63.97%, 10=35.69%, 20=0.24%, 50=0.07%
    lat (msec) : 100=0.01%, 250=0.01%
  cpu          : usr=0.23%, sys=0.39%, ctx=194650, majf=0, minf=39
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=194613/w=0/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=778452KB, aggrb=4324KB/s, minb=4324KB/s, maxb=4324KB/s, mint=180005msec, maxt=180005msec

2 . S3(s3fs)の場合

エラーで計測できず(S3に対してはできない様子)

3 . S3(goofys)の場合

エラーで計測できず(S3に対してはできない様子)

「dd」コマンド

# dd if=/dev/zero of=ddtest bs=1M count=1000

マウントポジションへ移動して実行

1 . EFSの場合

1048576000 bytes (1.0 GB) copied, 9.32339 s, 112 MB/s

2 . S3(s3fs)の場合

1048576000 bytes (1.0 GB) copied, 15.1685 s, 69.1 MB/s

3 . S3(goofys)の場合

1048576000 bytes (1.0 GB) copied, 7.03157 s, 149 MB/s

ファイル作成

# i=1; time while [ $i -le 500 ]
> do
> touch goofy_test_$i > /dev/null 2>&1
> i=$((i+1))
> done

マウントポジションへ移動して実行

1 . EFSの場合

real    0m7.806s
user    0m0.303s
sys     0m0.082s

2 . S3(s3fs)の場合

real    1m47.808s
user    0m0.338s
sys     0m0.082s

3 . S3(goofys)の場合

real    0m34.765s
user    0m0.348s
sys     0m0.078s

ファイル一覧表示

time ls -laR /path/to/mount > /dev/null

1 . EFSの場合

real    0m0.071s
user    0m0.003s
sys     0m0.003s

2 . S3(s3fs)の場合

real    0m0.707s
user    0m0.019s

3 . S3(goofys)の場合

real    0m1.073s
user    0m0.028s
sys     0m0.061s

まとめ

アバウトな検証ですけどざっくりと知るぶんには十分でしょうか。

goofysはやはりはやいですがs3fsも読み取り速度あがったんですかね?こんなに早かったイメージないんですが。。

でもEFSが東京リージョンで利用できる今、S3をマウントさせてまで使う必要性はないかな。

マネージドサービスですし、なにより導入が簡単です。なんだかんだでS3使うにはインストールに必要なモジュールが多いです。 EFSならユーティリティーツールで一発です。

もうちょっと踏み込んでやるならログをEFSに吐き出して書き込めきれるかとかスクリプト置いて読み込めるかとか画像とかとかやるべきでしょう。I/O的にはそこそこ大丈夫なきもしますが。

とりあえずはこのくらいで。

wordpressから移行しました

AWS環境にwordpress立ててドメイン取ってみたいなことで数ヶ月立ち上げてたんですがこの度はてなに移行しました。

理由は以下

  1. Wordpressいじるのが手間
  2. AWS環境で作る必要性がない(機能的に面白みがない)
  3. 楽したい

月々500円くらい出費してたのが無くなるのでおやつ増えます。