QPS、TPS、系统吞吐量在mysql中的查看方法

一、每秒查询数QPS

Queries Per Second意思是“每秒查询率”,是一台服务器每秒能够相应的查询次数
是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准。

二、每秒事务数TPS

是TransactionsPerSecond的缩写,也就是事务数/秒。它是软件测试结果的测量单位。
一个事务是指一个客户机向服务器发送请求然后服务器做出反应的过程。
客户机在发送请求时开始计时,收到服务器响应后结束计时,以此来计算使用的时间和完成的事务个数
    ## Tps每秒处理的事务数
          a 用户请求服务
          b 服务器自己的内部处理
          c 服务器返回给用户
       ### 解释
           这三个过程是一个完整的事务(具有原子性的特征),
           每秒能完成N个这三个事务过程,Tps(每秒的事务数)也就是N
       ### 举例子
           如果访问一个页面会请求服务器3次,那么一次访问,
           会产生一个“T”,产生3个“Q”

三、系统吞吐量

一个系统的吞度量(承压能力)与request对CPU的消耗、外部接口、IO等等紧密关联。
单个reqeust 对CPU消耗越高,外部系统接口、IO影响速度越慢,系统吞吐能力越低,反之越高。
系统吞吐量几个重要参数:QPS(TPS)、并发数、响应时间

概念

QPS(TPS):每秒钟request/事务 数量
并发数: 系统同时处理的request/事务数
响应时间:  一般取平均响应时间

理解了上面三个要素的意义之后,就能推算出它们之间的关系:

计算公式

QPS(TPS)= 并发数/平均响应时间
并发数 = QPS*平均响应时间

四、mysql下吞吐量参数的查看方式

(1)QPS(每秒Query量) 
      QPS = Questions(or Queries) / seconds 
       mysql > show  global  status like 'Question%'; 

(2)TPS(每秒事务量) 
      TPS = (Com_commit + Com_rollback) / seconds 
      mysql > show global status like 'Com_commit'; 
      mysql > show global status like 'Com_rollback'; 
 (3)key Buffer 命中率 
      mysql>show  global   status  like   'key%'; 
      key_buffer_read_hits = (1-key_reads / key_read_requests) * 100% 
      key_buffer_write_hits = (1-key_writes / key_write_requests) * 100% 
 (4)InnoDB Buffer命中率 
      mysql> show status like 'innodb_buffer_pool_read%'; 
      innodb_buffer_read_hits = (1 - innodb_buffer_pool_reads / innodb_buffer_pool_read_requests) * 100% 
 (5)Query Cache命中率 
      mysql> show status like 'Qcache%'; 
      Query_cache_hits = (Qcahce_hits / (Qcache_hits + Qcache_inserts )) * 100%; 
 (6)Table Cache状态量 
       mysql> show global  status like 'open%'; 
       比较 open_tables  与 opend_tables 值  
 (7)Thread Cache 命中率 
       mysql> show global status like 'Thread%'; 
       mysql> show global status like 'Connections'; 
       Thread_cache_hits = (1 - Threads_created / connections ) * 100% 
 (8)锁定状态 
       mysql> show global  status like '%lock%'; 
       Table_locks_waited/Table_locks_immediate=0.3%  如果这个比值比较大的话,说明表锁造成的阻塞比较严重 
       Innodb_row_lock_waits innodb行锁,太大可能是间隙锁造成的 
  (9)复制延时量 
        mysql > show slave status 
        查看延时时间 
  (10) Tmp Table 状况(临时表状况) 
         mysql > show status like 'Create_tmp%'; 
         Created_tmp_disk_tables/Created_tmp_tables比值最好不要超过10%,如果Created_tmp_tables值比较大, 
         可能是排序句子过多或者是连接句子不够优化 
   (11) Binlog Cache 使用状况 
          mysql > show status like 'Binlog_cache%'; 
          如果Binlog_cache_disk_use值不为0 ,可能需要调大 binlog_cache_size大小 
   (12) Innodb_log_waits 量 
          mysql > show status like 'innodb_log_waits'; 
          Innodb_log_waits值不等于0的话,表明 innodb log  buffer 因为空间不足而等待 

    比如命令: 
    >#show global status; 
    虽然可以使用: 
    >#show global status like %...%; 
    过滤,但是对应长长的list,每一项都代表什么意思,还是有必要弄清楚。

QPS计算

questions = show global status like 'questions';
uptime = show global status like 'uptime';
qps=questions/uptime

TPS计算

com_commit = show global status like 'com_commit';
com_rollback = show global status like 'com_rollback';
com_select = show global status like 'com_select';
com_insert = show global status like 'com_insert';
com_delete = show global status like 'com_delete';
com_update = show global status like 'com_update';
uptime = show global status like 'uptime';
tps=(com_commit + com_rollback + com_select + com_insert + com_delete + com_update)/uptime

运行命令

root@ubuntu:~# mysqladmin status
Uptime: 7708415  Threads: 281  Questions: 1530623457  Slow queries: 1616334  Opens: 749480  Flush tables: 1  Open tables: 800  Queries per second avg: 198.565

仅有 1 条评论
  1. mlboy

    https://go.microsoft.com/fwlink/?linkid=852980

    mlboy 回复
发表新评论取消回复