记录阿里巴巴QA架构组成长点滴。2008年关键词为效率,技术,影响力!QA/测试架构师定义:开发和设计测试框架测试库;纵横全局的考虑产品的功能,设计复杂的测试系统;负责研发某一项特定的测试技术;为公司考虑如何提高测试效率。领导公司测试技术的发展和测试策略上的方向,关注整个公司的测试部门的问题,前瞻性的考虑未来的版本的测试策略和技术。测试架构师计划/设计测试平台,关注着产品的测试过程,提供咨询服务,影响到公司内的测试机构测试社区,以及开发机构等,对产品各个方面施加深远而正确的影响,最终提高整体软件质量。

截取mysql 慢语句

上一篇 / 下一篇  2008-04-30 20:22:25 / 个人分类:开源工具与新技术研究

by liangjz

 

最近和开发、DBA一起对MYSQL作性能调优,发现几个点对抓取MYSQL慢语句很有帮助

在/etc/my.cnf 文件加入

log_slow_queries
log-queries-not-using-indexes
log_long_format
long_query_time=1

 

  将在mysql数据目录下( datadir = /home/mysql ) 生成一个如test-slow.log的文件,内容有:

# Time: 080430 20:06:53
#
User@Host: match_account[match_account] @  [10.0.4.114]
# Query_time: 0  Lock_time: 0  Rows_sent: 9  Rows_examined: 18
SELECT * FROM `tree_menus`   WHERE (parentid = 0)  ORDER BY sequence desc, id desc;
# Time: 080430 20:09:04

 

查询用了0秒,返回9行,一共查了18

 

如何利用呢,有2 种方法:

1) [root@test mysql]# grep Rows_examined   test-slow.log  | sort -g -k9 -r|uniq -u |head -100
# Query_time: 0  Lock_time: 0  Rows_sent: 30  Rows_examined: 24460
# Query_time: 0  Lock_time: 0  Rows_sent: 10  Rows_examined: 24440
# Query_time: 0  Lock_time: 0  Rows_sent: 9  Rows_examined: 24439
# Query_time: 0  Lock_time: 0  Rows_sent: 2  Rows_examined: 24432
# Query_time: 0  Lock_time: 0  Rows_sent: 1  Rows_examined: 24430
# Query_time: 0  Lock_time: 0  Rows_sent: 0  Rows_examined: 12043
# Query_time: 0  Lock_time: 0  Rows_sent: 34  Rows_examined: 2441
# Query_time: 0  Lock_time: 0  Rows_sent: 12  Rows_examined: 1449
# Query_time: 0  Lock_time: 0  Rows_sent: 15  Rows_examined: 30
# Query_time: 0  Lock_time: 0  Rows_sent: 5  Rows_examined: 23
# Query_time: 0  Lock_time: 0  Rows_sent: 6  Rows_examined: 22
# Query_time: 0  Lock_time: 0  Rows_sent: 9  Rows_examined: 18
# Query_time: 0  Lock_time: 0  Rows_sent: 1  Rows_examined: 6
# Query_time: 0  Lock_time: 0  Rows_sent: 1  Rows_examined: 5
# Query_time: 0  Lock_time: 0  Rows_sent: 2  Rows_examined: 2
[root@test mysql]# grep -A 1 -B 2  "Rows_examined: 24460"  test-slow.lo
grep: test-slow.lo: No such file or directory
[root@test mysql]# grep -A 1 -B 2  "Rows_examined: 24460"  test-slow.log
# Time: 080430 20:02:29
#
User@Host: match_account[match_account] @  [10.0.4.114]
# Query_time: 0  Lock_time: 0  Rows_sent: 30  Rows_examined: 24460
SELECT * FROM `profiles`    ORDER BY position, created_at DESC LIMIT 0, 30;

 

2)方法2:

[root@test mysql]# mysqldumpslow   -s  t   -t  20

Reading mysql slow query log from /home/mysql/test-slow.log
Count: 1  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=6.0 (6), match_account[match_account]@[10.0.4.114]
  SELECT * FROM `reports`    ORDER BY sequence desc LIMIT N

Count: 1  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=15.0 (15), match_account[match_account]@[10.0.4.114]
  SELECT * FROM `experts`   WHERE (email IS NULL)  ORDER BY sequence desc LIMIT N

 

一般我们关注的3类,参见

http://blog.dreamhosters.com/kbase/index.cgi?area=2868

 

A) "Rows_examined" is more than 2000
B) "Rows_examined" is less than 2000 but that query is being run 20 times a second.
C) "Rows_examined" is three times bigger than "Rows_sent"

 


TAG: 性能 MySQL 开源工具与新技术研究 SQL优化

 

评分:0

我来说两句

日历

« 2024-04-19  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 154215
  • 日志数: 163
  • 文件数: 1
  • 建立时间: 2008-02-26
  • 更新时间: 2008-12-10

RSS订阅

Open Toolbar