【MySQL】计算 TPS,QPS 的方式
生活随笔
收集整理的這篇文章主要介紹了
【MySQL】计算 TPS,QPS 的方式
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在做db基準(zhǔn)測試的時候,qps,tps 是衡量數(shù)據(jù)庫性能的關(guān)鍵指標(biāo)。本文比較了網(wǎng)上的兩種計算方式。先來了解一下相關(guān)概念。
概念介紹:
QPS:Queries Per Second ? ? ? ? 查詢量/秒,是一臺服務(wù)器每秒能夠相應(yīng)的查詢次數(shù),是對一個特定的查詢服務(wù)器在規(guī)定時間內(nèi)所處理查詢量多少的衡量標(biāo)準(zhǔn)。
TPS : ?Transactions Per Second ? 是事務(wù)數(shù)/秒,是一臺數(shù)據(jù)庫服務(wù)器在單位時間內(nèi)處理的事務(wù)的個數(shù)。?
如何計算: 從網(wǎng)上查看如果獲取mysql 的qps,tps 的方法有如下兩種: 方法一 基于 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
上述計算方法的值準(zhǔn)確合適嗎? 下圖是我手工做測試的結(jié)果: a 針對mysql innodb 表的dml 操作做了各個量的統(tǒng)計,結(jié)果如下: 由上圖可以得出結(jié)論: 1 com_commit, com_rollback 與顯示指定transaction無關(guān),只和顯式提交commit rollback 有關(guān)。 2 不管dml的結(jié)果是否成功,com_* 都會增加1 。
b 針對myisam 表的測試: 1 對于myisam 表 進行dml操作 只有questions 改變其他值不變。 2 對于myisam 存儲引擎使用com_* 計算其tps,qps 是不準(zhǔn)確的,使用questions 的值計算相對比較合適。
利用腳本使用不同的變量獲取數(shù)據(jù)庫的qps,tps 的對比圖: qps_s ? ? ?是基于 com_select qps_ques 是基于 questions , tps_iud ? ?是基于 com_insert, com_update,com_delete 之和, tps_com_rol是基于 com_commit com_rollback 之和 由上圖可以查看 基于questions 要比基于com_select的數(shù)值要大,因為questions本身是所有db訪問的集合。
總結(jié): Questions 是記錄了從mysqld啟動以來所有的select,dml 次數(shù)包括show 命令的查詢的次數(shù)。這樣多少有失準(zhǔn)確性,比如很多數(shù)據(jù)庫有監(jiān)控系統(tǒng)在運行,每5秒對數(shù)據(jù)庫進行一次show 查詢來獲取當(dāng)前數(shù)據(jù)庫的狀態(tài),而這些查詢就被記錄到QPS,TPS統(tǒng)計中,造成一定的"數(shù)據(jù)污染". 如果數(shù)據(jù)庫中存在比較多的myisam表,則計算還是questions 比較合適。 如果數(shù)據(jù)庫中存在比較多的innodb表,則計算以com_*數(shù)據(jù)來源比較合適。
如何計算: 從網(wǎng)上查看如果獲取mysql 的qps,tps 的方法有如下兩種: 方法一 基于 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
上述計算方法的值準(zhǔn)確合適嗎? 下圖是我手工做測試的結(jié)果: a 針對mysql innodb 表的dml 操作做了各個量的統(tǒng)計,結(jié)果如下: 由上圖可以得出結(jié)論: 1 com_commit, com_rollback 與顯示指定transaction無關(guān),只和顯式提交commit rollback 有關(guān)。 2 不管dml的結(jié)果是否成功,com_* 都會增加1 。
b 針對myisam 表的測試: 1 對于myisam 表 進行dml操作 只有questions 改變其他值不變。 2 對于myisam 存儲引擎使用com_* 計算其tps,qps 是不準(zhǔn)確的,使用questions 的值計算相對比較合適。
利用腳本使用不同的變量獲取數(shù)據(jù)庫的qps,tps 的對比圖: qps_s ? ? ?是基于 com_select qps_ques 是基于 questions , tps_iud ? ?是基于 com_insert, com_update,com_delete 之和, tps_com_rol是基于 com_commit com_rollback 之和 由上圖可以查看 基于questions 要比基于com_select的數(shù)值要大,因為questions本身是所有db訪問的集合。
總結(jié): Questions 是記錄了從mysqld啟動以來所有的select,dml 次數(shù)包括show 命令的查詢的次數(shù)。這樣多少有失準(zhǔn)確性,比如很多數(shù)據(jù)庫有監(jiān)控系統(tǒng)在運行,每5秒對數(shù)據(jù)庫進行一次show 查詢來獲取當(dāng)前數(shù)據(jù)庫的狀態(tài),而這些查詢就被記錄到QPS,TPS統(tǒng)計中,造成一定的"數(shù)據(jù)污染". 如果數(shù)據(jù)庫中存在比較多的myisam表,則計算還是questions 比較合適。 如果數(shù)據(jù)庫中存在比較多的innodb表,則計算以com_*數(shù)據(jù)來源比較合適。
總結(jié)
以上是生活随笔為你收集整理的【MySQL】计算 TPS,QPS 的方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自定义安装python,退格,方向键无法
- 下一篇: 查看MongoDB索引的使用,管理索引