Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How python calculates TPS and QPS

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Python calculates TPS and QPS. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

#!/ usr/bin/env python

#coding=utf-8

"""Get tps, qps in mysql in different ways and compare them"""

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()

Thank you for reading! About "python how to calculate TPS and QPS" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report