負荷計測ツール

ps

root@akat:/home/akat# ps afxu
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
# %CPU:CPU使用率
# %MEM:物理メモリ使用率
# VSZ:仮想メモリサイズ
# RSS:物理メモリサイズ
# TIME:CPU利用時間
root         2  0.0  0.0      0     0 ?        S    Mar09   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Mar09   0:16  \_ [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Mar09   0:00  \_ [kworker/u:0]
root         6  0.0  0.0      0     0 ?        S    Mar09   0:02  \_ [migration/0]
root         7  0.0  0.0      0     0 ?        S    Mar09   0:15  \_ [watchdog/0]
root         8  0.0  0.0      0     0 ?        S    Mar09   0:01  \_ [migration/1]
root        10  0.0  0.0      0     0 ?        S    Mar09   0:08  \_ [ksoftirqd/1]
root        12  0.0  0.0      0     0 ?        S    Mar09   0:15  \_ [watchdog/1]
root        13  0.0  0.0      0     0 ?        S<   Mar09   0:00  \_ [cpuset]
root        14  0.0  0.0      0     0 ?        S<   Mar09   0:00  \_ [khelper]
root        15  0.0  0.0      0     0 ?        S    Mar09   0:00  \_ [kdevtmpfs]
root        16  0.0  0.0      0     0 ?        S<   Mar09   0:00  \_ [netns]
root        17  0.0  0.0      0     0 ?        S    Mar09   0:03  \_ [kworker/u:1]
root        18  0.0  0.0      0     0 ?        S    Mar09   0:14  \_ [sync_supers]
root        19  0.0  0.0      0     0 ?        S    Mar09   0:00  \_ [bdi-default]
root        20  0.0  0.0      0     0 ?        S<   Mar09   0:00  \_ [kintegrityd]
root        21  0.0  0.0      0     0 ?        S<   Mar09   0:00  \_ [kblockd]
root        22  0.0  0.0      0     0 ?        S<   Mar09   0:00  \_ [ata_sff]
root        23  0.0  0.0      0     0 ?        S    Mar09   0:00  \_ [khubd]
root        24  0.0  0.0      0     0 ?        S<   Mar09   0:00  \_ [md]
root        26  0.0  0.0      0     0 ?        S    Mar09   0:01  \_ [khungtaskd]
root        27  0.0  0.0      0     0 ?        S    Mar09   0:06  \_ [kswapd0]
root        28  0.0  0.0      0     0 ?        SN   Mar09   0:00  \_ [ksmd]
root        29  0.0  0.0      0     0 ?        SN   Mar09   0:00  \_ [khugepaged]
root        30  0.0  0.0      0     0 ?        S    Mar09   0:00  \_ [fsnotify_mark]

root@akat:/home/akat# ps aux -L 
USER       PID   LWP %CPU NLWP %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1     1  0.0    1  0.0  10648   688 ?        Ss    5月09   1:52 init [2]
root         2     2  0.0    1  0.0      0     0 ?        S     5月09   0:00 [kthreadd]
root         3     3  0.0    1  0.0      0     0 ?        S     5月09   5:49 [ksoftirqd/0]
root         5     5  0.0    1  0.0      0     0 ?        S     5月09   0:00 [kworker/u:0]
root         6     6  0.0    1  0.0      0     0 ?        S     5月09   0:01 [migration/0]
root     24378 24378  0.0    1  0.1  11848  1524 ?        S     6月30   0:00 /bin/bash /usr/bin/mysqld_safe
mysql    24592 24592  0.0   26  9.2 935680 95016 ?        Sl    6月30   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/w
ww27032ue.err --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
mysql    24592 24594  0.0   26  9.2 935680 95016 ?        Sl    6月30   5:10 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/w
ww27032ue.err --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
mysql    24592 24595  0.0   26  9.2 935680 95016 ?        Sl    6月30   4:56 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/w
ww27032ue.err --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
mysql    24592 24596  0.0   26  9.2 935680 95016 ?        Sl    6月30   4:47 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/w
ww27032ue.err --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
mysql    24592 24597  0.0   26  9.2 935680 95016 ?        Sl    6月30   5:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/w
ww27032ue.err --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
mysql    24592 24598  0.0   26  9.2 935680 95016 ?        Sl    6月30   4:51 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/w
ww27032ue.err --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306

root@akat:/home/akat# ps -elf -L
# PID:プロセスID
# LWP:軽量プロセス(スレッド)
# NLWP(Number of LWPs):スレッド本数
# TIME:CPU使用時間
F S UID        PID  PPID   LWP  C NLWP PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
4 S root         1     0     1  0    1  80   0 -  2661 -       2013 ?        00:03:08 init [2]
1 S root         2     0     2  0    1  80   0 -     0 -       2013 ?        00:00:00 [kthreadd]
1 S root         3     2     3  0    1  80   0 -     0 -       2013 ?        00:06:30 [ksoftirqd/0]
1 S root         5     2     5  0    1  80   0 -     0 -       2013 ?        00:00:00 [kworker/u:0]
1 S root         6     2     6  0    1 -40   - -     0 -       2013 ?        00:00:01 [migration/0]
5 S root         7     2     7  0    1 -40   - -     0 -       2013 ?        00:01:05 [watchdog/0]
1 S root         8     2     8  0    1 -40   - -     0 -       2013 ?        00:00:01 [migration/1]
4 S mongodb   1531     1  1531  0    9  80   0 - 133798 -      2月16 ?      01:20:26 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb
1 S mongodb   1531     1  1533  0    9  80   0 - 133798 -      2月16 ?      00:00:00 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb
1 S mongodb   1531     1  1534  0    9  80   0 - 133798 -      2月16 ?      00:00:07 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb
1 S mongodb   1531     1  1535  0    9  80   0 - 133798 -      2月16 ?      00:00:00 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb
1 S mongodb   1531     1  1536  0    9  80   0 - 133798 -      2月16 ?      00:43:25 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb
1 S mongodb   1531     1  1537  0    9  80   0 - 133798 -      2月16 ?      00:00:21 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb
1 S mongodb   1531     1  1538  0    9  80   0 - 133798 -      2月16 ?      00:00:29 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb
1 S mongodb   1531     1  1539  0    9  80   0 - 133798 -      2月16 ?      00:00:01 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb
1 S mongodb   1531     1  1540  0    9  80   0 - 133798 -      2月16 ?      01:15:33 /usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb

dstat

root@hostname:/home/shimizu# aptitude install dstat
root@hostname:/home/shimizu# dstat -Tclmdrns # CPUやメモリ、ディスク情報を一箇所で確認可能
--epoch--- ----total-cpu-usage---- ---load-avg--- ------memory-usage----- -dsk/total- --io/total- -net/total- ----swap---
  epoch   |usr sys idl wai hiq siq| 1m   5m  15m | used  buff  cach  free| read  writ| read  writ| recv  send| used  free
1406543963|  0   0 100   0   0   0|   0 0.01 0.05| 194M 13.6M  212M  583M|1160B 5067B|0.08  0.38 |   0     0 | 130M 1752M
1406543964|  0   0 100   0   0   0|   0 0.01 0.05| 194M 13.6M  212M  583M|   0     0 |   0     0 |1042B  106B| 130M 1752M
1406543967|  0   0  99   0   0   0|   0 0.01 0.05| 194M 13.6M  212M  583M|   0     0 |   0     0 |1162B  506B| 130M 1752M
1406543968|  0   1 100   0   0   0|   0 0.01 0.05| 194M 13.6M  212M  583M|   0     0 |   0     0 |1162B  506B| 130M 1752M

root@hostname:/home/shimizu# dstat --output output.csv -Tclmdrns # CSV出力も可能
--epoch--- ----total-cpu-usage---- ---load-avg--- ------memory-usage----- -dsk/total- --io/total- -net/total- ----swap---
  epoch   |usr sys idl wai hiq siq| 1m   5m  15m | used  buff  cach  free| read  writ| read  writ| recv  send| used  free
1406544001|  0   0 100   0   0   0|   0 0.01 0.05| 194M 13.6M  212M  583M|1160B 5067B|0.08  0.38 |   0     0 | 130M 1752M
1406544002|  0   0 100   0   0   0|   0 0.01 0.05| 194M 13.6M  212M  583M|   0     0 |   0     0 |1504B  106B| 130M 1752M
1406544003|  0   0 100   0   0   0|   0 0.01 0.05| 194M 13.6M  212M  583M|   0     0 |   0     0 |1162B 1290B| 130M 1752M

root@hostname:/home/shimizu# which mysql # mysqlコマンドが/usr/bin/mysqlにないとダメらしい
/usr/bin/mysql
root@hostname:/home/shimizu# export DSTAT_MYSQL='-uroot -pTc90lm9drn -h127.0.0.1'
root@hostname:/home/shimizu# env | grep "DSTAT_MYSQL"
DSTAT_MYSQL=-uroot -pTc90lm9drn -h127.0.0.1
root@hostname:/home/shimizu# dstat -T --innodb-io --innodb-buffer --innodb-ops # innodb情報を表示
--epoch--- innodb-io-o innodb-pool ---innodb-ops--
  epoch   |rea wri syn|crt rea wri|ins upd del rea
1406542570|  0   0   0|  0 0.0 0.0|  0   0   0   0
1406542571|  0   0   0|  0   0   0|  0   0   0   0
1406542572|  0   0   0|  0   0   0|  0   0   0   0
1406542573|  0   0   0|  0   0   0|  0   0   0   0
1406542574|  0   0   0|  0   0   0|  0   0   0   0
1406542575|  0   0   0|  0   0   0|  0   0   0   0
# ---innodb-ops-- : show innodb operations counters
# --innodb-io : show innodb I/O stats
# --innodb-buffer : show innodb buffer stats

root@hostname:/home/shimizu# aptitude install python-mysqldb
root@hostname:/home/shimizu# export DSTAT_MYSQL_USER=root
root@hostname:/home/shimizu# export DSTAT_MYSQL_PWD=Tc90lm9drn
root@hostname:/home/shimizu# export DSTAT_MYSQL_HOST='127.0.0.1'
root@hostname:/home/shimizu# dstat -T --mysql5-cmds --mysql5-io --mysql5-keys # mysql5情報表示
--epoch--- ------mysql5-cmds------ -mysql5-io- ---mysql5-key-status----
  epoch   | sel   ins   upd   del | recv  sent|used read writ rreq wreq
1406543060|    0     0     0     0|0.00  0.02 |  0    0    0    0    0
1406543061|   70     0     0     0|13.9k  143k|  0    0    0    0    0
1406543062|   70     0     0     0|14.1k  144k|  0    0    0    0    0
1406543063|   70     0     0     0|14.3k  145k|  0    0    0    0    0

htop

topコマンドの機能強化版

root@hostname:/home/admin# aptitude install htop strace
以下の新規パッケージがインストールされます:
  htop strace

htop実行結果
2014-09-05_010310

[F5]でツリー表示
2014-09-04_120357

[F6]でソート可能
2014-09-05_005613

[s]でstraceの表示
2014-09-05_010042

[k]でシグナルを送ることが可能
2014-09-05_010635

iftop

トラフィック量をリアルタイム監視するツール

root@hostname:/home/admin# aptitude install iftop
以下の新規パッケージがインストールされます:
  iftop
更新: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。

root@hostname:/home/admin#  iftop -i eth0
                              195kb                         391kb                         586kb                         781kb                     977kb
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
ip-172-31-3-201.ap-northeast-1.compute.internal               => 8.3.3.1.ap.yournet.ne.jp                                       26.1kb  11.0kb  4.10kb
                                                              <=                                                                3.77kb  1.64kb   808b
ip-172-31-3-201.ap-northeast-1.compute.internal               => 17.xrfuwuqi.com                                                   0b      0b   14.8kb
                                                              <=                                                                   0b      0b    939b
ip-172-31-3-201.ap-northeast-1.compute.internal               => akismet.com                                                       0b      0b   1.39kb
                                                              <=                                                                   0b      0b    119b
ip-172-31-3-201.ap-northeast-1.compute.internal               => ip-172-31-0-2.ap-northeast-1.compute.internal                     0b      0b     44b
                                                              <=                                                                   0b      0b     74b


qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
TX:             cum:    107kB   peak:    153kb                                                                         rates:   26.1kb  11.0kb  20.4kb
RX:                    11.0kB           15.5kb                                                                                  3.77kb  1.64kb  1.89kb
TOTAL:                  118kB            162kb                                                                                  29.8kb  12.7kb  22.3kb

### 使用例 ###
root@hostname:/home/admin# iftop -i eth0 -f "dst port 80" # HTTP通信だけのトラフィックを確認する
root@hostname:/home/admin# iftop -i eth0 -nPN # -n:ホスト名を解決しない、-P:ポート番号も表示、-N:ポート番号からサービス名へ変換しない

TX:トラフィックの送信量
RX:トラフィックの受信料
cum:iftopを起動してからのトラフィック総量(上り、下り別)
TOTAL:iftopを起動してからのトラフィック総量
peak:瞬間に発生したトラフィックの最大量
rates:平均値。左から最近の2秒、最近の10秒、最近の40秒のトラフィック量の平均値

free

root@hostname:/home/shimizu# free
total used free shared buffers cached
Mem: 8199468 8123924 75544 0 142620 2629156
-/+ buffers/cache: 5352148 2847320
Swap: 6538232 129024 6409208
# swapにはみ出していたとしても、それだけでは メモリ不足の証拠にはならない
# あまり使わないコ-ドを追い出して cache と buffre に転用するため
# swapを利用しているかどうかはvmstatなどで確認可能

sar

sysstatパッケージに付属しており、インストールするとsadcというプログラムが自動でカーネルからレポートを取得する

root@akat:/home/akat# sar -P ALL
平均値:      CPU     %user     %nice   %system   %iowait    %steal     %idle
平均値:      all      4.90      0.02      1.16      0.15      0.00     93.77
平均値:        0      7.36      0.04      1.42      0.25      0.00     90.93
平均値:        1      2.45      0.00      0.89      0.06      0.00     96.60

vmstat

root@akat:/home/akat# vmstat 1 5 # 1秒毎に5回
# io:bi ブロックデバイスから受け取ったブロック(blocks/s)
# io:bo ブロックデバイスに送られたブロック(blocks/s)
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0  41460 236444 117120 366144    0    0     1     4   12    6  2  1 98  0
 0  0  41460 236436 117120 366168    0    0     0     0   53   98  0  0 99  0
 0  0  41460 236436 117120 366168    0    0     0     0   51   89  0  0 100  0
 1  0  41460 215356 117120 366168    0    0     0     0  325  121 39 11 50  0
 1  0  41460 223076 117120 366168    0    0     0     0  351  197 41  8 51  0

root@hostname:/home/shimizu# tune2fs -l /dev/xvda | grep "Block size"
Block size: 4096
# ブロックサイズが4KB、つまりio=1だと4KB/s

root@hostname:/home/shimizu# aptitude install hdparm
root@hostname:/home/shimizu# hdparm -t /dev/xvda # -Tオプションだと、Linuxのディスクキャッシュを利用する

/dev/xvda:
 Timing buffered disk reads:  66 MB in  3.42 seconds =  19.30 MB/sec

# read速度はhdparmで計測でき、20MB/s可能であるため余裕であることがわかる

root@hostname2:/home/shimizu# vmstat -p /dev/sdb1 # パーティションを指定することも可能
sdb1          reads   read sectors  writes    requested writes
               13023    1079802       6993     837048

# reads: このパーティションに発行された読み込みの総数
# read sectors: このパーティションから読み込まれた総セクタ数
# writes : このパーティションに発行された書き出しの総数
# requested writes: このパーティションへの書き出し要求の総数

iotop

I/Oの状態をリアルタイムで確認できる

root@hostname:/home/admin# aptitude install iotop
root@hostname:/home/admin# iotop
Total DISK READ:       0.00 B/s | Total DISK WRITE:       0.00 B/s
  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND
13760 be/4 mysql       0.00 B/s   73.28 K/s  0.00 %  5.18 % mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/my~r/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
11201 be/3 www-data    3.86 K/s    0.00 B/s  0.00 %  1.86 % php-fpm: pool www
11200 be/3 www-data    3.86 K/s    0.00 B/s  0.00 %  1.62 % php-fpm: pool www
11242 be/4 www-data    0.00 B/s    7.71 K/s  0.00 %  0.00 % nginx: worker process
    1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % init [2]
    2 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthreadd]
    3 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/0]
    4 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/0:0]
    5 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/u:0]
    6 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/0]
    7 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [watchdog/0]
    8 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [cpuset]
    9 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [khelper]

表示中に←→でソート項目を選択可能
-o: ディスクI/Oを発生させたプロセスだけ表示
-b: ディスクI/Oを時系列に表示
-d: 表示する間隔(秒)。1秒未満の指定可能
-t: タイムスタンプと一緒にディスクI/Oを表示

iostat

どのディスクデバイスがボトルネックとなっているかを調査する

root@hostname:/home/shimizu# iostat 1 2 # 監視感覚 監視回数
Linux 3.2.0-4-amd64 (hostname)   2014年08月03日  _x86_64_        (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.30    0.00    0.02    0.05    0.02   99.60

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
xvda              0.34         0.33         4.70    1195941   17262316

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    0.00    3.00    0.00   97.00

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
xvda              2.00        12.00         0.00         12          0


root@hostname:/home/shimizu# cat /etc/mtab # 現在マウントしているディスク情報を表示
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,relatime,size=10240k,nr_inodes=72449,mode=755 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,noexec,relatime,size=61108k,mode=755 0 0
/dev/xvda / ext4 rw,relatime,user_xattr,barrier=1,data=ordered 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
tmpfs /run/shm tmpfs rw,nosuid,nodev,noexec,relatime,size=122200k 0 0

root@hostname:/home/shimizu# iostat -x # 拡張情報も表示
Linux 3.2.0-4-amd64 (hostname)   2014年08月03日  _x86_64_        (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.30    0.00    0.02    0.05    0.02   99.60

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
xvda              0.00     0.15    0.02    0.32     0.33     4.70    29.82     0.01   15.64    8.25   16.06   1.75   0.06

pidstat

プロセス単位のリソース使用量を調べる

root@hostname:/home/shimizu# pidstat -p 9654 1 3 -t # 1秒間隔で3回表示する。-t:スレッド情報も表示する
Linux 3.2.0-4-amd64 (hostname)        2014年06月13日  _x86_64_        (2 CPU)

00時49分18秒      TGID       TID    %usr %system  %guest    %CPU   CPU  Command
00時49分19秒      9654         -    0.00    0.00    0.00    0.00     1  nginx
00時49分19秒         -      9654    0.00    0.00    0.00    0.00     1  |__nginx

00時49分19秒      TGID       TID    %usr %system  %guest    %CPU   CPU  Command
00時49分20秒      9654         -    0.00    0.00    0.00    0.00     1  nginx
00時49分20秒         -      9654    0.00    0.00    0.00    0.00     1  |__nginx

00時49分20秒      TGID       TID    %usr %system  %guest    %CPU   CPU  Command
00時49分21秒      9654         -    0.00    0.00    0.00    0.00     1  nginx
00時49分21秒         -      9654    0.00    0.00    0.00    0.00     1  |__nginx

平均値:       TGID       TID    %usr %system  %guest    %CPU   CPU  Command
平均値:       9654         -    0.00    0.00    0.00    0.00     -  nginx
平均値:          -      9654    0.00    0.00    0.00    0.00     -  |__nginx

slabtop

リアルタイムにカーネル slab キャッシュ情報を表示する
カーネルは、メモリの利用効率を高めるために、カーネル空間内のさまざまなメモリ資源を、資源ごとにキャッシュをする仕組みがある
これを「スラブキャッシュ」と呼ぶ

root@hostname:/home/shimizu# slabtop
 Active / Total Objects (% used)    : 225233 / 262764 (85.7%)
 Active / Total Slabs (% used)      : 17262 / 17262 (100.0%)
 Active / Total Caches (% used)     : 112 / 247 (45.3%)
 Active / Total Size (% used)       : 55015.65K / 63163.77K (87.1%)
 Minimum / Average / Maximum Object : 0.02K / 0.24K / 4096.00K

  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME
124357 106273  85%    0.10K   3361       37     13444K buffer_head
 31928  27028  84%    0.85K   7982        4     31928K ext4_inode_cache
 28960  28960 100%    0.19K   1448       20      5792K dentry
  9639   9618  99%    0.14K    357       27      1428K sysfs_dir_cache

ipcs

プロセス間通信機能の状況を報告します

root@hostname:/home/shimizu# ipcs
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x6c0104cc 3342336    zabbix     600        117192     6
0x0101098b 3178497    root       600        1200712    4

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x7a0104cc 3801088    zabbix     600        12
0x00000000 3604481    www-data   600        1
0x00000000 3637250    www-data   600        1

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

セマフォの使用状況を確認可能
セマフォは、資源の個数を管理するカウンタ(整数値)であり、これによって資源の排他的制御を実現している
共有メモリーなどのチェックする場合に利用する

root@hostname:/home/shimizu# ipcs -s
------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x7a0104cc 3801088    zabbix     600        12
0x00000000 3604481    www-data   600        1
0x00000000 3637250    www-data   600        1

fio

Fusion-io社推奨のテストツール

root@hostname:/boot# aptitude install fio
以下の新規パッケージがインストールされます:
  fio libibverbs1{a} librdmacm1{a}

root@hostname:/usr/local/src# fio -rw=randwrite -bs=16k -size=100m -iodepth=32 -directory=/tmp -direct=1 -invalidate=1 -runtime=300 -numjobs=8 -name=iotest -ioengine=libaio -group_reporting
# direct: ダイレクト転送するかどうか
# rw:読み書きのタイプ、read・write・randread・randwrite・readwrite・randrwがある
# bs: 読み書きの単位(ブロックサイズ)
# size: ファイルI/Oのトータルサイズ
# iodepth: どれ位並行して非同期読み書きを行うか
# directory: IOベンチマークの対象
# numjobs: 並列処理させるjob数
# direct: ダイレクト転送するかどうか、1だとnon-bufferd (O_DIRECT)、通常は1にする
# invalidate: バッファキャッシュの無効化
# runtime: テストの実行時間の上限
# ioengine: 利用するIOエンジン
# group_reporting: レポートをjobごとではなくグループ単位で出力
# name: job開始に必要なjob名、テストや結果には影響しない

iotest: (g=0): rw=randrw, bs=16K-16K/16K-16K, ioengine=libaio, iodepth=32
...
iotest: (g=0): rw=randrw, bs=16K-16K/16K-16K, ioengine=libaio, iodepth=32
2.0.8
Starting 8 processes
Jobs: 1 (f=1): [______m_] [100.0% done] [8784K/8688K /s] [549 /543  iops] [eta 00m:00s]
iotest: (groupid=0, jobs=8): err= 0: pid=26122
  read : io=408240KB, bw=2453.1KB/s, iops=153 , runt=166361msec # 平均の帯域幅(bandwidth)
    slat (usec): min=9 , max=3480.9K, avg=16822.74, stdev=147536.37 
    clat (usec): min=2 , max=9040.2K, avg=657244.35, stdev=1035805.88 # 処理完了までに要したレイテンシ(completion latency-リクエストの送信からその処理終了までに要した遅延時間)
     lat (usec): min=14 , max=9040.3K, avg=674068.49, stdev=1059305.72
    clat percentiles (usec):
     |  1.00th=[    3],  5.00th=[ 9920], 10.00th=[45312], 20.00th=[78336],
     | 30.00th=[111104], 40.00th=[162816], 50.00th=[264192], 60.00th=[325632],
     | 70.00th=[440320], 80.00th=[970752], 90.00th=[1925120], 95.00th=[2965504],
     | 99.00th=[5079040], 99.50th=[5603328], 99.90th=[6520832], 99.95th=[7110656],
     | 99.99th=[8978432]
    bw (KB/s)  : min=    4, max= 4672, per=21.42%, avg=525.41, stdev=665.78 # 帯域幅の情報: 最小、最大、平均、標準偏差
  write: io=410960KB, bw=2470.3KB/s, iops=154 , runt=166361msec
    slat (usec): min=11 , max=3992.7K, avg=21581.54, stdev=180320.03
    clat (msec): min=1 , max=14091 , avg=892.15, stdev=1530.94
     lat (msec): min=1 , max=14091 , avg=913.74, stdev=1561.92
    clat percentiles (msec):
     |  1.00th=[    5],  5.00th=[   28], 10.00th=[   59], 20.00th=[   90],
     | 30.00th=[  125], 40.00th=[  178], 50.00th=[  281], 60.00th=[  351],
     | 70.00th=[  486], 80.00th=[ 1205], 90.00th=[ 2769], 95.00th=[ 4555],
     | 99.00th=[ 7177], 99.50th=[ 8094], 99.90th=[10159], 99.95th=[10683],
     | 99.99th=[13304]
    bw (KB/s)  : min=    5, max= 4800, per=23.22%, avg=573.61, stdev=680.71
    lat (usec) : 4=0.61%, 10=0.01%, 20=0.01%, 50=0.07%, 100=0.10%
    lat (usec) : 250=0.18%, 500=0.12%, 750=0.04%, 1000=0.01%
    lat (msec) : 2=0.13%, 4=0.71%, 10=1.72%, 20=1.85%, 50=3.89%
    lat (msec) : 100=15.74%, 250=21.72%, 500=24.71%, 750=3.90%, 1000=3.38% # IOリクエストの送出からその応答が返されるまでの時間は251msと500msの間が全体の24.71%
    lat (msec) : 2000=9.01%, >=2000=12.09%
  cpu          : usr=0.07%, sys=0.27%, ctx=12055, majf=0, minf=180 # IO負荷がCPUに及ぼす影響が示されており、ここで得られる情報はIO側の速度に比してプロセッサ側が低速すぎないかを判定する
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.2%, 32=99.5%, >=64=0.0% # 17から32個のリクエストが非同期IOキューに置かれていた時間が全体の99.5%
     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.1%, 64=0.0%, >=64=0.0%
     issued    : total=r=25515/w=25685/d=0, short=r=0/w=0/d=0

Run status group 0 (all jobs):
   READ: io=408240KB, aggrb=2453KB/s, minb=2453KB/s, maxb=2453KB/s, mint=166361msec, maxt=166361msec # 総合帯域幅(aggrb:aggregate bandwidth)
  WRITE: io=410960KB, aggrb=2470KB/s, minb=2470KB/s, maxb=2470KB/s, mint=166361msec, maxt=166361msec

Disk stats (read/write):
  xvda: ios=26273/26437, merge=84/4917, ticks=12592488/13075484, in_queue=25688264, util=100.00%

root@hostname:/home/admin# cd /usr/local/src
root@hostname:/usr/local/src# wget http://www.winkey.jp/downloads/visit.php/fio-crystaldiskmark -O crystaldiskmark.fio  # CrystalDiskMarkと同じ計測が可能
root@hostname:/usr/local/src# fio crystaldiskmark.fio -o fio.txt
...

「write_iolog」および「read_iolog」は、送信したすべてのIOリクエストに関するログの書き込みおよび読み出しをfioに行わせるための指
何らかのアプリケーションからIOアクセスパターンの情報をインポートして、fioに解析させるという操作も、これらiologオプションによって可能らしいが、そのうちやってみる。。

QD32とは

NCQ機能のQueue Depth(キューデプス)を32個にすること
NCQ機能について、コマンドを一通り先にHDDに知らせてしまい、HDD自身に最も合理的な順番でコマンドを処理させること
このコマンドを受け取れる数を「Queue Depth(キューデプス)」と呼び、多いほうが効率的に処理できる

参考

http://www.winkey.jp/article.php/20110310142828679
http://sourceforge.jp/magazine/08/05/22/0127246
iftopの利用方法
http://www.ahref.org/tech/server/server-tips/801.html
Unix command > iotopコマンド
http://sweng.web.fc2.com/ja/program/shellscript/iotop.html

1件のコメントがあります

  1. shimizu

    fioの設定ファイルを利用した実行例について
    # ワンライナー
    fio –name=test –directory=/tmp/fio-test/ –direct=1 –rw=randwrite –bs=16k –size=1G –group_reporting –numjobs=1

    # 設定ファイル形式
    vim /tmp/fio.txt
    ————-
    [test]
    directory=/tmp/fio-test/
    direct=1
    rw=randwrite
    bs=16k
    size=1G
    group_reporting=1
    numjobs=1
    ————-
    fio /tmp/fio.txt

コメントは受け付けていません。