為什么要壓力測試
采購新設備,評估新設備性能
開發新項目,評估數據庫容量
新系統上線前,預估/模擬數據庫負載
更換數據庫版本,評估性能變化
關注指標
CPU %wait,%user,%sys 內存 只內存讀寫,不產生swap IO IOPS、 iowait、 svctm、 %util 數據庫 TPS/TpmC、吞吏量(QPS)、響應時長、 InnoDB指標 影響因素 硬件 – CPU(省電模式、超線程、多核) – 內存(鏡像模式、 xen內核限制可用總內存大小) – 陣列卡(BBU、 CACHE、條帶、讀寫策略、 FW) – 硬盤(SSD/SAS) 系統 – 內核參數(tcp相關) – 文件系統 – IO調度器 MySQL – TRANSACTION ISOLATION LEVEL – Buffer pool – Concurrency thread – Redo log – Binlog sync – innodb_flush_log_at_trx_commit
---- 可靠性測試 模擬意外事件 – 斷電(硬件冷重啟) – RESET(硬件熱重啟) – 陣列卡掉線 – 磁盤掉線 – REBOOT(系統重啟) – 正常關閉服務(kill -TERM) – 異常關閉服務(kill -9) – 磁盤空間滿 – 刪除文件 – 破壞性修改已打開文件 – … 長期極限高壓 – 持續數小時、數天、數周運行高負載計算、 IO任務 – 考驗服務器在高壓下的性能波勱情況 – 考驗硬件設備在高壓下的穩定性表現 模擬惡劣環境 – 供電不穩 – 通風冷卻不好 – 濕氣大、灰塵多
注意事項
只在本地加壓
壓測數據量小
壓測時間過短
壓測模式太少
壓力負載過大或過小
每輪測試完畢要凈化環境
測試工具 sysbench,tpcc-mysql
# unzip sysbench-0.5.zip yum install automake libaio libaio-devel libtool -y -----LOAD,CPU,QPS,TPS,CONNECT,IO,NET/IN,NET/OUT [root@mysql5635 proc]# more loadavg 0.00 0.01 0.05 1/221 8408 [root@mysql5635 proc]# cat /proc/cpuinfo tar xvfz sysbench-0.4.12-1.1.tgz ./autogen.sh ./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install --cpu性能測試 ./sysbench --help ./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory [root@mysql5635 sysbench]# ls /usr/local/mysql/lib/|grep libmysqlclient.so.18 libmysqlclient.so.18 libmysqlclient.so.18.1.0 [root@mysql5635 sysbench]# echo "/usr/local/mysql/lib" >>/etc/ld.so.conf [root@mysql5635 sysbench]# ldconfig drivers/mysql/libsbmysql.a -L/usr/local/mysql/lib -lmysqlclient_r scripting/lua/src/liblua.a -ldl -lrt -laio -lm -pthread /usr/bin/ld: cannot find -lmysqlclient_r
fileio - 文件 I/O測試
cpu - CPU系能測試
memory - 內存功能速度測試
threads - 線程子系統系能測試
mutex - 互斥性能測試
運行 – sysbench --test=[mode] [other_options] prepare – sysbench --test=[mode] [other_options] run – sysbench --test=[mode] [other_options] cleanup 通用基准 – 最大請求數:5,000,000 – 並發線程數:8 ~ 512 基准 – OLTP – mode=complex – engine=innodb – oltp-table-size=100,000,000 sysbench支持以下幾種測試模式: 1、CPU運算性能 2、磁盤IO性能 3、調度程序性能 4、內存分配及傳輸速度 5、POSIX線程性能 6、數據庫性能(OLTP基准測試)
測試用例
初始化測試庫環境(總共10個測試表,每個表 100000 條記錄,填充隨機生成的數據)
./sysbench --mysql-host=127.0.0.1 --mysql-port=3317 --mysql-user=tpcc --mysql-password=*** \
--test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on prepare
--test=tests/db/oltp.lua 表示調用 tests/db/oltp.lua 腳本進行 oltp 模式測試 --oltp_tables_count=10 表示會生成 10 個測試表 --oltp-table-size=100000 表示每個測試表填充數據量為 100000 --rand-init=on 表示每個測試表都是用隨機數據來填充的 真實測試場景中,數據表建議不低於10個,單表數據量不低於500萬行,當然了,要視服務器硬件配置而定。如果是配備了SSD或者PCIE SSD這種高IOPS設備的話,則建議單表數據量最少不低於1億行。
在上面初始化數據參數的基礎上,再增加一些參數,即可開始進行測試了:
./sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=tpcc \ --mysql-password=**** --test=tests/db/oltp.lua --oltp_tables_count=10 \ --oltp-table-size=10000000 --num-threads=8 --oltp-read-only=off \ --report-interval=10 --rand-type=uniform --max-time=3600 \ --max-requests=0 --percentile=99 run >> /tmp/2017080101.log
--num-threads=8 表示發起 8個並發連接 --oltp-read-only=off 表示不要進行只讀測試,也就是會采用讀寫混合模式測試 --report-interval=10 表示每10秒輸出一次測試進度報告 --rand-type=uniform 表示隨機類型為固定模式,其他幾個可選隨機模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托) --max-time=120 表示最大執行時長為 120秒 --max-requests=0 表示總請求數為 0,因為上面已經定義了總執行時長,所以總請求數可以設定為 0;也可以只設定總請求數,不設定最大執行時長 --percentile=99 表示設定采樣比例,默認是 95%,即丟棄1%的長請求,在剩余的99%里取最大值 即:模擬 對10個表並發OLTP測試,每個表1000萬行記錄,持續壓測時間為 1小時。 真實測試場景中,建議持續壓測時長不小於30分鍾,否則測試數據可能不具參考意義。
--oltp測試
--創建db
mysql> create database sbtest;
/data/soft/sysbench-0.5/sysbench/sysbench --test=/data/soft/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=5000000 \ --mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \ --max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 prepare /data/soft/sysbench-0.5/sysbench/sysbench --test=/data/soft/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=5000000 \ --mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \ --max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 run >> /home/mysql/sysbench_20180806.log
測試結果解讀如下:
[root@mysql5635 sysbench]# cat /home/mysql/sysbench.log sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 8 Report intermediate results every 10 second(s) Random number generator seed is 0 and will be ignored Threads started! -- 每10秒鍾報告一次測試結果,tps、每秒讀、每秒寫、99%以上的響應時長統計 [ 10s] threads: 8, tps: 194.81, reads/s: 2737.20, writes/s: 780.05, response time: 206.36ms (99%) [ 20s] threads: 8, tps: 213.60, reads/s: 2991.02, writes/s: 856.40, response time: 176.82ms (99%) [ 30s] threads: 8, tps: 233.90, reads/s: 3274.61, writes/s: 934.00, response time: 111.08ms (99%) [ 40s] threads: 8, tps: 224.40, reads/s: 3141.18, writes/s: 899.19, response time: 87.77ms (99%) [ 50s] threads: 8, tps: 229.70, reads/s: 3215.82, writes/s: 916.01, response time: 138.09ms (99%) [ 60s] threads: 8, tps: 238.98, reads/s: 3346.58, writes/s: 957.24, response time: 70.88ms (99%) [ 70s] threads: 8, tps: 225.50, reads/s: 3156.95, writes/s: 901.19, response time: 97.78ms (99%) [ 80s] threads: 8, tps: 232.51, reads/s: 3255.48, writes/s: 931.25, response time: 105.51ms (99%) [ 90s] threads: 8, tps: 230.79, reads/s: 3230.76, writes/s: 921.56, response time: 117.30ms (99%) [ 100s] threads: 8, tps: 232.91, reads/s: 3259.58, writes/s: 932.15, response time: 121.99ms (99%) [ 110s] threads: 8, tps: 244.60, reads/s: 3422.53, writes/s: 979.41, response time: 80.64ms (99%) [ 120s] threads: 8, tps: 234.39, reads/s: 3284.13, writes/s: 936.05, response time: 87.45ms (99%) OLTP test statistics: queries performed: read: 383124-- 讀總數 write: 109464-- 寫總數 other: 54732-- 其他操作總數(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等) total: 547320-- 全部總數 transactions: 27366 (227.99 per sec.)-- 總事務數(每秒事務數) deadlocks: 0 (0.00 per sec.)-- 發生死鎖總數 read/write requests: 492588 (4103.90 per sec.)-- 讀寫總數(每秒讀寫次數) other operations: 54732 (455.99 per sec.)-- 其他操作總數(每秒其他操作次數) General statistics:-- 一些統計結果 total time: 120.0291s-- 總耗時 total number of events: 27366- 共發生多少事務數 total time taken by event execution: 959.7161s-- 所有事務耗時相加(不考慮並行因素) response time:-- 響應時長統計 min: 5.35ms-- 最小耗時 avg: 35.07ms-- 平均耗時 max: 455.91ms-- 最長耗時 approx. 99 percentile: 116.12ms-- 超過99%平均耗時 Threads fairness: events (avg/stddev): 3420.7500/15.36 execution time (avg/stddev): 119.9645/0.02
--獲取數據
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=system --mysql-password=**** --test=tests/db/oltp.lua --oltp_tables_count=3 \ --oltp-table-size=1000 --rand-init=on prepare sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=system --mysql-password='****' --test=tests/db/oltp.lua --oltp_tables_count=3 \ --oltp-table-size=1000 --num-threads=8 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=120 --max-requests=0 \ --percentile=99 run >> /home/mysql/sysbench.log
----20180905 浪潮服務器測試
# unzip sysbench-0.5.zip # yum install automake libaio libaio-devel libtool -y # ./autogen.sh # ./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install drv_mysql.c:37:19: fatal error: mysql.h: No such file or directory # yum install mysql-community-devel # ./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/include/mysql && make && make install # echo "export PATH=$PATH:/usr/local/sysbench/bin/">>/etc/profile # source /etc/profile [root@mysql1 sysbench-0.5]# sysbench sysbench --test=/usr/local/sysbench/share/sysbench/oltp.lua --oltp-table-size=5000000 \ --mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \ --max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 prepare sysbench --test=/usr/local/sysbench/share/sysbench/oltp.lua --oltp-table-size=5000000 \ --mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \ --max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 run >> /home/mysql/sysbench_20180906.log sysbench --test=/usr/local/sysbench/share/sysbench/oltp.lua --oltp-table-size=5000000 \ --mysql-table-engine=innodb --mysql-user=system --mysql-password=***** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \ --max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 cleanup
--20190403
[root@localhost sysbench-0.5]# sysbench sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory [root@localhost sysbench-0.5]# ll /usr/local/mysql/lib/libmysqlclient.so.20 lrwxrwxrwx. 1 mysql mysql 25 Apr 3 15:37 /usr/local/mysql/lib/libmysqlclient.so.20 -> libmysqlclient.so.20.3.11 [root@localhost sysbench-0.5]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20
tpcc--mysql--去掉外鍵,添加主鍵自增
https://github.com/yejr/tpcc-mysql-autoinc-pk [root@mysql1 soft]# unzip tpcc-mysql-autoinc-pk-master.zip [root@mysql1 tpcc-mysql-autoinc-pk-master]# cd src/ [root@mysql1 src]# make cc -w -O2 -g -I. `mysql_config --include` -c load.c /bin/sh: mysql_config: 未找到命令 load.c:18:19: 致命錯誤:mysql.h:沒有那個文件或目錄 load.c:18:19: error: mysql.h: No such file or directory [root@hongquan1 src]# cp /usr/local/mysql/include/mysql.h . [root@hongquan1 src]# ln -s /usr/local/mysql/bin/mysql /usr/bin [root@hongquan1 src]# make cc -w -O2 -g -I. `mysql_config --include` -c load.c /bin/sh: mysql_config: command not found [root@hongquan1 src]# export PATH=/usr/local/mysql/bin:$PATH [root@hongquan1 src]# make [root@hongquan1 src]# cd .. [root@hongquan1 tpcc-mysql-autoinc-pk-master]# ll total 268 -rw-r--r-- 1 root root 1621 Mar 21 2017 add_fkey_idx.sql -rw-r--r-- 1 root root 6457 Mar 21 2017 create_table-autoinc-pk.sql -rw-r--r-- 1 root root 477 Mar 21 2017 load.sh -rw-r--r-- 1 root root 851 Mar 21 2017 README -rw-r--r-- 1 root root 5534 Mar 21 2017 README.md -rw-r--r-- 1 root root 1602 Mar 21 2017 run_tpcc.sh drwxr-xr-x 2 root root 4096 Mar 21 2017 schema2 drwxr-xr-x 5 root root 4096 Mar 21 2017 scripts drwxr-xr-x 2 root root 4096 Aug 13 10:10 src -rwxr-xr-x 1 root root 62899 Aug 13 10:10 tpcc_load -rw-r--r-- 1 root root 2193 Mar 21 2017 tpcc_load_parallel.sh -rwxr-xr-x 1 root root 157354 Aug 13 10:10 tpcc_start [root@mysql1 tpcc-mysql-autoinc-pk-master]# chown -R mysql:mysql /data/soft/tpcc-mysql-autoinc-pk-master [mysql@mysql1 ~]$ mysqladmin -usystem -****' -h127.0.0.1 -P3306 create tpcc [mysql@mysql1 ~]$ mysql -usystem -p'mysql' -h127.0.0.1 -P3306 -f tpcc < create_table-autoinc-pk.sql 加載數據 [root@mysql1 tpcc-mysql-autoinc-pk-master]# ./tpcc_load 192.168.19.87:3306 tpcc system "*****" 10 [root@mysql1 tpcc-mysql-autoinc-pk-master]# time ./tpcc_start -h 192.168.19.87 -P 3306 -d tpcc -usystem -****' -w 10 -c 32 -r 120 -l 600 -f tpcc_mysql_2018081301
--tpcc-mysql
http://blog.chinaunix.net/uid-26896862-id-3188313.html
--tpcc使用說明
下載TPCC-MySQL
[root@12crac1 software]# yum install bzr -y [root@12crac1 software]# bzr branch lp:~percona-dev/perconatools/tpcc-mysql You have not informed bzr of your Launchpad ID, and you must do this to write to Launchpad or access private data. See "bzr help launchpad-login". Branched 48 revision(s). [root@12crac1 software]# export PATH=/usr/local/mysql/bin:$PATH [root@12crac1 software]# cd tpcc-mysql/src/ [root@12crac1 src]# make cc -w -O2 -g -I. `mysql_config --include` -c load.c [root@12crac1 src]# cd .. [root@12crac1 tpcc-mysql]# ll -rwxr-xr-x 1 root root 61199 Mar 30 23:38 tpcc_load--用於初始化數據 -rwxr-xr-x 1 root root 155934 Mar 30 23:38 tpcc_start--用於執行基准測試 基本配置 [root@12crac1 ~]# su - mysql [mysql@12crac1 ~]$ cd /data/software/tpcc-mysql/ [mysql@12crac1 src]$ mysqladmin create tpcc mysql> create database tpcc; – create_table.sql - 創建數據表 – add_fkey_idx.sql – 創建索引及外鍵 [mysql@12crac1 tpcc-mysql]$ mysql -h 127.0.0.1 -usystem -pmysql tpcc < create_table.sql [mysql@12crac1 tpcc-mysql]$ mysql -h 127.0.0.1 -usystem -pmysql tpcc < add_fkey_idx.sql mysql> show tables; +----------------+ | Tables_in_tpcc | +----------------+ | customer | | district | | history | | item | | new_orders | | order_line | | orders | | stock | | warehouse | 初始化加載數據 – tpcc_load db_host db_name db_user db_passwd db_warehouse_num – 例如:tpcc_load localhost tpcc1000 user passwd 1000 運行OLTP測試 – ./tpcc_start -h localhost -d tpcc1000 -u root -p '***' -w 1000 -c 32 -r 120 -l 3600 -f ./tpcc_mysql_20120314 基准 - OLTP – warehouse = 1000 – max connection = 8 ~ 512 – warm up = 120(s) – run time/duration = 3600(s) 測試用例 ./tpcc_start -h host -d db -u user -p passwd -w 500 -c 128 -r 120 -l 3600 -w warehose/倉庫數 -c concurrent threads/並發線程 -r warmup/數據預熱時長 -l during time/持續加壓時長 [mysql@12crac1 tpcc-mysql]$ ./tpcc_load 127.0.0.1:3306 tpcc system "****" 10 ./tpcc_load: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory [root@12crac1 tpcc-mysql]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18 --初始化數據 ./tpcc_load 127.0.0.1:3306 tpcc system "***" 2 ./tpcc_start -h 127.0.0.1 -d tpcc -usystem -p "***" -w 2 -c 2 -r 100 -l 300 > tpcc.out [root@12crac1 tpcc-mysql]# vim load.sh 介紹一下各個參數的用法 -h server_host: 服務器名 -P port : 端口號,默認為3306 -d database_name: 數據庫名 -u mysql_user : 用戶名 -p mysql_password : 密碼 -w warehouses: 倉庫的數量 -c connections : 線程數,默認為1 -r warmup_time : 熱身時間,單位:s,默認為10s ,熱身是為了將數據加載到內存。 -l running_time: 測試時間,單位:s,默認為20s--建議半個小時或一個小時 3600 -i report_interval: 指定生成報告間隔時長 -f report_file: 測試結果輸出文件 [root@12crac1 tpcc-mysql]# ./tpcc_start -h 127.0.0.1 -d tpcc -usystem -p "***" -w 10 -c 10 -r 100 -l 300 -f /home/mysql/tpcc_mysql.log -t /home/mysql/tpcc_mysql.rtx ./tpcc_start -h 127.0.0.1 -d tpcc -usystem -p "***" -w 10 -c 10 -r 1200 -l 3600 > tpcc.out sc--成功,lt--延遲,rt--重試,fl--失敗 http://blog.chinaunix.net/uid-26896862-id-3563600.html --tpc 輸出詳情 STOPPING THREADS.......... <Raw Results> [0] sc:33640 lt:5 rt:0 fl:0 [1] sc:33648 lt:0 rt:0 fl:0 [2] sc:3364 lt:0 rt:0 fl:0 [3] sc:3364 lt:0 rt:0 fl:0 [4] sc:3364 lt:0 rt:0 fl:0 in 300 sec. <Raw Results2(sum ver.)> [0] sc:33640 lt:5 rt:0 fl:0 [1] sc:33648 lt:0 rt:0 fl:0 [2] sc:3364 lt:0 rt:0 fl:0 [3] sc:3364 lt:0 rt:0 fl:0 [4] sc:3364 lt:0 rt:0 fl:0 <Constraint Check> (all must be [OK]) [transaction percentage] Payment: 43.48% (>=43.0%) [OK] Order-Status: 4.35% (>= 4.0%) [OK] Delivery: 4.35% (>= 4.0%) [OK] Stock-Level: 4.35% (>= 4.0%) [OK] [response time (at least 90% passed)] New-Order: 99.99% [OK] Payment: 100.00% [OK] Order-Status: 100.00% [OK] Delivery: 100.00% [OK] Stock-Level: 100.00% [OK] <TpmC> 6729.000 TpmC --TpmC 整體性能指標,本系統每分鍾能夠處理的訂單數量,tpcc沒有收集系統性能指標 --使用gnuplot生成圖表 [root@12crac1 mysql]# yum install -y gnuplot [root@12crac1 mysql]# gnuplot [root@12crac1 mysql]# rm -f /var/run/yum.pid [root@12crac1 mysql]# yum install -y gnuplot-x11 [root@12crac1 scripts]# chmod +x analyze.sh [root@12crac1 scripts]# ./analyze.sh /home/mysql/tpcc_mysql1.log /home/mysql/tpcc_20160331.res Defined /home/mysql/tpcc_20160331.res [root@12crac1 scripts]# pwd /data/software/tpcc-mysql/scripts [root@12crac1 mysql]# vim log.conf [root@12crac1 mysql]# more log.conf set terminal gif small size 480,360 #指定輸出成gif圖片,且圖片大小為550×25 set output "tcpp.gif" #指定輸出gif圖片的文件名 set title "MySQL Performance" #圖片標題 set style data lines #顯示網格 set xlabel "Time/s" #X軸標題 set ylabel "Data" #Y軸標題 set grid #顯示網格 plot \ "tpcc_20160331.res" using 1:2 title "Total throughput" with lines 運行生成tcpp.gif: #cat log.conf | gnuplot ---20160415 ./tpcc_start -h 127.0.0.1 -d tpcc -usystem -p "mysql" -w 10 -c 10 -r 100 -l 300 > tpcc.out [root@12crac1 scripts]# ./analyze.sh /data/software/tpcc-mysql/tpcc.out >/home/mysql/tpcc_test.txt [root@12crac1 mysql]# cat log.conf |gnuplot Could not find/open font when opening font "arial", using internal non-scalable font [root@12crac1 mysql]# more tpcc_test.txt 1 1.403000 0 0.000000
fio在Linux系統下使用比較方便,iometer在window系統下使用比較方便,Orion是oracle的IO測試軟件,可在沒有安裝oracle數據庫的情況下模擬oracle數據庫場景的讀寫。
--下載fio源碼包
--檢查aio依賴包
[root@12crac1 ~]# rpm -qa|grep aio libaio-devel-0.3.107-10.el6.x86_64 libaio-0.3.107-10.el6.x86_64 [root@12crac1 software]# tar xvfz fio-2.1.10.tar.gz [root@12crac1 fio-2.1.10]# ./configure [root@12crac1 fio-2.1.10]# make -j [root@12crac1 fio-2.1.10]# ll |grep fio -rwxr-xr-x 1 root root 3164335 Mar 30 22:48 fio [root@12crac1 fio-2.1.10]# ./fio --help fio-2.1.10 [root@12crac1 fio-2.1.10]# ./fio --cmdhelp [root@12crac1 fio-2.1.10]# ./fio --enghelp --output --output-format=x --crctest Test speed of checksum functions --cpuclock-test Perform test/validation of CPU clock --runtime Runtime in seconds [root@12crac1 fio-2.1.10]# ./fio -filename=/data/ -direct=1 -iodepth 1 -rw=read -ioengine=psync \ -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest --output-format=json fio: pid=0, err=21/file:filesetup.c:63, func=unlink, error=Is a directory fio是用來對裸設備做測試的,所以你的-filename參數不能使用目錄,而應該使用硬盤分區 fio是一個非常靈活的io測試工具 說明: filename=/dev/sdb1 測試文件名稱,通常選擇需要測試的盤的data目錄。 direct=1 測試過程繞過機器自帶的buffer。使測試結果更真實,是否使用directIO。 rw=randwrite 測試隨機寫的I/O rw=randrw 測試隨機寫和讀的I/O bs=16k 單次io的塊文件大小為16k bsrange=512-2048 同上,提定數據塊的大小范圍 size=5g 本次的測試文件大小為5g,以每次4k的io進行測試,每個線程寫入數據量。 numjobs=30 本次的測試線程為30. runtime=1000 測試時間為1000秒,如果不寫則一直將5g文件分4k每次寫完為止。 ioengine=psync io引擎使用pync方式 rwmixwrite=30 在混合讀寫的模式下,寫占30% group_reporting 關於顯示結果的,匯總每個進程的信息。 此外 lockmem=1g 只使用1g內存進行測試。 zero_buffers 用0初始化系統buffer。 nrfiles=8 每個進程生成文件的數量 -thread:使用pthread_create創建線程,另一種是fork創建進程。進程的開銷比線程要大,一般都采用thread測試。 ios=所有group總共執行的IO數. merge=總共發生的IO合並數. ticks=Number of ticks we kept the disk busy. io_queue=花費在隊列上的總共時間. util=磁盤利用率
[root@12crac1 fio-2.1.10]# ./fio -filename=/dev/sda -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest --output-format=json { "fio version" : "fio-2.1.10", "jobs" : [ { "jobname" : "mytest", "groupid" : 0, "error" : 0, "read" : { "io_bytes" : 2159952, "bw" : 215973, "iops" : 13498, "runtime" : 10001, "slat" : { "min" : 0, "max" : 0, "mean" : 0.00, "stddev" : 0.00 .... [root@12crac1 fio-2.1.10]# ./fio -filename=/dev/sda -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest mytest: (g=0): rw=read, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1 ... fio-2.1.10 Starting 10 processes Jobs: 10 (f=10): [RRRRRRRRRR] [100.0% done] [240.5MB/0KB/0KB /s] [15.4K/0/0 iops] [eta 00m:00s] mytest: (groupid=0, jobs=10): err= 0: pid=10322: Wed Mar 30 23:11:15 2016 read : io=1931.7MB, bw=197775KB/s, iops=12360, runt= 10001msec clat (usec): min=75, max=95487, avg=767.47, stdev=1761.01 lat (usec): min=77, max=95489, avg=777.35, stdev=1767.68 clat percentiles (usec): | 1.00th=[ 133], 5.00th=[ 215], 10.00th=[ 270], 20.00th=[ 334], | 30.00th=[ 382], 40.00th=[ 430], 50.00th=[ 486], 60.00th=[ 564], | 70.00th=[ 668], 80.00th=[ 836], 90.00th=[ 1192], 95.00th=[ 1896], | 99.00th=[ 4832], 99.50th=[ 7328], 99.90th=[23680], 99.95th=[38144], | 99.99th=[60160] bw (KB /s): min= 8399, max=32608, per=9.95%, avg=19677.21, stdev=5373.64 lat (usec) : 100=0.12%, 250=7.92%, 500=44.10%, 750=23.21%, 1000=10.76% lat (msec) : 2=9.29%, 4=3.18%, 10=1.08%, 20=0.19%, 50=0.11% lat (msec) : 100=0.03% cpu : usr=0.05%, sys=11.29%, ctx=133572, majf=0, minf=382 IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued : total=r=123622/w=0/d=0, short=r=0/w=0/d=0 latency : target=0, window=0, percentile=100.00%, depth=1 Run status group 0 (all jobs): READ: io=1931.7MB, aggrb=197775KB/s, minb=197775KB/s, maxb=197775KB/s, mint=10001msec, maxt=10001msec Disk stats (read/write): sda: ios=122254/23, merge=0/25, ticks=54655/70, in_queue=54000, util=95.92%
==20180823
wget http://brick.kernel.dk/snaps/fio-2.2.5.tar.gz
yum install libaio-devel
隨機讀:(可直接用,向磁盤寫一個2G文件,10線程,隨機讀1分鍾,給出結果) fio -filename=/tmp/test_randread -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=16k -size=2G -numjobs=10 -runtime=60 -group_reporting -name=mytest read 順序讀 write 順序寫 rw,readwrite 順序混合讀寫 randwrite 隨機寫 randread 隨機讀 randrw 隨機混合讀寫 ./fio -filename=/dev/sda -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest ./fio -filename=/dev/sda -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=16k -size=200G -numjobs=30 -runtime=100 -group_reporting -name=mytest1 ./fio -filename=/data -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest ./fio -filename=/data/ -direct=1 -iodepth 1 -rw=randrw -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest --output-format=json ./fio -filename=/data/ -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest --output-format=json --iops [root@mysqlhq fio-2.2.5]# ./fio -filename=/dev/mapper/kylin-home -direct=1 -iodepth 1 -thread -rw=randrw -ioengine=psync -bs=16k -size=500m -numjobs=10 -runtime=10 -group_reporting -name=mytest --output-format=json ==118 [root@hongquan1 fio-2.2.5]# ./fio -filename=/dev/sda -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=16k -size=200G -numjobs=30 -runtime=100 -group_reporting -name=mytest1 mytest1: (g=0): rw=randrw, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1 ... fio-2.2.5 Starting 30 threads Jobs: 30 (f=30): [m(30)] [100.0% done] [495KB/223KB/0KB /s] [30/13/0 iops] [eta 00m:00s] mytest1: (groupid=0, jobs=30): err= 0: pid=1359: Thu Aug 23 16:16:29 2018 read : io=153456KB, bw=1531.3KB/s, iops=95, runt=100218msec clat (usec): min=33, max=1776.9K, avg=230518.12, stdev=295161.54 lat (usec): min=33, max=1776.9K, avg=230518.31, stdev=295161.57 clat percentiles (usec): | 1.00th=[ 52], 5.00th=[ 82], 10.00th=[ 119], 20.00th=[ 290], | 30.00th=[28544], 40.00th=[83456], 50.00th=[144384], 60.00th=[203776], | 70.00th=[268288], 80.00th=[362496], 90.00th=[585728], 95.00th=[905216], | 99.00th=[1368064], 99.50th=[1449984], 99.90th=[1646592], 99.95th=[1712128], | 99.99th=[1777664] bw (KB /s): min= 7, max= 677, per=3.92%, avg=60.01, stdev=46.19 write: io=63520KB, bw=649029B/s, iops=39, runt=100218msec clat (usec): min=40, max=1726.6K, avg=199873.39, stdev=299754.56 lat (usec): min=41, max=1726.6K, avg=199874.13, stdev=299754.51 clat percentiles (usec): | 1.00th=[ 56], 5.00th=[ 73], 10.00th=[ 87], 20.00th=[ 127], | 30.00th=[ 193], 40.00th=[ 354], 50.00th=[16320], 60.00th=[179200], | 70.00th=[248832], 80.00th=[342016], 90.00th=[552960], 95.00th=[872448], | 99.00th=[1384448], 99.50th=[1482752], 99.90th=[1695744], 99.95th=[1728512], | 99.99th=[1728512] bw (KB /s): min= 7, max= 186, per=5.75%, avg=36.39, stdev=23.70 lat (usec) : 50=0.65%, 100=8.68%, 250=14.30%, 500=5.25%, 750=1.63% lat (usec) : 1000=0.49% lat (msec) : 2=0.69%, 4=0.68%, 10=1.39%, 20=1.03%, 50=4.08% lat (msec) : 100=6.75%, 250=22.73%, 500=18.98%, 750=6.22%, 1000=2.55% lat (msec) : 2000=3.90% cpu : usr=0.00%, sys=0.01%, ctx=13467, majf=0, minf=5 IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued : total=r=9591/w=3970/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0 latency : target=0, window=0, percentile=100.00%, depth=1 Run status group 0 (all jobs): READ: io=153456KB, aggrb=1531KB/s, minb=1531KB/s, maxb=1531KB/s, mint=100218msec, maxt=100218msec WRITE: io=63520KB, aggrb=633KB/s, minb=633KB/s, maxb=633KB/s, mint=100218msec, maxt=100218msec Disk stats (read/write): sda: ios=10366/4808, merge=2971/339, ticks=2457713/996312, in_queue=3471461, util=100.00% ==226 Starting 30 threads Jobs: 30 (f=30): [m(30)] [0.0% done] [2157KB/1326KB/0KB /s] [134/82/0 iops] [eta 04d:15h:34m:27s] mytest1: (groupid=0, jobs=30): err= 0: pid=15910: Thu Aug 23 17:03:17 2018 read : io=1174.1MB, bw=11987KB/s, iops=749, runt=100365msec clat (usec): min=18, max=1509.4K, avg=39328.95, stdev=97965.98 lat (usec): min=18, max=1509.4K, avg=39329.08, stdev=97965.99 clat percentiles (usec): | 1.00th=[ 27], 5.00th=[ 38], 10.00th=[ 85], 20.00th=[ 5216], | 30.00th=[ 8512], 40.00th=[11584], 50.00th=[16064], 60.00th=[22144], | 70.00th=[30592], 80.00th=[43776], 90.00th=[74240], 95.00th=[124416], | 99.00th=[497664], 99.50th=[700416], 99.90th=[1335296], 99.95th=[1449984], | 99.99th=[1466368] bw (KB /s): min= 10, max= 1238, per=3.81%, avg=456.55, stdev=290.27 write: io=494432KB, bw=4926.4KB/s, iops=307, runt=100365msec clat (usec): min=57, max=852603, avg=1574.68, stdev=19490.91 lat (usec): min=57, max=852604, avg=1575.08, stdev=19490.91 clat percentiles (usec): | 1.00th=[ 64], 5.00th=[ 70], 10.00th=[ 75], 20.00th=[ 82], | 30.00th=[ 89], 40.00th=[ 98], 50.00th=[ 111], 60.00th=[ 139], | 70.00th=[ 426], 80.00th=[ 636], 90.00th=[ 1624], 95.00th=[ 2448], | 99.00th=[ 6368], 99.50th=[19840], 99.90th=[346112], 99.95th=[464896], | 99.99th=[659456] bw (KB /s): min= 8, max= 773, per=4.15%, avg=204.32, stdev=134.39 lat (usec) : 20=0.01%, 50=5.23%, 100=14.37%, 250=8.37%, 500=2.12% lat (usec) : 750=2.72%, 1000=1.01% lat (msec) : 2=2.93%, 4=4.07%, 10=13.03%, 20=15.51%, 50=18.59% lat (msec) : 100=7.23%, 250=3.06%, 500=1.04%, 750=0.40%, 1000=0.16% lat (msec) : 2000=0.16% cpu : usr=0.02%, sys=0.05%, ctx=106098, majf=0, minf=7 IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued : total=r=75194/w=30902/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0 latency : target=0, window=0, percentile=100.00%, depth=1 Run status group 0 (all jobs): READ: io=1174.1MB, aggrb=11987KB/s, minb=11987KB/s, maxb=11987KB/s, mint=100365msec, maxt=100365msec WRITE: io=494432KB, aggrb=4926KB/s, minb=4926KB/s, maxb=4926KB/s, mint=100365msec, maxt=100365msec Disk stats (read/write): sda: ios=75535/30918, merge=1152/5, ticks=2952491/48125, in_queue=3007268, util=100.00% ==145 mytest1: (groupid=0, jobs=30): err= 0: pid=29172: Thu Aug 23 17:27:52 2018 read : io=1471.8MB, bw=14105KB/s, iops=881, runt=106844msec clat (usec): min=19, max=8208.3K, avg=30723.67, stdev=167017.33 lat (usec): min=19, max=8208.3K, avg=30723.84, stdev=167017.33 clat percentiles (usec): | 1.00th=[ 25], 5.00th=[ 29], 10.00th=[ 34], 20.00th=[ 45], | 30.00th=[ 61], 40.00th=[ 118], 50.00th=[ 676], 60.00th=[ 6432], | 70.00th=[17024], 80.00th=[38144], 90.00th=[80384], 95.00th=[120320], | 99.00th=[244736], 99.50th=[428032], 99.90th=[1728512], 99.95th=[5079040], | 99.99th=[6193152] bw (KB /s): min= 1, max= 1937, per=4.38%, avg=617.23, stdev=324.41 write: io=625072KB, bw=5850.4KB/s, iops=365, runt=106844msec clat (usec): min=59, max=8208.4K, avg=3492.90, stdev=64545.70 lat (usec): min=60, max=8208.4K, avg=3517.20, stdev=64601.41 clat percentiles (usec): | 1.00th=[ 69], 5.00th=[ 80], 10.00th=[ 90], 20.00th=[ 113], | 30.00th=[ 219], 40.00th=[ 450], 50.00th=[ 494], 60.00th=[ 548], | 70.00th=[ 700], 80.00th=[ 988], 90.00th=[ 2160], 95.00th=[ 3984], | 99.00th=[35584], 99.50th=[123392], 99.90th=[552960], 99.95th=[667648], | 99.99th=[1003520] bw (KB /s): min= 1, max= 1052, per=4.54%, avg=265.60, stdev=152.50 lat (usec) : 20=0.01%, 50=17.05%, 100=14.41%, 250=8.37%, 500=8.76% lat (usec) : 750=8.01%, 1000=3.49% lat (msec) : 2=4.48%, 4=3.92%, 10=5.43%, 20=5.85%, 50=8.23% lat (msec) : 100=6.78%, 250=4.44%, 500=0.41%, 750=0.11%, 1000=0.04% lat (msec) : 2000=0.13%, >=2000=0.06% cpu : usr=0.19%, sys=0.22%, ctx=133273, majf=0, minf=19 IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% issued : total=r=94192/w=39067/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0 latency : target=0, window=0, percentile=100.00%, depth=1 Run status group 0 (all jobs): READ: io=1471.8MB, aggrb=14105KB/s, minb=14105KB/s, maxb=14105KB/s, mint=106844msec, maxt=106844msec WRITE: io=625072KB, aggrb=5850KB/s, minb=5850KB/s, maxb=5850KB/s, mint=106844msec, maxt=106844msec Disk stats (read/write): sda: ios=94438/39072, merge=49/0, ticks=2855388/142114, in_queue=2997516, util=95.88%