一、介紹
- SysBench 是一款開源的、跨平臺(tái)的、模塊化的、多線程的性能測(cè)試工具, 可以執(zhí)行 CPU/內(nèi)存/線程/IO/數(shù)據(jù)庫 等方面的性能測(cè)試
二、安裝 sysbench
- yum -y install sysbench
- 安裝完sysbench后,/usr/share/sysbench下對(duì)數(shù)據(jù)庫壓力測(cè)試的lua文件
- lua腳本說明
1、 bulk_insert.lua 批量寫入操作 2、 oltp_common.lua oltp公用代碼 3、 oltp_delete.lua 寫入和刪除并行操作 4、 oltp_insert.lua 純寫入操作 5、 oltp_point_select.lua 只讀操作,條件為唯一索引列 6、 oltp_read_only.lua 只讀操作,包含聚合,去重等操作 7、 oltp_read_write.lua 讀寫混合操作,最常用的腳本 8、 oltp_update_index.lua 更新操作,通過主鍵進(jìn)行更新 9、 oltp_update_non_index.lua 更新操作,不通過索引列 10、 oltp_write_only.lua 純寫操作,常用腳本,包括insert update delete 11、 select_random_points.lua 隨機(jī)集合只讀操作,常用腳本,聚集索引列的selete in操作 12、 select_random_ranges.lua 隨機(jī)范圍只讀操作,常用腳本,聚集索引列的selete between操作
- 參數(shù)說明
-–db-driver:用到的數(shù)據(jù)庫類型 -–MySQL-host:數(shù)據(jù)庫的IP -–mysql-port:數(shù)據(jù)庫的端口 -–mysql-socket:socket的路徑 -–mysql-user:數(shù)據(jù)庫用戶名 -–mysql-password:用戶密碼 -–mysql-db:數(shù)據(jù)庫名字,默認(rèn)為sysbench,需要提前創(chuàng)建創(chuàng)好 -–tables:生成表的個(gè)數(shù) -–table-size:每個(gè)表的行數(shù) -–report-interval:每隔多久在屏幕打印一次信息 -–time:壓測(cè)時(shí)間 -–threads:啟動(dòng)多少個(gè)線程,即模擬多少個(gè)用戶
- 幫助命令 sysbench /usr/share/sysbench/oltpreadwrite.lua help
oltp_read_write.lua options: --auto_inc[=on|off] Use AUTO_INCREMENT column as Primary Key (for MySQL), or its alternatives in other DBMS. When disabled, use client-generated IDs [on] --create_secondary[=on|off] Create a secondary index in addition to the PRIMARY KEY [on] --delete_inserts=N Number of DELETE/INSERT combinations per transaction [1] --distinct_ranges=N Number of SELECT DISTINCT queries per transaction [1] --index_updates=N Number of UPDATE index queries per transaction [1] --mysql_storage_engine=STRING Storage engine, if MySQL is used [innodb] --non_index_updates=N Number of UPDATE non-index queries per transaction [1] --order_ranges=N Number of SELECT ORDER BY queries per transaction [1] --pgsql_variant=STRING Use this PostgreSQL variant when running with the PostgreSQL driver. The only currently supported variant is 'redshift'. When enabled, create_secondary is automatically disabled, and delete_inserts is set to 0 --point_selects=N Number of point SELECT queries per transaction [10] --range_selects[=on|off] Enable/disable all range SELECT queries [on] --range_size=N Range size for range SELECT queries [100] --secondary[=on|off] Use a secondary index in place of the PRIMARY KEY [off] --simple_ranges=N Number of simple range SELECT queries per transaction [1] --skip_trx[=on|off] Don't start explicit transactions and execute all queries in the AUTOCOMMIT mode [off] --sum_ranges=N Number of SELECT SUM() queries per transaction [1] --table_size=N Number of rows per table [10000] --tables=N Number of tables [1]
數(shù)據(jù)庫壓力測(cè)試通常三個(gè)階段,準(zhǔn)備數(shù)據(jù)、壓測(cè)數(shù)據(jù)、清理數(shù)據(jù)
- 第一階段數(shù)據(jù)準(zhǔn)備
mysql -uroot -p123 -e "create database sbtest;" -- 創(chuàng)建測(cè)試數(shù)據(jù)庫 sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --threads=4 prepare
登錄數(shù)據(jù)庫檢查生成表和數(shù)據(jù)情況
- 第二階段數(shù)據(jù)運(yùn)行測(cè)試
情況1:查詢 sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --report-interval=10 --threads=128 --time=600 ru
備注:重要指標(biāo)
QPS(Query per second) 每秒查詢量:21021.78
TPS(Transaction per second)每秒事務(wù)量 1052.19
情況2: 在每個(gè)查詢的事物里面添加 INSERT/UPDATE/DELDETE 操作 sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --delete_inserts=10 --index_updates=10 --non_index_updates=10 --report-interval=10 --threads=4 --time=60 run
- 第三階段刪除測(cè)試數(shù)據(jù)
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --delete_inserts=10 --index_updates=10 --non_index_updates=10 --report-interval=10 --threads=4 --time=60 cleanup
- 注一個(gè)錯(cuò)誤處理(修改自己安裝mysql對(duì)應(yīng)socket文件)






