首页 > 代码库 > mysqladmin在SuSE linux系统中--sleep参数使用不准确问题

mysqladmin在SuSE linux系统中--sleep参数使用不准确问题

我们都知道,在MySQL中,可以使用mysqladmin命令的extended-status选项来查看MySQL的运行状态,比如获取我们常常关注的几个值:

# mysqladmin -uroot -proot ext |grep "Questions\|Queries\|Innodb_rows\|Com_select \|Com_insert \|Com_update \|Com_delete "
| Com_delete                               | 26750       |
| Com_insert                               | 347420      |
| Com_select                               | 1341126     |
| Com_update                               | 454425      |
| Innodb_rows_deleted                      | 26590       |
| Innodb_rows_inserted                     | 347416      |
| Innodb_rows_read                         | 2964050     |
| Innodb_rows_updated                      | 695605      |
| Queries                                  | 2304578     |
| Questions                                | 2259777     |
但这样得到的数值都累计的,如果想了解当前的状态,则需要进行一次差值计算,而庆幸的是,这个客户端工具提供了两个参数,这样就能实时的得到当前数据库的相关参数值:

-i, --sleep=#       Execute commands again and again with a sleep between,单位是秒

-r, --relative        Show difference between current and previous values when
                                      used with -i. Currently works only with extended-status.

# mysqladmin -uroot -proot ext -i 1 -r |grep "Questions\|Queries\|Innodb_rows\|Com_select \|Com_insert \|Com_update \|Com_delete "
| Com_delete                               | 26750       |
| Com_insert                               | 347420      |
| Com_select                               | 1341129     |
| Com_update                               | 454425      |
| Innodb_rows_deleted                      | 26590       |
| Innodb_rows_inserted                     | 347416      |
| Innodb_rows_read                         | 2964050     |
| Innodb_rows_updated                      | 695605      |
| Queries                                  | 2304592     |
| Questions                                | 2259791     |
这样就得到了MySQL当前数据库每秒中对应值,很直观,这个命令在RHEL 6.4 x86_64系统上可以正常使用。但在SuSE linux 11sp1 x86_64系统中,却是不准确的,即使用-i(或--sleep=)指定刷新的秒数,但事实并非如此。

在测试中,经常是指定了--sleep=1,但显示结果却是大概1分多钟刷新一次,非常奇怪。但在使用strace跟踪发现了原因:

# strace mysqladmin -uroot -proot ext -i 1 -r |grep "Questions\|Queries\|Innodb_rows\|Com_select \|Com_insert \|Com_update \|Com_delete "
execve("/usr/bin/mysqladmin", ["mysqladmin", "-uroot", "-proot", "ext", "-i", "1", "-r"], [/* 59 vars */]) = 0
brk(0)                                  = 0x62a000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0c036fe000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib64/mysql/tls/x86_64/libmysqlclient.so.15", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/mysql/tls/x86_64", 0x7fffbb00c0f0) = -1 ENOENT (No such file or directory)
open("/usr/lib64/mysql/tls/libmysqlclient.so.15", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/mysql/tls", 0x7fffbb00c0f0) = -1 ENOENT (No such file or directory)
open("/usr/lib64/mysql/x86_64/libmysqlclient.so.15", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/mysql/x86_64", 0x7fffbb00c0f0) = -1 ENOENT (No such file or directory)
open("/usr/lib64/mysql/libmysqlclient.so.15", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\262\1\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1420448, ...}) = 0
mmap(NULL, 3521032, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0c03185000
fadvise64(3, 0, 3521032, POSIX_FADV_WILLNEED) = 0
mprotect(0x7f0c032ac000, 2093056, PROT_NONE) = 0
mmap(0x7f0c034ab000, 217088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x126000) = 0x7f0c034ab000
mmap(0x7f0c034e0000, 2568, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f0c034e0000
close(3)                                = 0
……  <==== 省略若干 ====>
write(1, "+-------------------------------"..., 4096) = 4096
write(1, "                  | 0           "..., 4096) = 4096
write(1, "       |\n| Com_truncate         "..., 4096) = 4096
write(1, "ze                         | 163"..., 4096) = 4096
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
<span style="color:#ff0000;">nanosleep({83, 0}</span>,| Com_delete                               | 26750       |
| Com_insert                               | 347420      |
| Com_select                               | 1341136     |
| Com_update                               | 454425      |
| Innodb_rows_deleted                      | 26590       |
| Innodb_rows_inserted                     | 347416      |
| Innodb_rows_read                         | 2964050     |
| Innodb_rows_updated                      | 695605      |
| Queries                                  | 2304622     |
| Questions                                | 2259821     |
问题就在即使指定的是1秒刷新,但系统调用时却是83s刷新一次:
nanosleep({83, 0}
很可惜,这个功能不在这个系统中使用,更不幸的时,生产环境中的全都SuSE linux 11sp1系统,郁闷......

准备找个机会,向SUSE原厂问一下,到底什么情况的。