mysql计算实时的QPS/TPS
版本:mysql 5.7
需要开启show_compatibility_56
mysql> set global show_compatibility_56=on;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%show_compatibility_56%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| show_compatibility_56 | ON |
+-----------------------+-------+
1 row in set (0.01 sec)
QPS:
select VARIABLE_VALUE,now() from information_schema.GLOBAL_STATUS where VARIABLE_NAME in ('Queries');
查询两次得到的差值除以时间间隔
TPS:
select
sum(`VARIABLE_VALUE`),
now()
from
information_schema.GLOBAL_STATUS
where
VARIABLE_NAME in (
'COM_COMMIT',
'COM_ROLLBACK',
'COM_INSERT',
'COM_DELETE',
'COM_UPDATE'
)
python 计算QPS
# -*- coding: utf-8 -*-
import pymysql
import smtplib
import datetime
import time
##mysql 5.7
mysql_server="192.168.1.22"
user_name="root"
password= "testtest"
db_name="performance_schema"
gl_port=3306
offset = 100
def get_query_value():
sqltext = "select VARIABLE_VALUE as a from performance_schema.global_status where VARIABLE_NAME in ('Queries')"
##print(sqltext)
db = pymysql.connect(mysql_server,user_name, password, db_name,port=gl_port)
cursor = db.cursor()
try:
cursor.execute(sqltext)
results = cursor.fetchone()
except Exception as e:
print(e)
db.close()
q_value = results[0]
return q_value
if __name__ == '__main__':
prev_ops = 0
while True:
ops = int(get_query_value())
qps = ops - prev_ops
prev_ops = ops
print("QPS: "+ str(qps))
time.sleep(1)
TPS
# -*- coding: utf-8 -*-
import pymysql
import smtplib
import datetime
import time
##mysql 5.7
mysql_server="192.168.1.22"
user_name="root"
password= "testtest"
db_name="information_schema"
gl_port=3306
offset = 100
def get_tps_value():
sqltext = "select sum(VARIABLE_VALUE) as a from information_schema.global_status where VARIABLE_NAME in ('COM_COMMIT','COM_ROLLBACK','COM_INSERT','COM_DELETE','COM_UPDATE')"
##print(sqltext)
db = pymysql.connect(mysql_server,user_name, password, db_name,port=gl_port)
cursor = db.cursor()
try:
cursor.execute(sqltext)
results = cursor.fetchone()
except Exception as e:
print(e)
db.close()
q_value = results[0]
return q_value
if __name__ == '__main__':
prev_ops = 0
while True:
ops = int(get_tps_value())
qps = ops - prev_ops
prev_ops = ops
print("TPS: "+ str(qps))
time.sleep(1)
分类:
mysql
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2023-04-19 19c dml重定向使用