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上的安裝方法,如果需要安裝到其他操作系統(tǒng),參考Sysbench 官方文檔

安裝完畢后,所有自帶壓測腳本都在/usr/local/share/sysbench目錄下,PolarDB-X 1.0性能測試將使用該目錄下的腳本。除此之外,也可以在源碼目錄sysbench/sysbench/tests/db下找到對應的壓測腳本。

使用簡介

常用測試模型

Sysbench通過腳本定義了若干常用的壓測模型,以下簡單介紹幾個常用模型:

壓測模型 描述
bulk_insert.lua 批量插入數(shù)據(jù)
insert.lua 單值插入數(shù)據(jù)
delete.lua 刪除數(shù)據(jù)
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
            

以上建表語句中,分庫分表數(shù)可自行調整,該表會在準備數(shù)據(jù)階段自動生成,無需手動創(chuàng)建。

測試命令及參數(shù)

使用Sysbench進行壓測,通常分為三個步驟:

  • prepare:準備數(shù)據(jù);
  • run:運行測試模型;
  • cleanup:清理測試數(shù)據(jù)。

通常僅需準備一次數(shù)據(jù),在此數(shù)據(jù)基礎上測試各種模型即可。

常用參數(shù)

Sysbench中常用的參數(shù)如下:

  • --oltp-tables-count=1:表數(shù)量。
  • --oltp-table-size=10000000:每個表產生的記錄行數(shù)。
  • --oltp-read-only=off:是否生成只讀SQL,默認off,如果設置為on,則oltp模型不會生成update, delete,insert的SQL語句。
  • --oltp-skip-trx=[on|off]:省略BEGIN/COMMIT語句。默認是off。
  • --rand-init=on:是否隨機初始化數(shù)據(jù),如果不隨機化那么初始好的數(shù)據(jù)每行內容除了主鍵不同外其他完全相同。
  • --num-threads=12: 并發(fā)線程數(shù),可以理解為模擬的客戶端并發(fā)連接數(shù)。
  • --report-interval=10:表示每10s輸出一次性能數(shù)據(jù)。
  • --max-requests=0:壓力測試產生請求的總數(shù),如果以下面的max-time來記,這個值設為0即可。
  • --max-time=120:測試的持續(xù)時間。
  • --oltp_auto_inc=off:ID是否為自增列。
  • --oltp_secondary=on:將ID設置為非主鍵防止主鍵沖突。
  • --oltp_range_size=5: 連續(xù)取值5個,必定走到5個分片。
  • --mysql_table_options='dbpartition by hash(id) tbpartition by hash(id) tbpartitions 2'PolarDB-X 1.0支持拆分表,在建表的時候需要指定拆分方式。

示例命令

您可以使用如下命令進行對應操作:

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

sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp-tables-count=1 --report-interval=10 --oltp-table-size=10000000  --mysql-user=*** --mysql-password=*** --mysql-table-engine=innodb  --rand-init=on  --mysql-host=**** --mysql-port=*** --mysql-db=*** --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
            

執(zhí)行測試:

sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp-tables-count=1 --report-interval=10 --oltp-table-size=10000000  --mysql-user=*** --mysql-password=*** --mysql-table-engine=innodb  --rand-init=on  --mysql-host=**** --mysql-port=*** --mysql-db=*** --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
            

清理環(huán)境:

sysbench --test='/usr/local/share/sysbench/oltp.lua' --oltp-tables-count=1 --report-interval=10 --oltp-table-size=10000000  --mysql-user=*** --mysql-password=*** --mysql-table-engine=innodb  --rand-init=on  --mysql-host=**** --mysql-port=*** --mysql-db=*** --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