1
0

More than 1 year has passed since last update.

[AWS_27]EC2に負荷をかけてAutoScalingを試験する

Last updated at Posted at 2022-02-06

環境

Amazon Web Service

  • EC2(Amazon Linux 2 , t2.micro , 汎用SSD 8GB)
  • RDS(MySQL , db.t2.micro)
  • ALB

ローカルPC

  • MacBook Pro(2.9 GHz デュアルコアIntel Core i5 , 8 GB 2133 MHz LPDDR3)
  • macOS 11.3.1(20E241)

概要

EC2に擬似的に負荷をかけて、AutoScalingによってEC2インスタンスが増減するか障害試験を実施する。

障害試験

  • 1台のEC2インスタンスにブラウザからSSH接続する。
    実行中WebServer-Autoをクリックし、接続 > 接続をクリックする。

  • CPU使用率[%Cpu(s): xx us]を確認する。
    ctrl + Cで抜けられる。
[root@ip-xx-xx-xx-xx ~]# top
top - 08:54:15 up  4:35,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  99 total,   1 running,  62 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.0 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1006896 total,   291372 free,   226232 used,   489292 buff/cache
KiB Swap:        0 total,        0 free,        0 used.   636560 avail Mem



* 負荷をかけるコマンド

yes > /dev/null &
コマンド 意味
yes yを無限に出力し続ける
> ファイルへの上書き
>> ファイルへの追記(これでも良い)
/dev/null nullというファイル名
& バックグラウンドで実行



  • topコマンドでCPU使用率を確認。→99%
[root@ip-xx-xx-xx-xx ~]# top
top - 09:13:08 up  4:54,  1 user,  load average: 0.67, 0.22, 0.08
Tasks: 100 total,   2 running,  62 sleeping,   0 stopped,   0 zombie
%Cpu(s): 99.0 us,  1.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1006896 total,   290412 free,   226924 used,   489560 buff/cache
KiB Swap:        0 total,        0 free,        0 used.   635852 avail Mem 



  • 同様にもう一台のEC2インスタンスでも負荷をかける。

  • CloudWatchで、CPU使用率を確認する。
    CloudWatch > メトリクス > AutoScaling グループ別 > CPU Utilizationをクリックする。 (→平均が表示されるので、100%程度になっているはず。
  • 5分ほどで1台ずつ自動追加されるので、合計で4台になるまで待つ。

  • EC2インスタンスで負荷をかけるのを2台とも止める topコマンドで表示されるプロセスのうち、yesコマンドによるプロセスのプロセス番号を以下コマンドで止める。
kill xxxx




*5分ほどで1台ずつ自動削除されるので、合計2台になるまで待つ。

確認

  • CloudWatch > メトリクス > AutoScaling グループ別 > CPU UtilizationをクリックしてCPU使用率のグラフを確認する。。

時系列

時間 CPU利用率[%] EC2インスタンス
9:15 99.8 2台に負荷をかけた。実行中=2台。
9:20 66.6 実行中=2台。
9:25 56.4 18:23に1台自動追加。実行中=3台。
9:30 50.0 18:29に1台自動追加。実行中=4台。
9:35 33.5 2台の負荷を停止。
9:40 33.4 18:38に1台自動削除。実行中=3台。
9:45 0.3 18:44に1台自動削除。実行中=2台。

スクリーンショット 2021-05-27 11.40.37.png

  • EC2 > Auto Scaling グループ > Test-AutoScaling1 > アクティビティタブをクリックして、ログを確認。
ステータス 説明 原因
Successful Launching a new EC2 instance: i-xxxxxxxxxxxxxx At 2021-05-26T09:23:00Z a monitor alarm CPU_High in state ALARM triggered policy CPU_add changing the desired capacity from 2 to 3. At 2021-05-26T09:23:08Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 2 to 3.
Successful Launching a new EC2 instance: i-xxxxxxxxxxxxxx At 2021-05-26T09:29:00Z a monitor alarm CPU_High in state ALARM triggered policy CPU_add changing the desired capacity from 3 to 4. At 2021-05-26T09:29:10Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 3 to 4.
Successful Terminating EC2 instance: i-xxxxxxxxxxxxxx At 2021-05-26T09:38:47Z a monitor alarm CPU_Low in state ALARM triggered policy CPU_remove changing the desired capacity from 4 to 3. At 2021-05-26T09:38:51Z an instance was taken out of service in response to a difference between desired and actual capacity, shrinking the capacity from 4 to 3. At 2021-05-26T09:38:52Z instance i-xxxxxxxxxxxxxx was selected for termination.
Successful Terminating EC2 instance: i-xxxxxxxxxxxxxx At 2021-05-26T09:44:47Z a monitor alarm CPU_Low in state ALARM triggered policy CPU_remove changing the desired capacity from 3 to 2. At 2021-05-26T09:44:53Z an instance was taken out of service in response to a difference between desired and actual capacity, shrinking the capacity from 3 to 2. At 2021-05-26T09:44:53Z instance i-xxxxxxxxxxxxxx was selected for termination.
1
0
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
1
0