壓測工具 sysbench安裝及使用簡介(0.4.12\0.5\1.0.x+版本)
--2017-11-07更新 sysbench 1.0.9+安裝及簡單使用:{
安裝1:透過EPEL直接yum安裝
EPEL可以裝一下(如果沒裝)
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum install -y sysbench 即可
此處僅針對mysql做oltp測試做介紹:
安裝好後,會在/usr/share/sysbench/下存放lua指令碼
安裝2:去把sysbench.zip或者直接git clone下來
cd xxx/sysbench-master
make clean
./autogen.sh
./configure --prefix=/usr/local/sysbench/ --with-mysql --with-mysql-libs=/usr/lib64/mysql/
make && make install
根據具體情況可能需要指定不同的--with-mysql-libs
此處mysql依賴,透過rpm包預設安在/usr/lib64/mysql/
用法與老版本相近,此處舉例:
sysbench --db-driver=mysql /usr/share/sysbench/oltp_read_only.lua --mysql-host=$host --mysql-port=$port --mysql-user=$user --mysql-password=$password --mysql-db=sysbench(需自行建立) --tables=100 --table-size=5000000 --report-interval=10 --threads=64 --time=7200 prepare/run/cleanup
}
--2017-11-07更新 sysbench 0.5 安裝及簡單使用
{
$ sudo yum install gcc gcc-c++ automake make libtool mysql-community-devel
$ cd /tmp && git clone .git
$ cd /tmp/sysbench && ./autogen.sh
$ ./configure --prefix=/usr/local/sysbench-0.5 --with-mysql
$ make && make install
$ cd /usr/local/sysbench-0.5/bin
如mysql
$ ./sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 prepare
$ ./sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
如fio等
$ ./sysbench --test=fileio --file-total-size=5G prepare
$ ./sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
$ ./sysbench --test=fileio --file-total-size=5G cleanup
}
此處用的是sysbench 0.5
0.4.12版本和0.5類似
可以為使用者提供如下測試:
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
p.s.
在mysql官方推薦的是sysbench 0.4.12.10
http://dev.mysql.com/downloads/benchmarks.html
一. 安裝
解壓後:
- $ cd sysbench-0.5
- $ ./autogen.sh
- $ ./configure --prefix=(選擇sysbench安裝在哪) (如果需要測試oltp可以加後面的選項)--with-mysql-includes=/usr/local/mysql/include(換成你自己的) --with-mysql-libs=/usr/local/mysql/lib --with-mysql (還可以支援oracle和pgsql
- $ make && make install
可能需要安裝一下環境:
- $ sudo yum -y install libtool automake
原始碼來安裝autoconf和automake
附帶這兩個原始碼包url
配置環境變數:
- $ vi ~/.bash_profile
sysbench --version 或者直接 sysbench 可以看到版本資訊或者幫助資訊
- $ source ~/.bash_profile
- $ sysbench --version
- sysbench 0.5
sysbench: error while loading shared libraries: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory
則有可能是lib路徑不對
- $ sudo vi /etc/ld.so.conf
- 新增 /usr/local/mysql/lib 儲存退出
- $ sudo /sbin/ldconfig -v
二. file IO
指定--test=fileio即可。
fileio options:
--file-num=N number of files to create [128]
// 建立的檔案數
--file-block-size=N block size to use in all IO operations [16384]
// 塊大小,比如4096為4K
--file-total-size=SIZE total size of files to create [2G]
// 要建立檔案的總大小
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
// 磁碟訪問模式,分別為順序寫,順序讀寫,順序讀,隨機寫,隨機讀寫,隨機讀
--file-io-mode=STRING file operations mode {sync,async,mmap} [sync]
// 檔案操作模式,分別為同步,非同步,對映至記憶體,預設為同步
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
// 開啟檔案的附加標識
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]
// 在某個數請求之後做fsync(),預設為100
--file-fsync-all=[on|off] do fsync() after each write operation [off]
// 開啟或關閉在每個寫操作後執行fsync(),預設為OFF
--file-fsync-end=[on|off] do fsync() at the end of test [on]
// 開啟或關閉結束test時執行fsync(),預設為ON
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
// 使用什麼方法同步,預設為fsync
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]
// 儘可能合併IO請求的數量,預設為0
--file-rw-ratio=N reads/writes ratio for combined test [1.5]
// 讀寫比例,預設為1.5
測試例子:
- $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync prepare // 先做檔案準備 引數為prepare 建立10個檔案 每個102.4MB 檔案塊為4K
- sysbench 0.5: multi-threaded system evaluation benchmark
- 10 files, 104857Kb each, 1023Mb total
- Creating files for the test...
- Extra file open flags: 0
- Creating file test_file.0
- Creating file test_file.1
- Creating file test_file.2
- Creating file test_file.3
- Creating file test_file.4
- Creating file test_file.5
- Creating file test_file.6
- Creating file test_file.7
- Creating file test_file.8
- Creating file test_file.9
- 1073766400 bytes written in 12.11 seconds (84.56 MB/sec).
-
- $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync run // 開始測試,引數改為run
- sysbench 0.5: multi-threaded system evaluation benchmark
- Running the test with following options:
- Number of threads: 1
- Random number generator seed is 0 and will be ignored
- Extra file open flags: 0
- 10 files, 102.4Mb each
- 1024Mb total file size
- Block size 4Kb
- Periodic FSYNC enabled, calling fsync() each 100 requests.
- Calling fsync() at the end of test, Enabled.
- Using synchronous I/O mode
- Doing sequential write (creation) test
- Threads started!
- Operations performed: 0 reads, 10000 writes, 1000 Other = 11000 Total
- Read 0b Written 39.062Mb Total transferred 39.062Mb (8.3495Mb/sec)
- 2137.47 Requests/sec executed
- General statistics:
- total time: 4.6784s
- total number of events: 10000
- total time taken by event execution: 0.0767s
- response time:
- min: 0.00ms
- avg: 0.01ms
- max: 0.08ms
- approx. 95 percentile: 0.01ms
- Threads fairness:
- events (avg/stddev): 10000.0000/0.00
- execution time (avg/stddev): 0.0767/0.00
- $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync cleanup // 引數為cleanup 清除測試檔案
- sysbench 0.5: multi-threaded system evaluation benchmark
- Removing test files...
三. CPU test
指定--test=cpu即可。
cpu options:
--cpu-max-prime=N upper limit for primes generator [10000]
// 設定素數最大上限值,預設為10000
測試例子:
- $ sysbench --test=cpu --cpu-max-prime=1024 run
- sysbench 0.5: multi-threaded system evaluation benchmark
- Running the test with following options:
- Number of threads: 1
- Random number generator seed is 0 and will be ignored
- Primer numbers limit: 1024
- Threads started!
- General statistics:
- total time: 0.4622s
- total number of events: 10000
- total time taken by event execution: 0.4561s
- response time:
- min: 0.04ms
- avg: 0.05ms
- max: 0.15ms
- approx. 95 percentile: 0.05ms
- Threads fairness:
- events (avg/stddev): 10000.0000/0.00
- execution time (avg/stddev): 0.4561/0.00
四. memory test
指定--test=memory即可。
memory options:
--memory-block-size=SIZE size of memory block for test [1K]
// 記憶體塊的大小,預設為1K
--memory-total-size=SIZE total size of data to transfer [100G]
// 總共需要傳輸的大小,預設為100G
--memory-scope=STRING memory access scope {global,local} [global]
// 記憶體訪問是全域性還是本地,預設為全域性
--memory-hugetlb=[on|off] allocate memory from HugeTLB pool [off]
// 是否從HugeTLB中分配記憶體,預設為否
--memory-oper=STRING type of memory operations {read, write, none} [write]
// 記憶體的操作方式,讀,寫,或none,預設為寫
--memory-access-mode=STRING memory access mode {seq,rnd} [seq]
// 記憶體訪問模式,順序或隨機,預設為序列
測試例子:
- $ sysbench --test=memory --memory-block-size=4096 --memory-total-size=50G --memory-oper=read --memory-access-mode=rnd run
- sysbench 0.5: multi-threaded system evaluation benchmark
- Running the test with following options:
- Number of threads: 1
- Random number generator seed is 0 and will be ignored
- Threads started!
- Operations performed: 13107200 (950195.57 ops/sec)
- 51200.00 MB transferred (3711.70 MB/sec)
- General statistics:
- total time: 13.7942s
- total number of events: 13107200
- total time taken by event execution: 5.8543s
- response time:
- min: 0.00ms
- avg: 0.00ms
- max: 0.06ms
- approx. 95 percentile: 0.00ms
- Threads fairness:
- events (avg/stddev): 13107200.0000/0.00
- execution time (avg/stddev): 5.8543/0.00
五. threads test
指定--test=threads即可。
threads options:
--thread-yields=N number of yields to do per request [1000]
--thread-locks=N number of locks per thread [8]
// 每個執行緒鎖的數目
測試例子:
- [op@sAno1y sysbench]$ sysbench --test=threads run
- sysbench 0.5: multi-threaded system evaluation benchmark
- Running the test with following options:
- Number of threads: 1
- Random number generator seed is 0 and will be ignored
- Threads started!
- General statistics:
- total time: 3.6699s
- total number of events: 10000
- total time taken by event execution: 3.6635s
- response time:
- min: 0.35ms
- avg: 0.37ms
- max: 0.74ms
- approx. 95 percentile: 0.37ms
- Threads fairness:
- events (avg/stddev): 10000.0000/0.00
- execution time (avg/stddev): 3.6635/0.00
六. mutex test
指定--test=mutex即可。
mutex options:
--mutex-num=N total size of mutex array [4096]
// 互斥體資料大小,預設為4K
--mutex-locks=N number of mutex locks to do per thread [50000]
// 每個執行緒的互斥鎖,預設為50000
--mutex-loops=N number of empty loops to do inside mutex lock [10000]
// 互斥鎖內空迴圈的數目,預設為10000
測試例子:
- [op@sAno1y sysbench]$ sysbench --test=mutex --mutex-num=8192 --number-locks=102400 run
- sysbench 0.5: multi-threaded system evaluation benchmark
- Running the test with following options:
- Number of threads: 1
- Random number generator seed is 0 and will be ignored
- Threads started!
- General statistics:
- total time: 0.0049s
- total number of events: 1
- total time taken by event execution: 0.0048s
- response time:
- min: 4.79ms
- avg: 4.79ms
- max: 4.79ms
- approx. 95 percentile: 4.79ms
- Threads fairness:
- events (avg/stddev): 1.0000/0.00
- execution time (avg/stddev): 0.0048/0.00
七. oltp test
oltp options:
General database options:
--db-driver=STRING specifies database driver to use ('help' to get list of available drivers)
--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
Compiled-in database drivers:
mysql - MySQL driver
mysql options:
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=N MySQL server port [3306]
--mysql-socket=STRING MySQL socket
--mysql-user=STRING MySQL user [sbtest]
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
--mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]
--mysql-ssl=[on|off] use SSL connections, if available in the client library [off]
--myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]
--mysql-create-options=STRING additional options passed to CREATE TABLE []
建立測試資料:
--oltp-table-size為單表建立資料的數量
- sysbench --test=oltp --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test --oltp-table-size=50000000 prepare
開始run:其中--num-threads為併發數,--max-time為測試的時長(秒)
- sysbench --test=oltp --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test --oltp-table-size=5000000 --num-threads=1000 --max-time=60 --max-requests=0 --report-interval=10 run
在sysbench 0.5的版本中,則可以使用一個lua指令碼來建立表,並且可以指定多張表,比如:
其中 oltp_tables_count為指定prepare幾張表,--rand-init開啟則表示隨機寫數:
- sysbench --test=/opt/app/sysbench-0.5/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test \
- --oltp-table-size=50000000 --oltp_tables_count=10 --rand-init=on prepare
生成的測試表的資料樣例:
*************************** 1. row ***************************
id: 1
k: 50206885
c: 08566691963-88624912351-16662227201-46648573979-64646226163-77505759394-75470094713-41097360717-15161106334-50535565977
pad: 63188288836-92351140030-06390587585-66802097351-49282961843
*************************** 2. row ***************************
id: 2
k: 49910688
c: 95969429576-20587925969-20202408199-67602281819-18293380360-38184587501-73192830026-41693404212-56705243222-89212376805
pad: 09512147864-77936258834-40901700703-13541171421-15205431759
*************************** 3. row ***************************
id: 3
k: 50204693
c: 26283585383-48610978532-72166636310-67148386979-89643583984-06169170732-23477134062-17788128188-73465768032-24619558652
pad: 21979564480-87492594656-60524686334-78820761788-57684966682
*************************** 4. row ***************************
id: 4
k: 52180295
c: 72200234338-75748118569-08939863650-01688814841-36798767826-71560494483-89421079440-11810718401-29133837777-68338627243
pad: 80945118876-33522718290-51523426562-15979384524-91541356971
*************************** 5. row ***************************
id: 5
k: 41395699
c: 29279855805-99348203463-85191104223-39587263726-81794340135-73817557808-54578801760-64404111877-55434439976-37212880746
pad: 59222897263-22759023974-22020489960-93434521232-77981152534
5 rows in set (0.00 sec)
測試結果說明:
- No DB drivers specified, using mysql
- Running the test with following options:
- Number of threads: 1
- Random number generator seed is 0 and will be ignored
- 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
- Using 1 test tables
- Threads started!
- Done.
- OLTP test statistics:
- queries performed:
- read: 140000 -- 讀總數
- write: 50000 -- 寫總數
- other: 20000 -- 其他操作總數(除了dml之外的操作)
- total: 210000 -- 全部總數
- transactions: 10000 (229.62 per sec.) -- 總事務數
- deadlocks: 0 (0.00 per sec.) -- 死鎖數
- read/write requests: 190000 (4362.73 per sec.) -- 讀寫總數
- other operations: 20000 (459.23 per sec.) -- 其他操作總數
- General statistics:
- total time: 43.5507s -- 總耗時
- total number of events: 10000 -- 總共發生的事務數
- total time taken by event execution: 43.4491 -- 所有事務耗時相加(不考慮並行因素)
- response time:
- min: 3.75ms -- 最小耗時
- avg: 4.34ms -- 平均耗時
- max: 30.58ms -- 最大耗時
- approx. 95 percentile: 4.44ms -- 去掉5%的最大最小值,剩餘95%平均耗時
- Threads fairness:
- events (avg/stddev): 10000.0000/0.00
- execution time (avg/stddev): 43.4491/0.00
附錄: (通用選項)
- Usage:
- sysbench [general-options]... --test= [test-options]... command
- General options:
- --num-threads=N number of threads to use [1]
- --max-requests=N limit for total number of requests [10000]
- --max-time=N limit for total execution time in seconds [0]
- --forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]
- --thread-stack-size=SIZE size of stack per thread [64K]
- --tx-rate=N target transaction rate (tps) [0]
- --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
- --report-checkpoints=[LIST,...]dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
- --test=STRING test to run
- --debug=[on|off] print more debugging info [off]
- --validate=[on|off] perform validation checks where possible [off]
- --help=[on|off] print help and exit
- --version=[on|off] print version and exit [off]
- --rand-init=[on|off] initialize random number generator [off]
- --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
- --rand-spec-iter=N number of iterations used for numbers generation [12]
- --rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]
- --rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]
- --rand-seed=N seed for random number generator, ignored when 0 [0]
- --rand-pareto-h=N parameter h for pareto distibution [0.2]
- Log options:
- --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
- --percentile=N percentile rank of query response times to count [95]
- 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
- Commands: prepare run cleanup help version
- See 'sysbench --test= help' for a list of options for each test.
作者公眾號(持續更新)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29773961/viewspace-1849676/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【工具】sysbench 0.5 簡介
- 壓力測試sysbench安裝及引數介紹
- sysbench安裝及簡單使用
- sysbench工具手把手安裝配置及使用案例
- Sysbench使用簡介
- 官方壓測工具mysqlslap介紹及使用MySql
- Mysql 壓力測試工具sysbenchMySql
- 壓測工具之Sysbench(1_系統壓測)
- ELK esrally 壓測工具安裝使用
- Jmeter 4.0壓力測試工具安裝及使用方法JMeter
- Locust 簡介及安裝使用
- 壓測工具之Sysbench1.0(2_MySQL壓測)MySql
- MySQL DB Server 上面安裝 sysbench 作壓力測試MySqlServer
- mysql之 sysbench0.4.12資料庫效能測試MySql資料庫
- sysbench的安裝使用
- mysql壓力測試在青雲PCIE盤sysbench版本MySql
- mysql之 sysbench1.0.3 安裝與系統壓力測試MySql
- sysbench壓測實踐
- ubuntu20.04 安裝 wrk 壓力測試工具以及簡單使用Ubuntu
- PostgreSQL簡介及安裝SQL
- RabbitMQ簡介及安裝MQ
- Django簡介及安裝Django
- Allure簡介及安裝
- Docker簡介及安裝Docker
- [原創]Fitnesse測試工具介紹及安裝
- [原創]zabbix工具介紹,安裝及使用
- NewSQL資料庫壓力測試工具系列——SysbenchSQL資料庫
- CentOS 下安裝 wrk 壓測工具CentOS
- Apache下壓力測試工具ab安裝與使用Apache
- 使用sysbench壓測主機和資料庫資料庫
- 輕量級壓測平臺RunnerGo簡介及使用教程Go
- mysql叢集壓力測試在京東雲盤:sysbench版本MySql
- mysql壓力測試在京東雲ssd雲盤sysbench版本MySql
- KVM簡介,安裝及常見使用詳解
- Sysbench-0.5改成只有DML操作
- sysbench壓測Oracle 11gOracle
- sysbench壓測Oracle 12COracle
- sysbench tpcc 壓測結果分析