大家知道,在mysql中,计算qps与qts时,目前有两种方式。具体的算法如下:
但在使用方法一进行计算时,有如下问题。
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的值。