mysqlreport显示Com_中change_db占用比例高的问题的解决方法

最近公司的mysql服务器经常出现阻塞状态。动不动就重启,给用户访问带来了相当的不便。

首先说明一点,每天的访问量并不大每天才2W的访问量,按道理说,访问量再增加一倍这样的服务器也应该足以承受。可是我们的服务器为什么总是这样频频重启呢?经过mysqlreport显示mysql运行的状态如下:

<PRE><PRE><PRE><PRE><PRE><PRE><PRE><PRE><PRE><PRE><PRE><PRE><PRE><FONT color=#006bad>MySQL 5.1.28-rc-log   uptime 0 0:4:48    Thu Apr 30 14:04:58 2009<br><br>__ Key _________________________________________________________________<BR>Buffer used   7.74M of 384.00M %Used:  2.02<BR> Current   52.89M      %Usage: 13.77<BR>Write hit    0.00%<BR>Read hit    91.97%<br><br>__ Questions ___________________________________________________________<BR>Total     14.46k  50.2/s<BR> DMS      9.24k  32.1/s %Total: 63.90<BR> QC Hits    3.66k  12.7/s      25.33<BR> Com_     1.04k   3.6/s      7.19<BR> COM_QUIT    517   1.8/s      3.58<BR> -Unknown     1   0.0/s      0.01<BR>Slow 1 s      4   0.0/s      0.03 %DMS:  0.04 Log: OFF<BR>DMS       9.24k  32.1/s      63.90<BR> SELECT    9.21k  32.0/s      63.75     99.75<BR> UPDATE      23   0.1/s      0.16     0.25<BR> REPLACE      0    0/s      0.00     0.00<BR> DELETE      0    0/s      0.00     0.00<BR> INSERT      0    0/s      0.00     0.00<BR>Com_      1.04k   50/s      44.4<BR> set_option   523   1.8/s      3.62<BR> change_db    510   50/s      44.4<BR> show_proces    5   0.0/s      0.03<br><br>__ SELECT and Sort _____________________________________________________<BR>Scan        49   0.2/s %SELECT:  0.53<BR>Range       16   0.1/s      0.17<BR>Full join      2   0.0/s      0.02<BR>Range check     0    0/s      0.00<BR>Full rng join    0    0/s      0.00<BR>Sort scan     55   0.2/s<BR>Sort range    475   1.6/s<BR>Sort mrg pass    0    0/s<br><br>__ Query Cache _________________________________________________________<BR>Memory usage  12.02M of 150.00M %Used:  8.01<BR>Block Fragmnt  0.01%<BR>Hits      3.66k  12.7/s<BR>Inserts     9.14k  31.8/s<BR>Insrt:Prune  9.14k:1  31.8/s<BR>Hit:Insert   0.40:1<br><br>__ Table Locks _________________________________________________________<BR>Waited       0    0/s %Total:  0.00<BR>Immediate   10.49k  36.4/s<br><br>__ Tables ______________________________________________________________<BR>Open        58 of 512  %Cache: 11.33<BR>Opened       64   0.2/s<br><br>__ Connections _________________________________________________________<BR>Max used      4 of 2000   %Max:  0.20<BR>Total       519   1.8/s<br><br>__ Created Temp ________________________________________________________<BR>Disk table     1   0.0/s<BR>Table       184   0.6/s  Size: 256.0M<BR>File        5   0.0/s<br><br>__ Threads _____________________________________________________________<BR>Running       2 of  2<BR>Cached       2 of 150   %Hit: 99.23<BR>Created       4   0.0/s<BR>Slow        0    0/s<br><br>__ Aborted _____________________________________________________________<BR>Clients       0    0/s<BR>Connects      0    0/s<br><br>__ Bytes _______________________________________________________________<BR>Sent      20.36M  70.7k/s<BR>Received    1.37M  4.7k/s<br><br>__ InnoDB Buffer Pool __________________________________________________<BR>Usage     304.00k of  8.00M %Used:  3.71<BR>Read hit    84.42%<BR>Pages<BR> Free      493      %Total: 96.29<BR> Data       19           3.71 %Drty:  0.00<BR> Misc       0           0.00<BR> Latched                 0.00<BR>Reads       77   0.3/s<BR> From file    12   0.0/s      15.58<BR> Ahead Rnd     1   0.0/s<BR> Ahead Sql     0    0/s<BR>Writes       0    0/s<BR>Flushes       0    0/s<BR>Wait Free      0    0/s<br><br>__ InnoDB Lock _________________________________________________________<BR>Waits        0    0/s<BR>Current       0<BR>Time acquiring<BR> Total       0 ms<BR> Average      0 ms<BR> Max        0 ms<br><br>__ InnoDB Data, Pages, Rows ____________________________________________<BR>Data<BR> Reads      25   0.1/s<BR> Writes      3   0.0/s<BR> fsync       3   0.0/s<BR> Pending<BR>  Reads      0<BR>  Writes     0<BR>  fsync      0<br><br>Pages<BR> Created      0    0/s<BR> Read       19   0.1/s<BR> Written      0    0/s<br><br>Rows<BR> Deleted      0    0/s<BR> Inserted     0    0/s<BR> Read       0    0/s<BR> Updated      0    0/s<BR>大家可以看到在Com_中占的比例是相当大的,而一般情况下,这个值应该是3.0%左右。如果这个值过高的话,就说明,你的mysql处理请求中<BR>做了一些无谓的工作,占用了大量的系统资源。其中我们看到尤为change_db的占用率比较高。这个值高了,说明我们执行的user database;命令相当多。<BR>检查程序,原来我们在执行查询语句的时候应用了mysql_query_db("database","sql");这个语句在每次执行的时候都会自动调用use database;<BR>所以我们应该将mysql_db_query 更改成mysql_query();再观察mysql的运行状态,ok。一切正常了。</FONT>
© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享