git項目地址:
https://github.com/akopytov/sysbench
利用sysbench很容易對mysql做性能基准測試(當然這個工具很強大,除了測試主流數據庫性能,還能測試其它方面,詳情自己看官網項目文檔)
mac上的用法:
一、安裝
brew install sysbench
二、先在mysql上創建一個專門的測試數據庫,比如test
三、利用sysbench先生成測試數據
sysbench --test=oltp --oltp-table-size=5000000 --oltp-table-name=t_test \ --mysql-table-engine=innodb \ --mysql-host=localhost \ --mysql-db=test \ --mysql-user=root \ --mysql-password=*** \ prepare
上面這一堆的意思,是在本機localhost的test數據庫的t_test中創建500萬條測試數據,表的數據庫引擎為innodb.
tips:如果想知道還有哪些參數可用,可輸入命令
sysbench --test=oltp help
centos上如果用yum install sysbench安裝的話,運行時可能會出現
FATAL: no database driver specified
FATAL: failed to initialize database driver!
可以加上參數 --db-driver=mysql ,原因是yum方式安裝時,同時安裝了mysql與其它數據庫的驅動,不指定驅動類型的話,sysbench不知道你是要測試是mysql,還是oracle之類的其它數據庫
四、運行測試
sysbench --test=oltp --oltp-table-size=5000000 --oltp-table-name=t_test \ --mysql-table-engine=innodb \ --mysql-host=localhost \ --mysql-db=test \ --mysql-user=root \ --mysql-password=*** \ run
最后一個prepare改成run就行了,測試完后,會輸出類似以下結果:
sysbench 0.4.12: multi-threaded system evaluation benchmark
No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 1
Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Threads started!
Done.
OLTP test statistics:
queries performed:
read: 140000
write: 50000
other: 20000
total: 210000
transactions: 10000 (514.48 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 190000 (9775.14 per sec.)
other operations: 20000 (1028.96 per sec.)
Test execution summary:
total time: 19.4371s
total number of events: 10000
total time taken by event execution: 19.3581
per-request statistics:
min: 1.65ms
avg: 1.94ms
max: 13.48ms
approx. 95 percentile: 2.34ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 19.3581/0.00
一般我們比較關心:
transactions: 10000 (514.48 per sec.)
read/write requests: 190000 (9775.14 per sec.)
這代表每秒能處理的事務數,以及每秒的讀寫次數。
五、清理測試數據
sysbench --test=oltp --oltp-table-size=5000000 --oltp-table-name=t_test \ --mysql-table-engine=innodb \ --mysql-host=localhost \ --mysql-db=test \ --mysql-user=root \ --mysql-password=*** \ cleanup
最后一個換成cleanup即可。
春晚實在太無聊了,還不如寫二行代碼有意思,祝各位園友猴年大吉,身體健康,心想事成!
