【輕知識(shí)】sysbench壓測

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

建庫

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

壓測

準(zhǔn)備數(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壓測

線程 開多了就崩了。會(huì)出現(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:測試使用的目標(biāo)數(shù)據(jù)庫,這個(gè)庫名要事先創(chuàng)建
--oltp-tables-count=32:產(chǎn)生表的數(shù)量
--oltp-table-size=10000000:每個(gè)表產(chǎn)生的記錄行數(shù)
--oltp-dist-type=uniform:指定隨機(jī)取樣類型,可選值有 uniform(均勻分布), Gaussian(高斯分布), special(空間分布)。默認(rèn)是special
--oltp-read-only=off:表示不止產(chǎn)生只讀SQL,也就是使用oltp.lua時(shí)會(huì)采用讀寫混合模式。默認(rèn) off,如果設(shè)置為on,則不會(huì)產(chǎn)生update,delete,insert的sql。
--oltp-test-mode=nontrx:執(zhí)行模式,這里是非事務(wù)式的??蛇x值有simple,complex,nontrx。默認(rèn)是complex <br>    simple:簡單查詢,SELECT c FROM sbtest WHERE id=N <br>    complex (advanced transactional):事務(wù)模式在開始和結(jié)束事務(wù)之前加上begin和commit, 一個(gè)事務(wù)里可以有多個(gè)語句,如點(diǎn)查詢、范圍查詢、排序查詢、更新、刪除、插入等,并且為了不破壞測試表的數(shù)據(jù),該模式下一條記錄刪除后會(huì)在同一個(gè)事務(wù)里添加一條相同的記錄。
    nontrx (non-transactional):與simple相似,但是可以進(jìn)行update/insert等操作,所以如果做連續(xù)的對比壓測,你可能需要重新cleanup,prepare。
--oltp-skip-trx=[on|off]:省略begin/commit語句。默認(rèn)是off
--rand-init=on:是否隨機(jī)初始化數(shù)據(jù),如果不隨機(jī)化那么初始好的數(shù)據(jù)每行內(nèi)容除了主鍵不同外其他完全相同
--num-threads=12: 并發(fā)線程數(shù),可以理解為模擬的客戶端并發(fā)連接數(shù)
--report-interval=10:表示每10s輸出一次測試進(jìn)度報(bào)告
--max-requests=0:壓力測試產(chǎn)生請求的總數(shù),如果以下面的max-time來記,這個(gè)值設(shè)為0
--max-time=120:壓力測試的持續(xù)時(shí)間,這里是2分鐘。
注意,針對不同的選項(xiàng)取值就會(huì)有不同的子選項(xiàng)。比如oltp-dist-type=special,就有比如oltp-dist-pct=1、oltp-dist-res=50兩個(gè)子選項(xiàng),代表有50%的查詢落在1%的行(即熱點(diǎn)數(shù)據(jù))上,另外50%均勻的(sample uniformly)落在另外99%的記錄行上。
再比如oltp-test-mode=nontrx時(shí), 就可以有oltp-nontrx-mode,可選值有select(默認(rèn)), update_key, update_nokey, insert, delete,代表非事務(wù)式模式下使用的測試sql類型。
以上代表的是一個(gè)只讀的例子,可以把num-threads依次遞增(16,36,72,128,256,512),或者調(diào)整my.cnf參數(shù),比較效果。另外需要注意的是,大部分mysql中間件對事務(wù)的處理,默認(rèn)都是把sql發(fā)到主庫執(zhí)行,所以只讀測試需要加上oltp-skip-trx=on來跳過測試中的顯式事務(wù)。

查看表數(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)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容