mysql中questions与com_select的区别

大家知道,在mysql中,计算qps与qts时,目前有两种方式。具体的算法如下:

方法一:基于 questions  计算qps,基于  com_commit  com_rollback 计算tps
questions = show global status like 'questions';
uptime = show global status like 'uptime';
qps=questions/uptime

com_commit = show global status like 'com_commit';
com_rollback = show global status like 'com_rollback';
uptime = show global status like 'uptime';
tps=(com_commit + com_rollback)/uptime

方法二  基于 com_* 的status 变量计算tps ,qps
使用如下命令:
show global status where variable_name in('com_select','com_insert','com_delete','com_update');
获取间隔1s 的 com_*的值,并作差值运算
del_diff = (int(mystat2['com_delete'])   - int(mystat1['com_delete']) ) / diff
ins_diff = (int(mystat2['com_insert'])    - int(mystat1['com_insert']) ) / diff
sel_diff = (int(mystat2['com_select'])    - int(mystat1['com_select']) ) / diff
upd_diff = (int(mystat2['com_update'])   - int(mystat1['com_update']) ) / diff

但在使用方法一进行计算时,有如下问题。

questions的值与com_select的值的增长方式会极不一样,在mysql的系统中,questions值的增长方式和com_select的值的增长方式有很大区别;

我们先来看一下解释:

questions:已经发送给服务器的查询的个数。

com_select: select语句执行了多少次。

但是在实际的测试过程中,发现questions值的增长方式如下:

root@localhost : (none) 02:52:31> show global status where variable_name in('questions','uptime','com_commit','com_rollback');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_commit    | 0     |
| Com_rollback  | 0     |
| Questions     | 75    |
| Uptime        | 14796 |
+---------------+-------+
4 rows in set (0.00 sec)


root@localhost : (none) 02:52:37> use test
Database changed
root@localhost : test 02:53:11> show global status where variable_name in('questions','uptime','com_commit','com_rollback');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_commit    | 0     |
| Com_rollback  | 0     |
| Questions     | 78    |
| Uptime        | 14838 |

+---------------+-------+

在进行一次use test命令时,questions的值增长了2,如果不增长2。

但是对于com_select的增长方式如下:

root@localhost : mysql 03:02:29> show global status where variable_name in('com_select','com_insert','com_delete','com_update');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_delete    | 0     |
| Com_insert    | 1     |
| Com_select    | 29    |
| Com_update    | 0     |
+---------------+-------+
4 rows in set (0.00 sec)


root@localhost : mysql 03:02:31> use test
Database changed
root@localhost : test 03:02:33> show global status where variable_name in('com_select','com_insert','com_delete','com_update');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_delete    | 0     |
| Com_insert    | 1     |
| Com_select    | 30    |
| Com_update    | 0     |
+---------------+-------+
4 rows in set (0.00 sec)


root@localhost : test 03:02:35> select @@version;
+------------+
| @@version  |
+------------+
| 5.6.34-log |
+------------+
1 row in set (0.00 sec)


root@localhost : test 03:02:46> show global status where variable_name in('com_select','com_insert','com_delete','com_update');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_delete    | 0     |
| Com_insert    | 1     |
| Com_select    | 31    |
| Com_update    | 0     |
+---------------+-------+
4 rows in set (0.00 sec)


root@localhost : test 03:02:48> show global status where variable_name in('com_select','com_insert','com_delete','com_update');

在进行show命令时,com_select的值是不会增长的。


而且对于数据库的监控,经常会用到show命令。

所以在使用第一种方式计算时,其实数据是被污染的。

而且questions的值在设置环境变量的时候,也是一直在增长的,你如下语句,而com_select的值在此过程中,并不增长。

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


所以在使用question方式进行计算时,人为拉高了qps的结果,相对来说,使用com_select此种方式来计算qps,相对比较帖近真实情况一些,也就是说,在同等条件下,拉高了qps的值。



发布了145 篇原创文章 · 获赞 21 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/wxc20062006/article/details/79786800