python如何计算TPS和QPS
这篇文章给大家分享的是有关python如何计算TPS和QPS的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
#!/usr/bin/env python
#coding=utf-8
""" 以不同方式获取mysql中的tps,qps,并做对比 """
import time
import sys
import os
import MySQLdb
import dbconn
def main() :
try:
conn = MySQLdb.connect(host=dbconn.DB_HOST,port=int(dbconn.DB_PORT),user=dbconn.DB_USER,passwd=dbconn.DB_PASS, charset='utf8')
except MySQLdb.ERROR,e:
print "Error %d:%s"%(e.args[0],e.args[1])
exit(1)
conn.autocommit(True)
cursor=conn.cursor()
diff = 1
mystat1={}
mystat2={}
sql = "show global status where Variable_name in ('Com_commit','Com_delete','Com_insert','Com_rollback','Com_select','Com_update','Questions');"
while True:
try :
cursor.execute(sql)
results1 = cursor.fetchall()
mystat1=dict(results1)
time.sleep(diff)
cursor.execute(sql)
results2 = cursor.fetchall()
mystat2=dict(results2)
Com_diff = (int(mystat2['Com_commit']) - int(mystat1['Com_commit']) ) / diff
del_diff = (int(mystat2['Com_delete']) - int(mystat1['Com_delete']) ) / diff
ins_diff = (int(mystat2['Com_insert']) - int(mystat1['Com_insert']) ) / diff
rol_diff = (int(mystat2['Com_rollback']) - int(mystat1['Com_rollback']))/ diff
sel_diff = (int(mystat2['Com_select']) - int(mystat1['Com_select']) ) / diff
upd_diff = (int(mystat2['Com_update']) - int(mystat1['Com_update']) ) / diff
que_diff = (int(mystat2['Questions']) - int(mystat1['Questions']) ) / diff
qps_s = sel_diff
tps_iud = del_diff+ins_diff+upd_diff
qps_ques=que_diff
tps_Com_rol= Com_diff + rol_diff
print 'qps_s = %s , qps_ques = %s , tps_iud = %s ,tps_Com_rol = %s' %(qps_s ,qps_ques, tps_iud,tps_Com_rol)
except KeyboardInterrupt :
print "exit .."
sys.exit()
conn.close()
if __name__ == '__main__':
main()
感谢各位的阅读!关于“python如何计算TPS和QPS”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341