概要
ハードディスクの簡易ベンチマークとして、hdparmコマンドを使う方法を紹介します。hdparmコマンドはハードディスクのパラメータを設定・取得するコマンドですが、-tオプション・-Tオプションを指定することで、シーケンシャルアクセスの読み込み速度を測定することができます。
ドライブ識別情報の表示
-I Request identification info directly from the drive, which is displayed in
a new expanded format with considerably more detail than with the older -i
flag.
直接、ドライブに識別情報を要求します。古い-iフラグに比べるとかなり詳細な、新しい拡張されたフォーマットを表示します。
# hdparm -I /dev/hda2
/dev/hda2:
ATA device, with non-removable media
Model Number: QEMU HARDDISK
Serial Number: QM00001
Firmware Revision: 0.12.3
Standards:
Used: ATA/ATAPI-5 published, ANSI INCITS 340-2000
Supported: 7 6 5 4 & some of 6
Configuration:
Logical max current
cylinders 16383 16383
heads 16 16
sectors/track 63 63
--
CHS current addressable sectors: 16514064
LBA user addressable sectors: 41943040
LBA48 user addressable sectors: 41943040
device size with M = 1024*1024: 20480 MBytes
device size with M = 1000*1000: 21474 MBytes (21 GB)
Capabilities:
LBA, IORDY(cannot be disabled)
Standby timer values: spec'd by Vendor
R/W multiple sector transfer: Max = 16 Current = 16
DMA: sdma0 sdma1 sdma2 mdma0 mdma1 *mdma2 udma0 udma1 udma2 udma3 udma4 udma5
Cycle time: min=120ns recommended=120ns
PIO: pio0 pio1 pio2
Cycle time: no flow control=120ns IORDY flow control=120ns
Commands/features:
Enabled Supported:
* SMART feature set
* NOP cmd
* 48-bit Address feature set
* Mandatory FLUSH_CACHE
* FLUSH_CACHE_EXT
HW reset results:
CBLID- above Vih
Device num = 0
デバイス読み込み速度の測定
-t Perform timings of device reads for benchmark and comparison purposes.
For meaningful results, this operation should be repeated 2-3 times on an
otherwise inactive system (no other active processes) with at least a cou-
ple of megabytes of free memory. This displays the speed of reading
through the buffer cache to the disk without any prior caching of data.
This measurement is an indication of how fast the drive can sustain
sequential data reads under Linux, without any filesystem overhead. To
ensure accurate measurements, the buffer cache is flushed during the pro-
cessing of -t using the BLKFLSBUF ioctl. If the -T flag is also speci-
fied, then a correction factor based on the outcome of -T will be incorpo-
rated into the result reported for the -t operation.
ベンチマーク及び比較目的で、デバイス読み込み速度を測定します。有意な結果を得るためには、少なくとも数メガバイトの空きメモリがあり、他にアクティブなプロセスがない状態で、この操作を2〜3回繰り返してください。この操作はデータが事前にキャッシュされていない状態から、バッファキャッシュを通してディスクを読み出す速度を表示します。この測定は、ファイルシステムのオーバーヘッドなしに、そのドライブがLinuxでどれだけシーケンシャルアクセスの読み込み速度を維持できるかを示します。より正確に測定をするためには、-tの実行の間にBLKFLSBUF ioctlを使ってバッファキャッシュをクリアします。-Tフラグが同時に指定された場合、-Tの結果を元にした補正係数が-tの結果に加味されます。
# hdparm -t /dev/hda2
/dev/hda2:
Timing buffered disk reads: 916 MB in 3.00 seconds = 304.92 MB/sec
キャッシュ読み込み速度の測定
-T Perform timings of cache reads for benchmark and comparison purposes. For
meaningful results, this operation should be repeated 2-3 times on an oth-
erwise inactive system (no other active processes) with at least a couple
of megabytes of free memory. This displays the speed of reading directly
from the Linux buffer cache without disk access. This measurement is
essentially an indication of the throughput of the processor, cache, and
memory of the system under test. If the -t flag is also specified, then a
correction factor based on the outcome of -T will be incorporated into the
result reported for the -t operation.
ベンチマーク及び比較目的で、キャッシュ読み込み速度を測定します。有意な結果を得るためには、少なくとも数メガバイトの空きメモリがあり、他にアクティブなプロセスがない状態で、この操作を2〜3回繰り返してください。この操作はディスクアクセスなしに、直接Linuxのバッファキャッシュから読み出す速度を表示します。この測定は、システムユーザーテスト環境でのプロセッサ・キャッシュ・メモリの基本的な処理能力を示します。-tフラグが同時に指定された場合、-Tの結果を元にした補正係数が-tの結果に加味されます。
# hdparm -T /dev/hda2
/dev/hda2:
Timing cached reads: 17404 MB in 2.00 seconds = 8709.20 MB/sec
デバイス読み込み速度の測定
12回測定し、最小値と最大値を除いた10回分の平均値を求めます。
FILE: /root/bin/benchmark_sequential_read
#!/bin/bash
if [ -z $1 ]
then
echo "Usage: `basename $0` FILESYSTEM" 1>&2
exit 1
fi
# It measures 12 times and displays a result.
for i in 0 1 2 3 4 5 6 7 8 9 10 11
do
sleep 10
_lines[$i]=`hdparm -t $1`
echo [$i] ${_lines[$i]}
_speeds1[$i]=`echo ${_lines[$i]} | cut -d' ' -f12`
done
# A result is rearranged into an ascending order.
IFS=$'\n'
_speeds1=(`echo "${_speeds1[*]}" | sort`)
# The minimum and the maximum are excepted and average value is calculated.
_sum=0
for i in 1 2 3 4 5 6 7 8 9 10
do
_speeds2[$i]=${_speeds1[$i]}
done
_avg=`echo "${_speeds2[*]}" | awk '{s+=$1}END{print s/10}'`
# Average value is displayed.
echo "AVG $_avg MB/sec"
/dev/hda2のデバイス読み込み速度を測定します。引数に測定したいデバイスを指定してください。
# benchmark_sequential_read /dev/hda2
[0] /dev/hda2: Timing buffered disk reads: 668 MB in 3.00 seconds = 222.60 MB/sec
[1] /dev/hda2: Timing buffered disk reads: 996 MB in 3.00 seconds = 331.50 MB/sec
[2] /dev/hda2: Timing buffered disk reads: 1082 MB in 3.00 seconds = 360.57 MB/sec
[3] /dev/hda2: Timing buffered disk reads: 1150 MB in 3.00 seconds = 383.24 MB/sec
[4] /dev/hda2: Timing buffered disk reads: 1164 MB in 3.00 seconds = 387.78 MB/sec
[5] /dev/hda2: Timing buffered disk reads: 1106 MB in 3.00 seconds = 368.12 MB/sec
[6] /dev/hda2: Timing buffered disk reads: 1114 MB in 3.00 seconds = 371.05 MB/sec
[7] /dev/hda2: Timing buffered disk reads: 1136 MB in 3.00 seconds = 378.64 MB/sec
[8] /dev/hda2: Timing buffered disk reads: 1120 MB in 3.00 seconds = 372.83 MB/sec
[9] /dev/hda2: Timing buffered disk reads: 1116 MB in 3.00 seconds = 371.81 MB/sec
[10] /dev/hda2: Timing buffered disk reads: 986 MB in 3.00 seconds = 328.61 MB/sec
[11] /dev/hda2: Timing buffered disk reads: 1096 MB in 3.00 seconds = 364.98 MB/sec
AVG 363.135 MB/sec
キャッシュ読み込み速度の測定
12回測定し、最小値と最大値を除いた10回分の平均値を求めます。
FILE: /root/bin/benchmark_cache_read
#!/bin/bash
if [ -z $1 ]
then
echo "Usage: `basename $0` FILESYSTEM" 1>&2
exit 1
fi
# It measures 12 times and displays a result.
for i in 0 1 2 3 4 5 6 7 8 9 10 11
do
sleep 10
_lines[$i]=`hdparm -T $1`
echo [$i] ${_lines[$i]}
_speeds1[$i]=`echo ${_lines[$i]} | cut -d' ' -f11`
done
# A result is rearranged into an ascending order.
IFS=$'\n'
_speeds1=(`echo "${_speeds1[*]}" | sort`)
# The minimum and the maximum are excepted and average value is calculated.
_sum=0
for i in 1 2 3 4 5 6 7 8 9 10
do
_speeds2[$i]=${_speeds1[$i]}
done
_avg=`echo "${_speeds2[*]}" | awk '{s+=$1}END{print s/10}'`
# Average value is displayed.
echo "AVG $_avg MB/sec"
/dev/hda2のキャッシュ読み込み速度を測定します。引数に測定したいデバイスを指定してください。
# benchmark_cache_read /dev/hda2
[0] /dev/hda2: Timing cached reads: 15880 MB in 2.00 seconds = 7945.72 MB/sec
[1] /dev/hda2: Timing cached reads: 16304 MB in 2.00 seconds = 8158.65 MB/sec
[2] /dev/hda2: Timing cached reads: 16788 MB in 2.00 seconds = 8401.84 MB/sec
[3] /dev/hda2: Timing cached reads: 15532 MB in 2.00 seconds = 7772.83 MB/sec
[4] /dev/hda2: Timing cached reads: 16364 MB in 2.00 seconds = 8188.12 MB/sec
[5] /dev/hda2: Timing cached reads: 17104 MB in 2.00 seconds = 8559.26 MB/sec
[6] /dev/hda2: Timing cached reads: 16368 MB in 2.00 seconds = 8190.56 MB/sec
[7] /dev/hda2: Timing cached reads: 15972 MB in 2.00 seconds = 7992.65 MB/sec
[8] /dev/hda2: Timing cached reads: 16124 MB in 2.00 seconds = 8068.73 MB/sec
[9] /dev/hda2: Timing cached reads: 16364 MB in 2.00 seconds = 8188.59 MB/sec
[10] /dev/hda2: Timing cached reads: 15544 MB in 2.00 seconds = 7778.54 MB/sec
[11] /dev/hda2: Timing cached reads: 16372 MB in 2.00 seconds = 8192.00 MB/sec
AVG 8110.54 MB/sec