【輕知識】sysbench壓測

下面內(nèi)容主要借鑒同事的wiki季蚂。經(jīng)過他允許我就貼了肄程。
insert 放后面雾消,前面的查詢跟更新献汗。都是同量的數(shù)據(jù)。

建庫

mysql -h110.xx.xx.10 -udb_user -pdb_pw-P3306

壓測

準備數(shù)據(jù)

sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua \
--mysql-host=host  \
--mysql-port=3306 \
--mysql-user=db_user \
--mysql-password=db_pw \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
prepare

oltp壓測

線程 開多了就崩了炼幔。會出現(xiàn)Lost connection to MySQL server during query

sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user \
--mysql-password=db_pw \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> ./mysysbench.log

select

sysbench /usr/share/sysbench/tests/include/oltp_legacy/select.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user \
--mysql-password=db_pw \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> ./oltp_select.log

select_random_points

sysbench /usr/share/sysbench/tests/include/oltp_legacy/select_random_points.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user \
--mysql-password=db_pw \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> ./select_random_points.log

select random ranges

sysbench /usr/share/sysbench/tests/include/oltp_legacy/select_random_ranges.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user \
--mysql-password=db_pw \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> ./select_random_ranges.log

update_index

sysbench /usr/share/sysbench/tests/include/oltp_legacy/update_index.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user \
--mysql-password=db_pw \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> ./update_index.log

update_non_index

sysbench /usr/share/sysbench/tests/include/oltp_legacy/update_non_index.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user \
--mysql-password=db_pw \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> ./update_non_index.log

insert

sysbench /usr/share/sysbench/tests/include/oltp_legacy/insert.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user \
--mysql-password=db_pw \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> ./insert.log

bulk_insert

sysbench /usr/share/sysbench/tests/include/oltp_legacy/bulk_insert.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user  \
--mysql-password=db_pw  \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> /home/bulk_insert.log

delete

sysbench /usr/share/sysbench/tests/include/oltp_legacy/delete.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user  \
--mysql-password=db_pw  \
--mysql-db=dbtest \
--oltp-tables-count=32 \
--oltp-table-size=200000 \
--oltp-dist-type=uniform \
--oltp-read-only=off \
--oltp-test-mode=complex \
--rand-init=on \
--db-driver=mysql \
--report-interval=10 \
--threads=1000 \
--time=120 \
run >> /home/delete.log

清空數(shù)據(jù)

sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua \
--mysql-host=110.xx.xx.10  \
--mysql-port=3306 \
--mysql-user=db_user  \
--mysql-password=db_pw  \
--mysql-db=dbtest \
--db-driver=mysql \
--oltp-tables-count=32 \
cleanup

字段解釋

mysql-db=dbtest:測試使用的目標數(shù)據(jù)庫,這個庫名要事先創(chuàng)建
--oltp-tables-count=32:產(chǎn)生表的數(shù)量
--oltp-table-size=10000000:每個表產(chǎn)生的記錄行數(shù)
--oltp-dist-type=uniform:指定隨機取樣類型,可選值有 uniform(均勻分布), Gaussian(高斯分布), special(空間分布)卷胯。默認是special
--oltp-read-only=off:表示不止產(chǎn)生只讀SQL,也就是使用oltp.lua時會采用讀寫混合模式威酒。默認 off窑睁,如果設(shè)置為on,則不會產(chǎn)生update,delete,insert的sql葵孤。
--oltp-test-mode=nontrx:執(zhí)行模式担钮,這里是非事務式的∮热裕可選值有simple,complex,nontrx箫津。默認是complex <br>    simple:簡單查詢,SELECT c FROM sbtest WHERE id=N <br>    complex (advanced transactional):事務模式在開始和結(jié)束事務之前加上begin和commit, 一個事務里可以有多個語句苏遥,如點查詢饼拍、范圍查詢、排序查詢田炭、更新师抄、刪除、插入等教硫,并且為了不破壞測試表的數(shù)據(jù)叨吮,該模式下一條記錄刪除后會在同一個事務里添加一條相同的記錄。
    nontrx (non-transactional):與simple相似瞬矩,但是可以進行update/insert等操作茶鉴,所以如果做連續(xù)的對比壓測,你可能需要重新cleanup,prepare丧鸯。
--oltp-skip-trx=[on|off]:省略begin/commit語句蛤铜。默認是off
--rand-init=on:是否隨機初始化數(shù)據(jù),如果不隨機化那么初始好的數(shù)據(jù)每行內(nèi)容除了主鍵不同外其他完全相同
--num-threads=12: 并發(fā)線程數(shù)丛肢,可以理解為模擬的客戶端并發(fā)連接數(shù)
--report-interval=10:表示每10s輸出一次測試進度報告
--max-requests=0:壓力測試產(chǎn)生請求的總數(shù)围肥,如果以下面的max-time來記,這個值設(shè)為0
--max-time=120:壓力測試的持續(xù)時間蜂怎,這里是2分鐘穆刻。
注意,針對不同的選項取值就會有不同的子選項杠步。比如oltp-dist-type=special氢伟,就有比如oltp-dist-pct=1、oltp-dist-res=50兩個子選項幽歼,代表有50%的查詢落在1%的行(即熱點數(shù)據(jù))上朵锣,另外50%均勻的(sample uniformly)落在另外99%的記錄行上。
再比如oltp-test-mode=nontrx時, 就可以有oltp-nontrx-mode甸私,可選值有select(默認), update_key, update_nokey, insert, delete诚些,代表非事務式模式下使用的測試sql類型。
以上代表的是一個只讀的例子皇型,可以把num-threads依次遞增(16,36,72,128,256,512)诬烹,或者調(diào)整my.cnf參數(shù),比較效果弃鸦。另外需要注意的是绞吁,大部分mysql中間件對事務的處理,默認都是把sql發(fā)到主庫執(zhí)行唬格,所以只讀測試需要加上oltp-skip-trx=on來跳過測試中的顯式事務家破。

查看表數(shù)據(jù)量

查詢表的數(shù)據(jù)量
SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', table_rows AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'dbtest';
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末颜说,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子员舵,更是在濱河造成了極大的恐慌脑沿,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件马僻,死亡現(xiàn)場離奇詭異庄拇,居然都是意外死亡,警方通過查閱死者的電腦和手機韭邓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進店門措近,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人女淑,你說我怎么就攤上這事瞭郑。” “怎么了鸭你?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵屈张,是天一觀的道長。 經(jīng)常有香客問我袱巨,道長阁谆,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任愉老,我火速辦了婚禮场绿,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘嫉入。我一直安慰自己焰盗,他們只是感情好,可當我...
    茶點故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布咒林。 她就那樣靜靜地躺著熬拒,像睡著了一般。 火紅的嫁衣襯著肌膚如雪垫竞。 梳的紋絲不亂的頭發(fā)上澎粟,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天,我揣著相機與錄音件甥,去河邊找鬼捌议。 笑死哼拔,一個胖子當著我的面吹牛引有,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播倦逐,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼譬正,長吁一口氣:“原來是場噩夢啊……” “哼宫补!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起曾我,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤粉怕,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后抒巢,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體贫贝,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年蛉谜,在試婚紗的時候發(fā)現(xiàn)自己被綠了稚晚。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,030評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡型诚,死狀恐怖客燕,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情狰贯,我是刑警寧澤也搓,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站涵紊,受9級特大地震影響傍妒,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜栖袋,卻給世界環(huán)境...
    茶點故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一拍顷、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧塘幅,春花似錦昔案、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至匾乓,卻和暖如春捞稿,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背拼缝。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工娱局, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人咧七。 一個月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓衰齐,卻偏偏與公主長得像,于是被迫代替她去往敵國和親继阻。 傳聞我的和親對象是個殘疾皇子耻涛,可洞房花燭夜當晚...
    茶點故事閱讀 44,976評論 2 355