i漂泊

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3581|回复: 0

MySQL关键性能监控(QPS/TPS)

[复制链接]
TA的礼物信息
  • 收到:0
  • 送出:2
发表于 2017-3-6 14:46:32 | 显示全部楼层 |阅读模式
工作中尝尝会遇到各种数据库性能调优,除了查看某条SQL执行时间长短外,还需要对系统的整体处理能力有更全局的掌握。

QPS:Query per second,每秒查询量

TPS:Transaction per second,每秒事物量

以上两个指标在实际应用中会经常被问到,作为一个项目领导者,必须时刻掌握这些重要指标,并根据相应趋势做出调整。

以下列出上述两个指标的具体算法:
QPS = Queries/ Seconds
Queries 是系统状态值--总查询次数,可以通过show status查询得出
675932-20160216092955204-2030644290.jpg

Seconds是监控的时间区间,单位秒
QPS = (Q2 - Q1)/10   间隔10秒查询两次并记录Q1,Q2,以此计算出QPS值

===================华丽的分割线===============================
TPS = (Com_commit + Com_rollback) / Seconds
Com_commit是系统状态值--事务提交数

2.jpg
Com_rollback是系统状态值--事务回滚数
3.jpg
取时间差,计算规则同QPS
  1. --查看MySQL本次启动后的运行时间(单位:秒)
  2. show status like 'uptime';

  3. --查看select语句的执行数
  4. show [global] status like 'com_select';

  5. --查看insert语句的执行数
  6. show [global] status like 'com_insert';

  7. --查看update语句的执行数
  8. show [global] status like 'com_update';

  9. --查看delete语句的执行数
  10. show [global] status like 'com_delete';

  11. --查看试图连接到MySQL(不管是否连接成功)的连接数
  12. show status like 'connections';

  13. --查看线程缓存内的线程的数量。
  14. show status like 'threads_cached';

  15. --查看当前打开的连接的数量。
  16. show status like 'threads_connected';

  17. --查看当前打开的连接的数量。
  18. show status like 'threads_connected';

  19. --查看创建用来处理连接的线程数。如果Threads_created较大,你可能要增加thread_cache_size值。
  20. show status like 'threads_created';

  21. --查看激活的(非睡眠状态)线程数。
  22. show status like 'threads_running';


  23. --查看立即获得的表的锁的次数。
  24. show status like 'table_locks_immediate';

  25. --查看不能立即获得的表的锁的次数。如果该值较高,并且有性能问题,你应首先优化查询,然后拆分表或使用复制。
  26. show status like 'table_locks_waited';

  27. --查看创建时间超过slow_launch_time秒的线程数。
  28. show status like 'slow_launch_threads';

  29. --查看查询时间超过long_query_time秒的查询的个数。
  30. show status like 'slow_queries';
复制代码


回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

QQ|小黑屋|手机版|IPiaoBo Inc. ( 渝ICP备17002826号 )

GMT+8, 2024-3-29 00:30 , Processed in 0.074730 second(s), 48 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表