LoginSignup
3
6

More than 1 year has passed since last update.

stress-ngコマンドでCPU、メモリ、ディスクに負荷をかける

Last updated at Posted at 2021-06-09

概要

stress-ngコマンドで負荷検証をするための簡単な使い方。

環境

  • CentOS 7.8
  • stress-ng 0.07.29

Installation

$ sudo yum -y install epel-release
$ sudo yum -y install --enablerepo=epel stress-ng
$ stress-ng -V
stress-ng, version 0.07.29

CPU

-c は起動するプロセスの数。

CPU使用率100%

$ stress-ng -c 1

CPU使用率50%

$ stress-ng -c 1 -l 50

メモリ

10秒間にメモリを1GB使用。
-m は起動するプロセスの数。

$ stress-ng -m 1 --vm-bytes 1G --timeout 10

ディスク

ディスクを2GB使用する

$ stress-ng -d 1 --hdd-bytes 2G

書き込み速度を測る

ダミーファイルを作成して、書き込み速度を測る方法。計測する度にサーバーのキャッシュクリアを行う。

/dev/zeroを使う。

# 10Gのダミーをファイル作成(1MiB*10000)
time dd if=/dev/zero of=zero.txt bs=1MiB count=10000; time sync
# 1Gのダミーをファイル作成(1MiB*1000)
time dd if=/dev/zero of=zero.txt bs=1MiB count=1000; time sync
# 1Mのダミーをファイル作成(1MiB*1)
time dd if=/dev/zero of=zero.txt bs=1MiB count=1; time sync
# 4kのダミーをファイル作成(4KiB *1)
time dd if=/dev/zero of=zero.txt bs=4KiB count=1; time sync
実行例
$ time dd if=/dev/zero of=zero.txt bs=4KiB count=1; time sync
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 0.000268956 s, 15.2 MB/s

real    0m0.003s
user    0m0.000s
sys 0m0.002s

real    0m0.007s
user    0m0.001s
sys 0m0.001s
表示 意味
real %e そのコマンドを実行するのにかかった時間
user %U そのコマンドを実行するのに使用したユーザーCPU時間
sys %S そのコマンドを実行するのに使用したシステムCPU時間

読み込み速度を計測

書き込み速度の計測で出力したファイルを読み込む。

$ time dd if=zero.txt of=/dev/null

参考

3
6
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
3
6