下面內(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';