PolarDB-X 1.0效能測試使用Sysbench作為壓測工具,本文介紹Sysbench的使用方法。
安裝
測試使用的是Sysbench 0.5版本,安裝方法如下:
git clone https://github.com/akopytov/sysbench.git
cd sysbench
git checkout 0.5
yum -y install make automake libtool pkgconfig libaio-devel
yum -y install mariadb-devel
./autogen.sh
./configure
make -j
make install
以上是在壓測ECS上的安裝方法,如果需要安裝到其他動作系統,參考Sysbench 官方文檔。
安裝完畢後,所有內建壓測指令碼都在/usr/local/share/sysbench目錄下,PolarDB-X 1.0效能測試將使用該目錄下的指令碼。除此之外,也可以在源碼目錄sysbench/sysbench/tests/db下找到對應的壓測指令碼。
使用簡介
常用測試模型
Sysbench通過指令碼定義了若干常用的壓測模型,以下簡單介紹幾個常用模型:
壓測模型 | 描述 |
bulk_insert.lua | 批量插入資料 |
insert.lua | 單值插入資料 |
delete.lua | 刪除資料 |
oltp.lua | 混合讀寫測試,讀寫比例14:4 |
select.lua | 簡單的主鍵查詢 |
表結構
對PolarDB-X 1.0進行測試時,對Sysbench的測試表稍作改造,將其修改為分庫分表的形式,測試表的建表語句如下:
CREATE TABLE `sbtest1` (
`id` int(10) unsigned NOT NULL,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
`pad` char(60) NOT NULL DEFAULT '',
KEY `xid` (`id`),
KEY `k_1` (`k`)
) dbpartition by hash(`id`) tbpartition by hash(`id`) tbpartitions 4
以上建表語句中,分庫分表數可自行調整,該表會在準備資料階段自動產生,無需手動建立。
測試命令及參數
使用Sysbench進行壓測,通常分為三個步驟:
prepare:準備資料;
run:運行測試模型;
cleanup:清理測試資料。
通常僅需準備一次資料,在此資料基礎上測試各種模型即可。
常用參數
Sysbench中常用的參數如下:
--oltp-tables-count=1:表數量。--oltp-table-size=10000000:每個表產生的記錄行數。--oltp-read-only=off:是否產生唯讀SQL,預設off,如果設定為on,則oltp模型不會產生update, delete,insert的SQL語句。--oltp-skip-trx=[on|off]:省略BEGIN/COMMIT語句。預設是off。--rand-init=on:是否隨機初始化資料,如果不隨機化那麼初始好的資料每行內容除了主鍵不同外其他完全相同。--num-threads=12: 並發線程數,可以理解為類比的用戶端並發串連數。--report-interval=10:表示每10s輸出一次效能資料。--max-requests=0:壓力測試產生請求的總數,如果以下面的max-time來記,這個值設為0即可。--max-time=120:測試的期間。--oltp_auto_inc=off:ID是否為自增列。--oltp_secondary=on:將ID設定為非主鍵防止主鍵衝突。--oltp_range_size=5: 連續取值5個,必定走到5個分區。--mysql_table_options='dbpartition by hash(id) tbpartition by hash(id) tbpartitions 2':PolarDB-X 1.0支援拆分表,在建表的時候需要指定拆分方式。
樣本命令
您可以使用如下命令進行對應操作:
在執行命令之前您需要先手動建立測試資料庫,再根據實際的執行個體資訊對以下參數進行替換:
<user_name>:帳號名稱。
<password>:帳號密碼。
<host>:內網或公網地址。
<port>:內網或公網地址對應的連接埠號碼。
<db_name>:資料庫名稱。
準備資料:
sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp-tables-count=1 --report-interval=10 --oltp-table-size=10000000 --mysql-user=<user_name> --mysql-password=<password> --mysql-table-engine=innodb --rand-init=on --mysql-host=<host> --mysql-port=<port> --mysql-db=<db_name> --max-time=300 --max-requests=0 --oltp_skip_trx=on --oltp_auto_inc=off --oltp_secondary=on --oltp_range_size=5 --mysql_table_options='dbpartition by hash(`id`) tbpartition by hash(`id`) tbpartitions 2' --num-threads=200 prepare執行測試:
sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp-tables-count=1 --report-interval=10 --oltp-table-size=10000000 --mysql-user=<user_name> --mysql-password=<password> --mysql-table-engine=innodb --rand-init=on --mysql-host=<host> --mysql-port=<port> --mysql-db=<db_name> --max-time=300 --max-requests=0 --oltp_skip_trx=on --oltp_auto_inc=off --oltp_secondary --oltp_range_size=5 --mysql_table_options='dbpartition by hash(`id`) tbpartition by hash(`id`) tbpartitions 2' --num-threads=200 run清理環境:
sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp-tables-count=1 --report-interval=10 --oltp-table-size=10000000 --mysql-user=<user_name> --mysql-password=<password> --mysql-table-engine=innodb --rand-init=on --mysql-host=<host> --mysql-port=<port> --mysql-db=<db_name> --max-time=300 --max-requests=0 --oltp_skip_trx=on --oltp_auto_inc=off --oltp_secondary --oltp_range_size=5 --mysql_table_options='dbpartition by hash(`id`) tbpartition by hash(`id`) tbpartitions 2' --num-threads=200 cleanup