祖仙教小凡仙 海鯊數據庫架構師mysql
下載: https://codeload.github.com/akopytov/sysbench/zip/master
解壓
unzip sysbench-master.zip
編譯
sh autogen.sh git
./configure --perfix=/u01/sysbench --with-mysql=/u01/mysqlsoft/mysql --with-mysql-includes=/u01/mysqlsoft/mysql/include --with-mysql-libs=/u01/mysqlsoft/mysql/lib && make && make install 那麼就須要本身指定 MySQL 的路徑了。好比個人 MySQL 喜歡本身安裝在 /usr/local/mysql 下,則按照如下方法編譯: ./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install 固然了,用上面的參數編譯的話,就要確保你的 MySQL lib目錄下有對應的 so 文件,若是沒有,能夠本身下載 devel 或者 share 包來安裝。 另外,若是想要讓 sysbench 支持 pgsql/oracle 的話,就須要在編譯的時候加上參數 --with-pgsql 或者 --with-oracle 這2個參數默認是關閉的,只有 MySQL 是默認支持的。 若是報錯 cp /u01/mysqlsoft/mysql/lib/libmysqlclient.so.20 /lib64 運行一下 [root@MYSQL-MASTER sysbench-master]# sysbench sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) Reading the script from the standard input: 一、通用選項: General options: # 通用選項 --threads=N 要使用的線程數,默認 1 個 [1] --events=N 最大容許的事件個數,默認爲[0] --time=N 最大的總執行時間,以秒爲單位默認爲[10] --thread-stack-size=SIZE 每一個線程的堆棧大小,默認爲[64K] --rate=N 指定數量多少事件(事務)平均每秒鐘應該執行的全部線程。0(默認)意味着無限的速率,即事件儘快執行 --report-interval=N 以秒爲單位按期報告具備指定間隔的中間統計信息, 0 禁用中間報告,默認爲0 --debug[=on|off] 打印更多 debug 信息 [off] --validate[=on|off] 儘量執行驗證檢查 [off] --help[=on|off] 顯示幫助信息並退出 [off] --version[=on|off] 顯示版本信息並退出 [off] --config-file=FILENAME 包含命令行選項的文件 --tables=N 表數量(數據庫測試) --table-size=N 表大小 --tx-rate=N 廢棄,改用 --rate [0] --max-requests=N 廢棄,改用 --events [0] --max-time=N 廢棄,改用 --time [0] --num-threads=N 廢棄,改用 --threads [1] 2 數據庫專用選項: mysql options: # MySQL 數據庫專用選項 --mysql-host=[LIST,...] MySQL server host [localhost] --mysql-port=[LIST,...] MySQL server port [3306] --mysql-socket=[LIST,...] MySQL socket --mysql-user=STRING --mysql-password=STRING --mysql-db=STRING --mysql-ssl[=on|off] --mysql-ssl-cipher=STRING --mysql-compression[=on|off] --mysql-debug[=on|off] --mysql-ignore-errors=[LIST,...] --mysql-dry-run[=on|off] pgsql options: # PostgreSQL 數據庫專用選項 --pgsql-host=STRING --pgsql-port=N --pgsql-user=STRING --pgsql-password=STRING --pgsql-db=STRING 三、腳本: 默認放在/usr/share/sysbench/,有以下腳本 個人放在/u01/sysbench/share/sysbench/ bulk_insert.lua; oltp_delete.lua; oltp_point_select.lua; oltp_read_write.lua; oltp_update_non_index.lua; select_random_points.lua; oltp_common.lua; oltp_insert.lua; oltp_read_only.lua; oltp_update_index.lua; oltp_write_only.lua; select_random_ranges.lua 3、測試: 這裏僅作數據庫測試,其餘測試能夠是用sysbench –help,sysbench cpu help等查看相應參數。 流程:一、建測試表及數據;二、進行測試;3清除數據。(一、prepare;二、run;三、cleanup) 一、 建測試表及數據: 線程,數據表大小及數量及其餘參數按需求修改便可 編輯個SHELL來預備階段 [root@MYSQL-MASTER u01]# cat TEST_MYSQL_USE_SYSBENCH.sh sysbench /u01/sysbench/share/sysbench/oltp_read_write.lua --time=60 --mysql-host=192.168.2.21 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=MGR_TEST --table-size=10000 --tables=2 --threads=2 prepare 這些參數比較簡單,沒法是腳本在哪裏? IP 端口 用戶 密碼 數據庫(SCHMA) 幾個表 多少行數據 幾個線程 之類的. 運行測試程序預備階段 [root@MYSQL-MASTER u01]# sh TEST_MYSQL_USE_SYSBENCH.sh sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) Initializing worker threads... Creating table 'sbtest1'... Creating table 'sbtest2'... Inserting 10000 records into 'sbtest1' Inserting 10000 records into 'sbtest2' Creating a secondary index on 'sbtest1'... Creating a secondary index on 'sbtest2'... 在第二個節點上看到新建了兩個表 Database changed mysql> show tables; +--------------------+ | Tables_in_MGR_TEST | +--------------------+ | t1 | +--------------------+ 1 row in set (0.00 sec) mysql> show tables; +--------------------+ | Tables_in_MGR_TEST | +--------------------+ | sbtest1 | | sbtest2 | | t1 | +--------------------+ 3 rows in set (0.00 sec) 二、 測試數據: [root@MYSQL-MASTER u01]# cat sysbench_mysql_run.sh sysbench /u01/sysbench/share/sysbench/oltp_read_write.lua --time=60 --mysql-host=192.168.2.21 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=MGR_TEST --table-size=10000 --tables=2 --threads=2 run ##建兩個表,每一個表1萬行,兩個線程,最大執行60秒 [root@MYSQL-MASTER u01]# sh sysbench_mysql_run.sh sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) Running the test with following options: Number of threads: 2 Initializing random number generator from current time Initializing worker threads... Threads started! SQL statistics: queries performed: read: 1428 --讀總數 write: 189 --寫總數 other: 423 --其餘操做 total: 2040 --所有操做總數 transactions: 102 (1.66 per sec.)--總事務數102,每秒1.66 queries: 2040 (33.30 per sec.)--查詢數 ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) Throughput: events/s (eps): 1.6649 --每秒事件 time elapsed: 61.2632s total number of events: 102 Latency (ms): min: 510.65 --最小響應實際 avg: 1191.67 --平均 max: 2441.14 --最大 95th percentile: 2082.91 --超過95%平均耗時 sum: 121549.92 --總計 Threads fairness: events (avg/stddev): 51.0000/1.00 --總處理事件 execution time (avg/stddev): 60.7750/0.49 --總執行時間 --感受每秒事務支持好少...... 不太理想 三、 清洗數據: sysbench /u01/sysbench/share/sysbench/oltp_read_write.lua --time=60 --mysql-host=192.168.2.21 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=MGR_TEST --table-size=10000 --tables=2 --threads=2 cleanup [root@MYSQL-MASTER u01]# sh sysbench_mysql_clear.sh sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) Dropping table 'sbtest1'... Dropping table 'sbtest2'...