Sysbench 是模組化、跨平台、多執行緒基準測試工具,支援 CPU、磁碟 I/O、記憶體、執行緒、資料庫(OLTP)等測試模式。支援 MySQL、Drizzle、PostgreSQL、Oracle。
專案地址:https://launchpad.net/sysbench
# 安裝 bzr 客戶端
rpm -Uvh https://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum install bzr
# 下載源碼
cd /tmp
bzr branch lp:sysbench
cd /tmp/sysbench-0.4.12-1.1
./autogen.sh
./configure --with-mysql-includes=/usr/local/mysql/include \
--with-mysql-libs=/usr/local/mysql/lib
make
成功後產生 sysbench 執行檔(~3.3MB)。
cd /tmp/sysbench-0.4.12-1.1/sysbench
mysqladmin create sbtest
./sysbench --mysql-host=1.2.3.4 --mysql-port=3317 \
--mysql-user=tpcc --mysql-password=tpcc \
--test=tests/db/oltp.lua \
--oltp_tables_count=10 \
--oltp-table-size=100000 \
--rand-init=on \
prepare
| 參數 | 含義 |
|---|---|
--test=tests/db/oltp.lua |
使用 OLTP 測試腳本 |
--oltp_tables_count=10 |
建立 10 張測試表 |
--oltp-table-size=100000 |
每表 10 萬行資料 |
--rand-init=on |
隨機資料填充 |
💡 實戰建議:表數 ≥ 10,單表 ≥ 500 萬行;SSD/PCIe SSD 環境建議單表 ≥ 1 億行。
./sysbench --mysql-host=1.2.3.4 --mysql-port=3306 \
--mysql-user=tpcc --mysql-password=tpcc \
--test=tests/db/oltp.lua \
--oltp_tables_count=10 \
--oltp-table-size=10000000 \
--num-threads=8 \
--oltp-read-only=off \
--report-interval=10 \
--rand-type=uniform \
--max-time=3600 \
--max-requests=0 \
--percentile=99 \
run >> ./log/sysbench_oltpX_8_20140921.log
| 參數 | 含義 |
|---|---|
--num-threads=8 |
8 個並發連線 |
--oltp-read-only=off |
讀寫混合模式 |
--report-interval=10 |
每 10 秒輸出一次報告 |
--rand-type=uniform |
均勻分佈隨機(可選 gaussian/special/pareto) |
--max-time=3600 |
壓測 1 小時 |
--max-requests=0 |
不限總請求數(由時間控制) |
--percentile=99 |
99 百分位響應時間 |
💡 建議壓測時長 **≥ 30 分鐘**,否則結果參考價值有限。
[ 10s] threads: 8, tps: 1111.51, reads/s: 15568.42, writes/s: 4446.13, response time: 9.95ms (99%)
[ 20s] threads: 8, tps: 1121.90, reads/s: 15709.62, writes/s: 4487.80, response time: 9.78ms (99%)
...
OLTP test statistics:
queries performed:
read: 938224
write: 268064
other: 134032
total: 1340320
transactions: 67016 (1116.83 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 1206288 (20103.01 per sec.)
General statistics:
total time: 60.0053s
total number of events: 67016
response time:
min: 4.27ms
avg: 7.16ms
max: 13.80ms
approx. 99 percentile: 9.88ms