出自:https://www.cnblogs.com/hally/p/8360637.htmlhtml
sysbench是一款壓力測試工具,能夠測試系統的硬件性能,也能夠用來對數據庫進行基準測試mysql
wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0.zip" 下載以後的名字是1.0.zip。解壓以後爲sysbench-1.0linux
百度雲網盤:https://pan.baidu.com/s/1mjoa25y 密碼:i4pmgit
cd sysbench-1.0github
執行autogen.sh用它來生成configure這個文件sql
./autogen.sh
執行configure && make && make install 來完成sysbench的安裝數據庫
./configure && make && make install 這個命令是用於mysql默認的安裝路徑
./configure --prefix=/usr/local/sysbench/ --with-mysql --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib 這個是用於指定mysql安裝的路徑(個人mysql是默認路徑,因此我用第一種)
固然了,用上面的參數編譯的話,就要確保你的 MySQL lib目錄下有對應的 so 文件,若是沒有,能夠本身下載 devel 或者 share 包來安裝。
另外,若是想要讓 sysbench 支持 pgsql/oracle 的話,就須要在編譯的時候加上參數
--with-pgsql
或者
--with-oracle
這2個參數默認是關閉的,只有 MySQL 是默認支持的
執行以後出現這個錯誤
這是缺乏MySQL頭文件和庫文件centos
centos6用:服務器
yum install MySQL-shared 併發
yum install MySQL-devel
centos7用:
yum install -y Percona-XtraDB-Cluster-shared-56.x86_64
yum install -y Percona-XtraDB-Cluster-devel-56
從新 ./configure && make && make install
測試:sysbench cpu --cpu-max-prime=10000 run
出現這個就是成功
sysbench支持如下幾種測試模式:
一、CPU運算性能 二、磁盤IO性能 三、調度程序性能 四、內存分配及傳輸速度 五、POSIX線程性能 六、數據庫性能(OLTP基準測試) 目前sysbench主要支持 mysql,drizzle,pgsql,oracle 等幾種數據庫。
3、OLTP測試前準備
初始化測試庫環境(總共10個測試表,每一個表 100000 條記錄,填充隨機生成的數據):
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 表示調用 tests/db/oltp.lua 腳本進行 oltp 模式測試 --oltp_tables_count=10 表示會生成 10 個測試表 --oltp-table-size=100000 表示每一個測試表填充數據量爲 100000 --rand-init=on 表示每一個測試表都是用隨機數據來填充的
若是在本機,也能夠使用 –mysql-socket 指定 socket 文件來鏈接。加載測試數據時長視數據量而定,若過程比較久須要稍加耐心等待。
真實測試場景中,數據表建議不低於10個,單表數據量不低於500萬行,固然了,要視服務器硬件配置而定。若是是配備了SSD或者PCIE SSD這種高IOPS設備的話,則建議單表數據量最少不低於1億行。
4、進行OLTP測試
在上面初始化數據參數的基礎上,再增長一些參數,便可開始進行測試了:
./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 表示隨機類型爲固定模式,其餘幾個可選隨機模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累託) --max-time=120 表示最大執行時長爲 120秒 --max-requests=0 表示總請求數爲 0,由於上面已經定義了總執行時長,因此總請求數能夠設定爲 0;也能夠只設定總請求數,不設定最大執行時長 --percentile=99 表示設定採樣比例,默認是 95%,即丟棄1%的長請求,在剩餘的99%裏取最大值
即:模擬 對10個表併發OLTP測試,每一個表1000萬行記錄,持續壓測時間爲 1小時。
真實測試場景中,建議持續壓測時長不小於30分鐘,不然測試數據可能不具參考意義
5、測試結果解讀:
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 8 Report intermediate results every 10 second(s) Random number generator seed is 0 and will be ignored Threads started! -- 每10秒鐘報告一次測試結果,tps、每秒讀、每秒寫、99%以上的響應時長統計 [ 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%) [ 30s] threads: 8, tps: 1120.00, reads/s: 15679.10, writes/s: 4480.20, response time: 9.84ms (99%) [ 40s] threads: 8, tps: 1114.20, reads/s: 15599.39, writes/s: 4456.30, response time: 9.90ms (99%) [ 50s] threads: 8, tps: 1114.00, reads/s: 15593.60, writes/s: 4456.70, response time: 9.84ms (99%) [ 60s] threads: 8, tps: 1119.30, reads/s: 15671.60, writes/s: 4476.50, response time: 9.99ms (99%) OLTP test statistics: queries performed: read: 938224 -- 讀總數 write: 268064 -- 寫總數 other: 134032 -- 其餘操做總數(SELECT、INSERT、UPDATE、DELETE以外的操做,例如COMMIT等) total: 1340320 -- 所有總數 transactions: 67016 (1116.83 per sec.) -- 總事務數(每秒事務數) deadlocks: 0 (0.00 per sec.) -- 發生死鎖總數 read/write requests: 1206288 (20103.01 per sec.) -- 讀寫總數(每秒讀寫次數) other operations: 134032 (2233.67 per sec.) -- 其餘操做總數(每秒其餘操做次數) General statistics: -- 一些統計結果 total time: 60.0053s -- 總耗時 total number of events: 67016 -- 共發生多少事務數 total time taken by event execution: 479.8171s -- 全部事務耗時相加(不考慮並行因素) response time: -- 響應時長統計 min: 4.27ms -- 最小耗時 avg: 7.16ms -- 平均耗時 max: 13.80ms -- 最長耗時 approx. 99 percentile: 9.88ms -- 超過99%平均耗時 Threads fairness: events (avg/stddev): 8377.0000/44.33 execution time (avg/stddev): 59.9771/0.00
其餘信息能夠參考這個鏈接:
http://www.linuxidc.com/Linux/2017-04/142856.htm
實時操做:
/usr/local/bin/sysbench oltp_common --mysql-host=10.1.18.74 --mysql-port=3306 --table-size=1000000 --db-driver=mysql --mysql-db=test --mysql-user=root--mysql-password=root prepare 此命令用來生成表
oltp_common #生成庫的腳本
--mysql-db=test#指定庫
prepare #運行的命令
--oltp_tables_count=10 用來指定生成多少張表
/usr/local/bin/sysbench oltp_read_only --mysql-host=10.1.18.74 --mysql-port=3306 --table-size=1000 --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=root --time=10 --max-requests=0 --threads=8 run 這是運行
oltp_read_only #指定只讀腳本
--mysql-db=test #指定運行的庫
--threads=8 #指定併發鏈接數
run #運行指令
/usr/local/bin/sysbench oltp_write_only --mysql-host=10.1.18.74 --mysql-port=3306 --table-size=1000 --db-driver=mysql --mysql-db=test --mysql-user=hairong.cao --mysql-password=hairong.cao --time=10 --max-requests=0 --threads=8 run
oltp_write_only #指定只寫腳本
生成表:
/usr/local/bin/sysbench tests/include/oltp_legacy/oltp.lua --mysql-host=10.1.18.74 --mysql-port=3306 --oltp_tables_count=8 --table-size=10000000 --db-driver=mysql --mysql-db=test --mysql-user=hairong.cao --mysql-password=hairong.cao prepare
混合場景壓測:
/usr/local/bin/sysbench tests/include/oltp_legacy/oltp.lua --mysql-host=10.1.18.74 --mysql-port=3306 --table-size=10000000 --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=root --oltp_tables_count=8 --max-requests=0 --threads=32 --oltp-read-olny=off --report-interval=10 --percentile=99 --max-time=3600 run >> ./logs/baidu.log
cpu測試:
/usr/local/bin/sysbench --test=cpu --num-threads=40 --max-requests=10000 --cpu-max-prime=20000 run
IO測試:
生成測試文件; /usr/local/bin/sysbench --test=fileio --file-num=10 --file-total-size=5G prepare 表示生成10個5G的文件
運行測試: /usr/local/bin/sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --max-requests=5000 --num-threads=16 --file-num=10 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
參數說明: --max-requests=5000 表示5000請求量
--num-threads=16 16個線程
File operations:
reads/s: 1791.40 表示每秒讀的次數
writes/s: 1188.31 表示每秒寫的次數
fsyncs/s: 5.96 表示每秒從內存向磁盤同步的次數
Throughput:read, MiB/s: 27.99 這裏表示讀的帶寬written, MiB/s: 18.57 這裏表示寫的帶寬