mysqlreport显示Com_中change_db占用比例高的问题的解决方法
程序员文章站
2023-11-20 19:49:40
首先说明一点,每天的访问量并不大每天才2w的访问量,按道理说,访问量再增加一倍这样的服务器也应该足以承受。可是我们的服务器为什么总是这样频频重启呢?经过mysqlrepor...
首先说明一点,每天的访问量并不大每天才2w的访问量,按道理说,访问量再增加一倍这样的服务器也应该足以承受。可是我们的服务器为什么总是这样频频重启呢?经过mysqlreport显示mysql运行的状态如下:
mysql 5.1.28-rc-log uptime 0 0:4:48 thu apr 30 14:04:58 2009
__ key _________________________________________________________________
buffer used 7.74m of 384.00m %used: 2.02
current 52.89m %usage: 13.77
write hit 0.00%
read hit 91.97%
__ questions ___________________________________________________________
total 14.46k 50.2/s
dms 9.24k 32.1/s %total: 63.90
qc hits 3.66k 12.7/s 25.33
com_ 1.04k 3.6/s 7.19
com_quit 517 1.8/s 3.58
-unknown 1 0.0/s 0.01
slow 1 s 4 0.0/s 0.03 %dms: 0.04 log: off
dms 9.24k 32.1/s 63.90
select 9.21k 32.0/s 63.75 99.75
update 23 0.1/s 0.16 0.25
replace 0 0/s 0.00 0.00
delete 0 0/s 0.00 0.00
insert 0 0/s 0.00 0.00
com_ 1.04k 50/s 44.4
set_option 523 1.8/s 3.62
change_db 510 50/s 44.4
show_proces 5 0.0/s 0.03
__ select and sort _____________________________________________________
scan 49 0.2/s %select: 0.53
range 16 0.1/s 0.17
full join 2 0.0/s 0.02
range check 0 0/s 0.00
full rng join 0 0/s 0.00
sort scan 55 0.2/s
sort range 475 1.6/s
sort mrg pass 0 0/s
__ query cache _________________________________________________________
memory usage 12.02m of 150.00m %used: 8.01
block fragmnt 0.01%
hits 3.66k 12.7/s
inserts 9.14k 31.8/s
insrt:prune 9.14k:1 31.8/s
hit:insert 0.40:1
__ table locks _________________________________________________________
waited 0 0/s %total: 0.00
immediate 10.49k 36.4/s
__ tables ______________________________________________________________
open 58 of 512 %cache: 11.33
opened 64 0.2/s
__ connections _________________________________________________________
max used 4 of 2000 %max: 0.20
total 519 1.8/s
__ created temp ________________________________________________________
disk table 1 0.0/s
table 184 0.6/s size: 256.0m
file 5 0.0/s
__ threads _____________________________________________________________
running 2 of 2
cached 2 of 150 %hit: 99.23
created 4 0.0/s
slow 0 0/s
__ aborted _____________________________________________________________
clients 0 0/s
connects 0 0/s
__ bytes _______________________________________________________________
sent 20.36m 70.7k/s
received 1.37m 4.7k/s
__ innodb buffer pool __________________________________________________
usage 304.00k of 8.00m %used: 3.71
read hit 84.42%
pages
free 493 %total: 96.29
data 19 3.71 %drty: 0.00
misc 0 0.00
latched 0.00
reads 77 0.3/s
from file 12 0.0/s 15.58
ahead rnd 1 0.0/s
ahead sql 0 0/s
writes 0 0/s
flushes 0 0/s
wait free 0 0/s
__ innodb lock _________________________________________________________
waits 0 0/s
current 0
time acquiring
total 0 ms
average 0 ms
max 0 ms
__ innodb data, pages, rows ____________________________________________
data
reads 25 0.1/s
writes 3 0.0/s
fsync 3 0.0/s
pending
reads 0
writes 0
fsync 0
pages
created 0 0/s
read 19 0.1/s
written 0 0/s
rows
deleted 0 0/s
inserted 0 0/s
read 0 0/s
updated 0 0/s
大家可以看到在com_中占的比例是相当大的,而一般情况下,这个值应该是3.0%左右。如果这个值过高的话,就说明,你的mysql处理请求中
做了一些无谓的工作,占用了大量的系统资源。其中我们看到尤为change_db的占用率比较高。这个值高了,说明我们执行的user database;命令相当多。
检查程序,原来我们在执行查询语句的时候应用了mysql_query_db("database","sql");这个语句在每次执行的时候都会自动调用use database;
所以我们应该将mysql_db_query 更改成mysql_query();再观察mysql的运行状态,ok。一切正常了。