1、sybench下載地址:http://sourceforge.net/projects/sysbench/?source=dlpmysql
2、sybench安裝:
# ./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=
/usr/local/mysql/lib 若是須要sysbench支持Oracle或者PostgreSQL的話,還須要在編譯時加上--with-pgsql或者--with-oracle
#make 出錯信息以下
../libtool: line 838: X--tag=CC: command not found
../libtool: line 871: libtool: ignoring unknown tag : command not found
../libtool: line 838: X--mode=link: command not found
../libtool: line 1004: *** Warning: inferring the mode of operation is deprecated.: command not found
../libtool: line 1005: *** Future versions of Libtool will require --mode=MODE be specified.: command not found
解決方法:
#make clean
#export echo=echo
# ./autogen.sh 對環境進行清理
若是出現: ./autogen.sh: line 3: aclocal: command not found
yum install automake perl libtool
#./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=
/usr/local/mysql/lib
#make && make installsql
3、sybench可測試內容:
Compiled-in tests:
fileio - File I/O test 文件IO測試
cpu - CPU performance test 性能測試
memory - Memory functions speed test 內存分配與傳輸速度測試
threads - Threads subsystem performance test 線程子系統性能測試
mutex - Mutex performance test 數據庫OLTP測試
oltp - OLTP test數據庫
1. CPU性能測試
sysbench --test=cpu --cpu-max-prime=5000 run
CPU的性能測試主要經過素數的運算來進行,--cpu-max-prime用來選項指定最大的素數,具體參數能夠根據CPU的性能來設置。服務器
2. 內存性能測試
sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run
--memory-block-size指定每一個block的大小,--memory-total-size指定總的傳輸量,另外還有其餘選項,可經過命令sysbench –test=memory help進行查看。併發
3. 磁盤I/O性能測試
首先生成須要測試的文件
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 prepare
而後執行測試
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 run
最後清理測試文件
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 cleanup
--num-threads指定最大建立的線程數,--file-num指定文件數目,--file-taotal-size指定建立的文件總大小,--file-test-mode指定文件讀寫模式,rndrw爲隨機讀,--file-rw-ratio指定讀寫比率。另外還有更多的選項能夠經過命令sysbench –test=fileio help進行查看。
4. 線程測試oracle
sysbench --test=threads --num-threads=32 --thread-yields=100 --thread-locks=2 run
--num-threads指定線程數,--thread-yield指定每一個請求的壓力,--thread-locks指定每一個線程的鎖數量。
5. 數據庫性能測試app
注意:在高於100時的併發量時 不要用 --oltp-skip-trx=on 不然有可能出現Duplicate entry 'xxx' for key 'PRIMARY錯誤socket
參數說明:
--mysql-host指定使用的MySQL服務器的地址,
--mysql-user指定鏈接MySQL的用戶名,
--mysql-password指定密碼,
--mysql-db指定使用的數據庫,
--oltp-table-name指定使用的表,
--mysql-table-engine指定表所使用的數據庫引擎,
--mysql-engine-trx說明使用的數據庫引擎是不是事務的,
--oltp-skip-trx指定是否忽略事務語句(BEGIN/COMMIT),
--oltp-table-size指定數據表中的記錄數,
--max-requests指定最大請求數,默認爲10000
--num-threads指定線程數,默認爲1
--max-time 測試執行時間
--oltp_table_count=1:指定測試過程當中表的個數ide
1) 生成10000行記錄測試數據,建立oltp數據庫或者使用–mysql-db指定一個已經存在的數據庫
sysbench --test=oltp --mysql-host=localhost --db-driver=mysql --mysql-db=oltp --oltp-table-name=sbtest0606 --oltp-table-size=10000 --mysql-user=user1 --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock prepare性能
2) 測試5分鐘(命令運行時間)或者【指定最大請求數1500跑完爲止】
sysbench --test=oltp --mysql-host=localhost --db-driver=mysql --mysql-db=oltp --oltp-table-name=sbtest0606 --oltp-table-size=10000 --max-requests=1500 --mysql-user=user1 --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock run
【--max-time=300】【--max-requests=1500】【--num-threads=16】
測試結果:
Maximum number of requests for OLTP test is limited to 1500
Threads started!
Done.
OLTP test statistics: 查詢統計
queries performed:
read: 21084 讀操做x次
write: 7517 寫操做x次
other: 3006 其它操做x次
total: 31607 總操做x次
#—-事務數總計,每秒的事務處理量
transactions: 1500 (407.09 per sec.) 總事務/請求 (每秒事務數)可看做是TPS的性能指標
deadlocks: 6 (1.63 per sec.)
read/write requests: 28601 (7762.06 per sec.) 讀寫請求read+write (每秒處理I/O請求次數)可看做是IOPS性能指標
other operations: 3006 (815.80 per sec.)
Test execution summary:
total time: 3.6847s 總執行時間
total number of events: 1500
total time taken by event execution: 182.6919
#—-每一個請求的統計信息
per-request statistics:
min: 6.12ms 最小
avg: 121.79ms 單次執行的平均響應時間
max: 378.37ms 單次執行中最長響應時間
approx. 95 percentile: 197.95ms 95%的百分比響應時間分佈
#—-線程權重信息,工做負荷如何被均勻分配
Threads fairness: 線程公平性統計信息(thread-fairness),用於表示模擬負載的公平性
events (avg/stddev): 30.0000/1.28
execution time (avg/stddev): 3.6538/0.02
3. 刪除測試數據
sysbench --test=oltp --mysql-host=localhost --db-driver=mysql --mysql-db=oltp --oltp-table-name=sbtest0606 --oltp-table-size=10000 --max-requests=1500 --mysql-user=user1 --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock cleanup
說明: sysbench測試自動生成的隨機字段值: +----+---+---+----------------------------------------------------+ | id | k | c | pad | +----+---+---+----------------------------------------------------+ | 10 | 0 | | qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt | +----+---+---+----------------------------------------------------+ 一個事務是指一個客戶機向服務器發送請求而後服務器作出反應的過程。客戶機在發送請求時開始計時,收到服務器響應後結束計時,以此來計算使用的時間和完成的事務個數。 系統吞度量 承壓能力QPS(TPS) 在DB中一般TPS:Transactions Per Second(每秒傳輸的事物處理個數),即服務器每秒處理的事務數。INNODB 引擎 QPS:Query per second(每秒處理的查詢數)MyISAM 引擎,也即每秒的響應請求數 IOPS 每秒磁盤進行的I/O操做次數