MySQL基準測試工具sysbench

markzy5201190發表於2013-11-06
MySQL基準測試工具sysbench

sysbench多執行緒效能測試工具,可以測試cpu/memory/IO/資料庫等效能。

2個版本sysbench0.4和sysbench0.5介紹:
我們先了解對資料庫OLTP測試:

sysbench --help

Usage:
sysbench [general-options]... --test= [test-options]... command  
--test:測試型別,有fileio/memory/threads/mutex.

sysbench0.5與sysbench0.4區別:0.5支援多表測試,執行實時列印統計資訊,自定義lua指令碼;
--test=
2者測試模組如下:
sysbench0.5:
Compiled-in tests:  
  fileio - File I/O test  
  cpu - CPU performance test  
  memory - Memory functions speed test  
  threads - Threads subsystem performance test  
  mutex - Mutex performance test  

sysbench0.5:
Compiled-in tests:  
  fileio - File I/O test  
  cpu - CPU performance test  
  memory - Memory functions speed test  
  threads - Threads subsystem performance test  
  mutex - Mutex performance test  
  oltp - OLTP test  #與0.5不同點

--general-options
每個模組對應的general-options可以藉助:
sysbench --test=oltp help
因0.4和0.5版本不同,但是基本引數是相容的;

--command
經歷prepare run cleaup
prepare:準備過程,oltp測試向表中load資料
run:正式測試過程
cleanup是清理過程,run後需要清理測試過程中遺留下來的資訊。

sysbench測試例項:
--prepare:
sysbench --test=/home/zbs/sysbench-0.5/sysbench/tests/db/parallel_prepare.lua  
--oltp_tables_count=1 
--oltp-table-size=$records 
--rand-init=on 
--num-threads=$thds 
--oltp-read-only=off 
--report-interval=10 
--rand-type=special 
--rand-spec-pct=5 
--mysql-table-engine=$type 
--max-time=8000 
--mysql-host=$host 
--mysql-port=$port  
--mysql-user=test 
--mysql-password=test 
--mysql-db=test1 
--max-requests=0  prepare

--run:
sysbench --test=/home/zbs/sysbench-0.5/sysbench/tests/db/parallel_prepare.lua  
--oltp_tables_count=1 
--oltp-table-size=$records 
--rand-init=on 
--num-threads=$thds 
--oltp-read-only=off 
--report-interval=10 
--rand-type=special 
--rand-spec-pct=5 
--mysql-table-engine=$type 
--max-time=8000 
--mysql-host=$host 
--mysql-port=$port  
--mysql-user=test 
--mysql-password=test 
--mysql-db=test1 
--max-requests=0  run

--cleanup:
sysbench --test=/home/zbs/sysbench-0.5/sysbench/tests/db/parallel_prepare.lua  
--oltp_tables_count=1 
--oltp-table-size=$records 
--rand-init=on 
--num-threads=$thds 
--oltp-read-only=off 
--report-interval=10 
--rand-type=special 
--rand-spec-pct=5 
--mysql-table-engine=$type 
--max-time=8000 
--mysql-host=$host 
--mysql-port=$port  
--mysql-user=test 
--mysql-password=test 
--mysql-db=test1 
--max-requests=0  cleanup

3者測試引數一致,不同的階段使用的引數不同;
引數瞭解:
--test:指定測試模式對應的lua檔案,這個裝好sysbench就有且這是0.5新增,0.4只需直接--test=oltp即可。  
--oltp_table_count=1:指定測試過程中表的個數,0.5新增,0.4整個測試過程只有一個表。  
--oltp-table-size=:指定表的大小,如果指定1000,那麼它會往表裡初始化1000條資料  
--rand-init=on:是否隨機初始化資料,如果不隨機化那麼初始好的資料每行內容除了主鍵不同外其他完全相同。  
--num-threads=:測試過程中併發執行緒數,看測試要求來定併發壓力。  
--otlp-read-only=off:知否只讀測試  
--report-interval=10:每隔多久列印一次統計資訊,單位秒,0.5新增  
--rand-type=special:資料分佈模式,special表示存在熱點資料,uniform表示非熱點資料模式,還有其他幾個選項。  
--rand-spec-pct=5:這個與上面那個選項相關
--mysql-table-engine=$type:表的儲存引擎型別,innodb/myisam/tokudb/這些都可以。  
--max-time=8000:這個命令跑多長時間,單位秒,與之相反的是指定請求數--max-requests  
--mysql-host=$host --mysql-port=$port  --mysql-user=test --mysql-password=test --mysql-db=test1  這幾個表示被測試的MySQL例項資訊,因為需要連資料庫  
--max-requests:可以兩者形式指定命令執行多長時間。  

綜上所述:
sysbench優點:
1.測試型別可以選擇
2.定製的引數選擇豐富
缺點:
1.測試表結構太簡單;
CREATE TABLE `sbtest1` (  
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
  `k` int(10) unsigned NOT NULL DEFAULT '0',  
  `c` char(120) NOT NULL DEFAULT '',  
  `pad` char(60) NOT NULL DEFAULT '',  
  PRIMARY KEY (`id`),  
  KEY `k_1` (`k`)  
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

有效僅有3個欄位,不能正式模擬線上應用,可以利用它來做指導測試,作為標準,
測試產品穩定性,抗壓性,mysql打補丁,更改引數,利用sysbench跑上幾天或更久
時間看起執行情況;

網頁摘錄














 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26855487/viewspace-775897/,如需轉載,請註明出處,否則將追究法律責任。

相關文章