SystemTapã§MySQLã®Disk I/Oãåæãã
å®é¨ã¨ã³ããªã§ãã
åæ©
Oracleã®Statspack/AWRã§åãããã¡ã¤ã«åä½ã®Disk I/Oæ å ±ããMySQLã§ãæ¡åããããããã¯æ¬¡ã«ç¤ºããããªãã¼ã¿ã§ãã
File IO Stats DB/Inst: ORA112/ORA112 Snaps: 6-7 ->Mx Rd Bkt: Max bucket time for single block read ->ordered by Tablespace, File Tablespace Filename ------------------------ ---------------------------------------------------- Av Mx Av Av Rd Rd Av Av Buffer BufWt Reads Reads/s (ms) Bkt Blks/Rd Writes Writes/s Waits (ms) -------------- ------- ----- --- ------- ------------ -------- ---------- ------ SYSAUX /opt/oracle/oradata/ORA112/sysaux01.dbf 48 1 8.5 ### 2.0 37 0 0 SYSTEM /opt/oracle/oradata/ORA112/system01.dbf 47 1 8.1 32 1.0 9 0 0 UNDOTBS1 /opt/oracle/oradata/ORA112/undotbs01.dbf 2 0 40.0 ### 1.0 13 0 0 USERS /opt/oracle/oradata/ORA112/users01.dbf 4,358 57 48.9 ### 1.9 5 0 8 15.0 -------------------------------------------------------------
Oracleã§ã¯ããããæ å ±ã表é ååä½ããã¡ã¤ã«åä½ããã¼ãã«ã»ã¤ã³ããã¯ã¹åä½ã§åå¾ãããã¨ãã§ãã¾ããããã©ã¼ãã³ã¹ãã¥ã¼ãã³ã°ã®ããã«ã¯ãã²ã¨ã欲ããæ å ±ã§ãã
æ¹å¼æ¡
ããããèãã¾ããã
- MySQLã«ããããå½ã¦ãã¨ã¨ãã«ããã©ã°ã¤ã³ãæ¸ãã¦INFORMATION_SCHEMAã§æ
å ±ãè¦ãããããã«ãã
â çæ³çã§ããã主ã«ç§ã®æè¡åã足ãã¾ããã - ptrace(2)ã§Disk I/Oé¢é£ã®ã·ã¹ãã ã³ã¼ã«ãããã¯ãã
â éä¸ã¾ã§ä½ã£ã¦ããã®ã§ããã3çªç®ã®æ¡ãæãã¤ããã®ã§ããã¾ããã - SystemTapã§Disk I/Oé¢é£ã®ã·ã¹ãã ã³ã¼ã«ãç£è¦ãã
â ããã§ã§ããããªæ°ããã¾ãã
SystemTapã¨ã¯
SystemTapã¯Linuxã«ã¼ãã«ã®åä½ãã¢ãã¿ãªã³ã°ãããã¼ã«ã§ããæ¦è¦ã«ã¤ãã¦ã¯ä»¥ä¸ã®IBM developerWorksã®è¨äºãåèã«ãªãã¨æãã¾ãã
ãããã¦ãå ¬å¼ãµã¤ãã®ãã®ãã¼ãºã¬ã¤ãã¨ãªãã¡ã¬ã³ã¹ããã¥ã¢ã«ããåç §ãã ããã
- SystemTap Beginners Guide (è±èª)
- SystemTap Language Reference (è±èª)
CentOS 5ã®å ´åãSystemTapã¯ãã£ã¹ããªãã¥ã¼ã·ã§ã³ã«ä»å±ãã¦ãã¾ãããã ãã追å ã§kernel-debuginfoã¨kernel-debuginfo-commonãã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããã¾ãããããã®ããã±ã¼ã¸ã¯ http://debuginfo.centos.org/ ã§é å¸ããã¦ãã¾ãã
SystemTapã¹ã¯ãªãã
ä»åä½æããSystemTapã¹ã¯ãªããã以ä¸ã«ç¤ºãã¾ãã
global PROCNAME = "mysqld" global fds probe begin { printf("start\n") } probe syscall.read, syscall.pread { if (execname() == PROCNAME) { fds[pid(), tid()] = fd } } probe syscall.read.return, syscall.pread.return { if (execname() == PROCNAME && $return != -1) { printf("read\t%d\t%d\t%d\n", pid(), fds[pid(), tid()], $return) } } probe syscall.write, syscall.pwrite { if (execname() == PROCNAME) { fds[pid(), tid()] = fd } } probe syscall.write.return, syscall.pwrite.return { if (execname() == PROCNAME && $return != -1) { printf("write\t%d\t%d\t%d\n", pid(), fds[pid(), tid()], $return) } } probe syscall.close { if (execname() == PROCNAME) { printf("close\t%d\t%d\n", pid(), fd) } } probe timer.s(5) { printf("print\n") }
ããã¯read(2)ãpread(2)ãwrite(2)ãpwrite(2)ãç£è¦ãã¦ããã»ã¹IDããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ãèªã¿æ¸ããããã¤ãæ°ãæ¨æºåºåã«ãã³ãããã¹ã¯ãªããã§ãããã®éãã°ã大éã«åºåãããã®ãé²ããããç£è¦å¯¾è±¡ãmysqldããã»ã¹ã«éå®ãã¦ãã¾ãã
Perlã¹ã¯ãªãã
SystemTapã ãã§ã¯ã©ããã¦ãå¦çãå®çµã§ããªãã£ãã®ã§ãè£å©çã«Perlã使ãã¾ããã次ã«ç¤ºãã¹ã¯ãªããã§åºåçµæã®éè¨ãè¡ãã¾ãã
#!/usr/bin/perl use strict; use warnings; my (%file, $flag, %entry, %reads, %writes, %rbytes, %wbytes, $interval); $flag = 0; $interval = 5; while (my $line = <>) { chomp($line); my ($call, $pid, $fd, $size) = split(/\t/, $line); if (($call eq 'read') or ($call eq 'write')) { if (!defined($file{"$pid,$fd"})) { $file{"$pid,$fd"} = readlink("/proc/$pid/fd/$fd") or next; } my $f = $file{"$pid,$fd"}; if (substr($f, 0, 1) eq '/') { $flag = 1; $entry{$f} = 1; if ($call eq 'read') { $reads{$f}++; $rbytes{$f} += $size; } elsif ($call eq 'write') { $writes{$f}++; $wbytes{$f} += $size; } } } elsif ($call eq 'close') { if (defined($file{"$pid,$fd"})) { delete($file{"$pid,$fd"}); } } elsif ($call eq 'print') { if ($flag == 1) { my ($sec, $min, $hour, $day, $mon, $year) = localtime(); printf "\n%04d-%02d-%02d %02d:%02d:%02d\n", $year + 1900, $mon + 1, $day, $hour, $min, $sec; print " r/s w/s rKB/s wKB/s file\n"; foreach my $f (sort keys %entry) { printf "%7.1f %7.1f %8.1f %8.1f %s\n", defined($reads{$f}) ? $reads{$f} / $interval : 0, defined($writes{$f}) ? $writes{$f} / $interval : 0, defined($rbytes{$f}) ? $rbytes{$f} / $interval / 1024 : 0, defined($wbytes{$f}) ? $wbytes{$f} / $interval / 1024 : 0, $f; } $flag = 0; %entry = %reads = %writes = %rbytes = %wbytes = (); } } else { print "$call\n"; } }
å®è¡ä¾
SystemTapã¯rootã¦ã¼ã¶ã§å®è¡ãã¾ããMySQLã§InnoDBãå©ç¨ãã¦ããå ´åã¯ãinnodb_file_per_tableãæå¹ã«ãã¦ãã¼ãã«ãã¨ã«ãã¡ã¤ã«ãåãã¦ãããã¨ããããããã¾ãã試ãã«TPC-Bã®ãã©ã³ã¶ã¯ã·ã§ã³ãå®è¡ãã¦ã¿ãã¨ããã以ä¸ã®çµæãå¾ããã¨ãã§ãã¾ããã
# stap mysql.stp | perl mysqltap.pl start 2010-01-20 03:34:27 r/s w/s rKB/s wKB/s file 0.0 20.8 0.0 23.1 /var/lib/mysql/ib_logfile0 1.4 0.0 22.4 0.0 /var/lib/mysql/ibdata1 16.4 0.0 262.4 0.0 /var/lib/mysql/tpcb/accounts.ibd 0.6 0.0 9.6 0.0 /var/lib/mysql/tpcb/branches.ibd 0.0 0.6 0.0 22.4 /var/lib/mysql/tpcb/history.ibd 0.6 0.0 9.6 0.0 /var/lib/mysql/tpcb/tellers.ibd 2010-01-20 03:34:32 r/s w/s rKB/s wKB/s file 0.0 78.8 0.0 84.0 /var/lib/mysql/ib_logfile0 62.0 0.0 992.0 0.0 /var/lib/mysql/tpcb/accounts.ibd 0.0 0.2 0.0 6.4 /var/lib/mysql/tpcb/history.ibd 2010-01-20 03:34:37 r/s w/s rKB/s wKB/s file 0.0 80.0 0.0 84.1 /var/lib/mysql/ib_logfile0 0.2 1.0 3.2 176.0 /var/lib/mysql/ibdata1 59.6 0.0 953.6 0.0 /var/lib/mysql/tpcb/accounts.ibd 0.0 0.6 0.0 35.2 /var/lib/mysql/tpcb/history.ibd 2010-01-20 03:34:42 r/s w/s rKB/s wKB/s file 0.0 80.6 0.0 81.8 /var/lib/mysql/ib_logfile0 61.4 0.0 982.4 0.0 /var/lib/mysql/tpcb/accounts.ibd 0.0 0.4 0.0 6.4 /var/lib/mysql/tpcb/history.ibd 2010-01-20 03:34:47 r/s w/s rKB/s wKB/s file 0.0 52.6 0.0 56.3 /var/lib/mysql/ib_logfile0 0.0 1.8 0.0 1120.0 /var/lib/mysql/ibdata1 41.8 33.0 668.8 662.4 /var/lib/mysql/tpcb/accounts.ibd 0.0 0.2 0.0 3.2 /var/lib/mysql/tpcb/branches.ibd 0.0 0.2 0.0 3.2 /var/lib/mysql/tpcb/history.ibd 0.0 0.2 0.0 3.2 /var/lib/mysql/tpcb/tellers.ibd 2010-01-20 03:34:52 r/s w/s rKB/s wKB/s file 0.0 1.4 0.0 0.7 /var/lib/mysql/ib_logfile0 0.0 5.4 0.0 3769.6 /var/lib/mysql/ibdata1 0.0 204.8 0.0 4009.6 /var/lib/mysql/tpcb/accounts.ibd 0.0 0.6 0.0 25.6 /var/lib/mysql/tpcb/history.ibd
ãããã§ããããMySQLãä½ããã¦ãã¦ã©ãã«è² è·ãããã£ã¦ããã®ããä¸ç®çç¶ã§ããï¼
ã¾ããè¦ããã«ããã¯iostatããã¡ã¤ã«åä½ã§è¦ããããããªãã®ã§ããããMySQL以å¤ã«ãããããå¿ç¨ãå©ãããã§ãã
ä»å¾ã®èª²é¡
ã¨ããããMySQLã®ããã©ã¼ãã³ã¹ãã¥ã¼ãã³ã°ã«ã¯ä½¿ããããªã®ã§ãããå®ç§ãæãã«ã¯ããã¤ã足ããªãã¨ãããããã¾ãã
- ä»ã«ãç£è¦ããªããã°ãªããªãã·ã¹ãã ã³ã¼ã«ããã(io_submit(2)ãªã©)
- å®éã®ç©çI/Oãè¦ãã«ã¯ããã£ã¨ä½ãã¬ã¤ã¤ã®é¢æ°ãç£è¦ããå¿ è¦ããã
æ£ç´ç§ã¯ããã§ãã£ã±ããã£ã±ããªã®ã§ã詳ããæ¹ã«æ¹è¯ãã¦ããã ããã¨ã¨ã¦ãããããã§ãã