Skip to content

Instantly share code, notes, and snippets.

@unchama
Last active December 30, 2024 05:26
Show Gist options
  • Save unchama/8b28826b2ec889ef279c4d12e95133a0 to your computer and use it in GitHub Desktop.
Save unchama/8b28826b2ec889ef279c4d12e95133a0 to your computer and use it in GitHub Desktop.
起動した瞬間から全力負荷テストするsystemd-unit-fileたち
[Unit]
Description=fio--read-rand4k
After=network-online.target
[Service]
User=root
Group=root
TimeoutStopSec=20
WorkingDirectory=/tmp
ExecStart=/bin/sh -c "fio --name=test --filename=/root/fio-test-file--read-rand4k --size=2g --ioengine=libaio --direct=1 --rw=randread --bs=4k --iodepth=32 --time_based --runtime=600"
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=fio--read-seq
After=network-online.target
[Service]
User=root
Group=root
TimeoutStopSec=20
WorkingDirectory=/tmp
ExecStart=/bin/sh -c "fio --name=test --filename=/root/fio-test-file --size=2g --ioengine=libaio --direct=1 --rw=read --bs=1M --iodepth=1 --time_based --runtime=600"
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=fio--write-rand4k
After=network-online.target
[Service]
User=root
Group=root
TimeoutStopSec=20
WorkingDirectory=/tmp
ExecStart=/bin/sh -c "fio --name=test --filename=/root/fio-test-file-write-rand4k --size=2g --ioengine=libaio --direct=1 --rw=randwrite --bs=4k --iodepth=32 --time_based --runtime=600 --refill_buffers"
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=fio--write-seq
After=network-online.target
[Service]
User=root
Group=root
TimeoutStopSec=20
WorkingDirectory=/tmp
ExecStart=/bin/sh -c "fio --name=test --filename=/root/fio-test-file-write --size=2g --ioengine=libaio --direct=1 --rw=write --bs=1M --iodepth=1 --time_based --runtime=600 --refill_buffers"
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=stress-ng--matrix
After=network-online.target
[Service]
User=root
Group=root
TimeoutStopSec=20
WorkingDirectory=/tmp
ExecStart=/bin/sh -c "stress-ng --matrix $(cat /proc/cpuinfo | grep -c '^processor') --timeout 0 --metrics"
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=stress-ng--vm
After=network-online.target
[Service]
User=root
Group=root
TimeoutStopSec=20
WorkingDirectory=/tmp
ExecStart=/bin/sh -c "stress-ng --vm $(cat /proc/cpuinfo | grep -c '^processor') --vm-bytes 95% --timeout 0 --metrics"
Restart=always
[Install]
WantedBy=multi-user.target

stress-ng--matrix.service

  • CPU負荷超大(常時張り付く)
  • メモリ負荷無
  • IO負荷無

stress-ng--vm.service

  • CPU負荷大(ほぼ常時張り付くがたまに息継ぎする)
  • メモリ負荷大(mapとunmapを大量に行う)
  • IO負荷小(Read IOが数百KB/s流れたり流れなかったり。Write IOはほぼない)

fio--read-seq.service

  • CPU負荷無
  • メモリ負荷無
  • IO負荷大(Seq Read IO大量)

fio--write-seq.service

  • CPU負荷無
  • メモリ負荷無
  • IO負荷大(Seq Write IO大量)
  • SSDにやる場合は書き込み寿命が急速に減るのでCGroupでIO制限をかけるかVMならハイパーバイザーのレイヤーでIO制限をかけるかしたほうがよい

cgroupでのIO制限のかけ方

unitfile の Service ディレクティブ内に記載すればおk。 編集後 systemctl daemon-reload と対象unitのrestartで適用される。

# Write I/O制限の設定(例: 1MB/s)
IOWriteBandwidthMax=/path/to/disk 1M

# Read IOPS制限の設定(例: 100IOPS)
IOWriteIOPSMax=/path/to/disk 100

# 全てのディスクに対してWrite I/O制限を設定(例: 1MB/s)
IOWriteBandwidthMax=/ 1M

# Read I/O制限の設定(例: 1MB/s)
IOReadBandwidthMax=/path/to/disk 1M

# Read IOPS制限の設定(例: 100IOPS)
IOReadIOPSMax=/path/to/disk 100

# 全てのディスクに対してRead I/O制限を設定(例: 1MB/s)
IOReadBandwidthMax=/ 1M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment