計算TPS,QPS的方式
qps,tps是衡量數據庫性能的關鍵指標,網上普遍有兩種計算方式
TPS,QPS相關概念
QPS:Queries Per Second 查詢量/秒,是一台服務器每秒能夠相應的查詢次數,是對一個特定的查詢服務器在規定時間內所處理查詢量多少的衡量標准
TPS : Transactions Per Second 是事務數/秒,是一台數據庫服務器在單位時間內處理的事務的個數。
計算方式一:基於 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
tps= Com_insert/s + Com_update/s + Com_delete/s
qps=Com_select/s + Com_insert/s + Com_update/s + Com_delete/s
一些結論
總結
Questions 是記錄了從mysqld啟動以來所有的select,dml 次數包括show 命令的查詢的次數。這樣多少有失准確性,比如很多數據庫有監控系統在運行,每5秒對數據庫進行一次show 查詢來獲取當前數據庫的狀態,而這些查詢就被記錄到QPS,TPS統計中,造成一定的"數據污染".
如果數據庫中存在比較多的myisam表,則計算還是questions 比較合適。
如果數據庫中存在比較多的innodb表,則計算以com_*數據來源比較合適。