sysbench對數據庫的性能測試

一、sybench下載地址:http://sourceforge.net/projects/sysbench/?source=dlp

二、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 install


三、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. 線程測試

sysbench --test=threads --num-threads=32 --thread-yields=100 --thread-locks=2 run
--num-threads指定線程數,--thread-yield指定每個請求的壓力,--thread-locks指定每個線程的鎖數量。
5. 數據庫性能測試

注意:在高於100時的併發量時 不要用 --oltp-skip-trx=on 否則有可能出現Duplicate entry 'xxx' for key 'PRIMARY錯誤

參數說明:
--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:指定測試過程中表的個數

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操作次數             

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章