MySQL基準測試和sysbench工具

參考https://www.cnblogs.com/kismetv/archive/2017/09/30/7615738.html

1、基準測試的做用

sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,能夠用來進行CPU、內存、磁盤I/O、線程、數據庫的性能測試。目前支持的數據庫有MySQL、Oracle和PostgreSQL。如下操做都將以支持MySQL數據庫爲例進行。 
Sysbench的測試主要包括如下幾個方面: 
一、磁盤io性能 
二、cpu性能 
三、內存分配及傳輸速度 
四、POSIX線程性能 
五、調度程序性能 
六、數據庫性能(OLTP基準測試).html

2、基準測試的指標mysql

常見的數據庫指標包括:linux

  • TPS/QPS:衡量吞吐量。
  • 響應時間:包括平均響應時間、最小響應時間、最大響應時間、時間百分比等,其中時間百分比參考意義較大,如前95%的請求的最大響應時間。。
  • 併發量:同時處理的查詢請求的數量。

 

3、基準測試的分類

 

對MySQL的基準測試,有以下兩種思路:c++

 

(1)針對整個系統的基準測試:經過http請求進行測試,如經過瀏覽器、APP或postman等測試工具。該方案的優勢是可以更好的針對整個系統,測試結果更加準確;缺點是設計複雜實現困難。git

 

(2)只針對MySQL的基準測試:優勢和缺點與針對整個系統的測試剛好相反。github

 

在針對MySQL進行基準測試時,通常使用專門的工具進行,例如mysqlslap、sysbench等。其中,sysbench比mysqlslap更通用、更強大,且更適合Innodb(由於模擬了許多Innodb的IO特性),下面介紹使用sysbench進行基準測試的方法。sql

 

4、安裝數據庫

https://github.com/akopytov/sysbench官網數組

#git clone https://github.com/akopytov/sysbench.git瀏覽器

#autogen.sh 運行生成configure

#./configure --prefix=/root/sysbench --with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/

 

#make && make install

 

 

 

 

默認支持MySQL,若是須要測試Oracle/PostgreSQL,則在configure時須要加上–with-oracle或者–with-pgsql參數.

依賴庫安裝 
須要安裝m4 autoconf automake libtool 這幾個包,經過 
yum install m4 autoconf automake libtool可進行安裝,不然會報錯( xxx… wasn’t found, exiting) 
./autogen.sh (若是是源碼編譯安裝就不須要執行了) 
執行後在目錄下會出現configure文件夾,就說明能夠開始執行配置了。

./configure --prefix=/root/sysbench --with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/

須要指定include和lib目錄。若是沒有,說明安裝時候沒有安裝安裝開發包,這個要單獨安裝的,找Development Libraries 包. 
安裝完成後執行:

[root@localhost sysbench]# ll -rth sysbench
total 236K
-rw-r--r--. 1 root root 7.1K Jun 18 04:12 sysbench.h
[root@localhost sysbench]# make
Making all in doc
make[1]: Entering directory `/root/sysbench/doc' ...... [root@localhost sysbench]# make install Making install in doc make[1]: Entering directory `/root/sysbench/doc' .....

沒有報錯的話就在當前的/root/sysbench/sysbench目錄下會生成一個二進制可執行文件:sysbench

[root@localhost sysbench]# ll
total 4096
-rw-r--r--. 1 root root 3661 Jun 18 04:12 CMakeLists.txt -rw-r--r--. 1 root root 24391 Jun 18 04:12 db_driver.c -rw-r--r--. 1 root root 9911 Jun 18 04:12 db_driver.h -rw-r--r--. 1 root root 129832 Jun 18 08:49 db_driver.o drwxr-xr-x. 7 root root 4096 Jun 18 12:50 drivers -rw-r--r--. 1 root root 25253 Jun 18 12:50 Makefile -rw-r--r--. 1 root root 2020 Jun 18 04:12 Makefile.am -rw-r--r--. 1 root root 25998 Jun 18 06:12 Makefile.in -rw-r--r--. 1 root root 3640 Jun 18 04:12 sb_list.h -rw-r--r--. 1 root root 16223 Jun 18 04:12 sb_logger.c -rw-r--r--. 1 root root 4554 Jun 18 04:12 sb_logger.h -rw-r--r--. 1 root root 116256 Jun 18 08:49 sb_logger.o -rw-r--r--. 1 root root 13731 Jun 18 04:12 sb_options.c -rw-r--r--. 1 root root 3108 Jun 18 04:12 sb_options.h -rw-r--r--. 1 root root 109536 Jun 18 08:49 sb_options.o -rw-r--r--. 1 root root 3456 Jun 18 04:12 sb_percentile.c -rw-r--r--. 1 root root 1570 Jun 18 04:12 sb_percentile.h -rw-r--r--. 1 root root 64616 Jun 18 08:49 sb_percentile.o -rw-r--r--. 1 root root 5982 Jun 18 04:12 sb_timer.c -rw-r--r--. 1 root root 3796 Jun 18 04:12 sb_timer.h -rw-r--r--. 1 root root 54544 Jun 18 08:49 sb_timer.o -rw-r--r--. 1 root root 6860 Jun 18 04:12 sb_win.c -rw-r--r--. 1 root root 2747 Jun 18 04:12 sb_win.h drwxr-xr-x. 4 root root 4096 Jun 18 12:50 scripting -rwxr-xr-x. 1 root root 3300573 Jun 18 12:24 sysbench [root@localhost sysbench]# ./sysbench --help ./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory [root@localhost sysbench]# ldd sysbench linux-vdso.so.1 => (0x00007fff3dd70000) libmysqlclient.so.18 => not found //重點在這裏,連接庫沒找到,只好手動加一下 libdl.so.2 => /lib64/libdl.so.2 (0x00007f95b0e55000) librt.so.1 => /lib64/librt.so.1 (0x00007f95b0c4d000) libm.so.6 => /lib64/libm.so.6 (0x00007f95b09c9000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f95b07ab000) libc.so.6 => /lib64/libc.so.6 (0x00007f95b0417000)  /lib64/ld-linux-x86-64.so.2 (0x00007f95b1068000) [root@localhost sysbench]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib //手動創建一個軟連接 [root@localhost sysbench]# ldconfig //生效 [root@localhost sysbench]# ldd sysbench //在查看就找到ibmysqlclient.so.18 linux-vdso.so.1 => (0x00007fffc5ffc000) libmysqlclient.so.18 => /usr/lib/libmysqlclient.so.18 (0x00007fa7895d8000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fa7893d4000) librt.so.1 => /lib64/librt.so.1 (0x00007fa7891cb000) libm.so.6 => /lib64/libm.so.6 (0x00007fa788f47000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa788d2a000) libc.so.6 => /lib64/libc.so.6 (0x00007fa788995000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fa78868f000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa788479000)  /lib64/ld-linux-x86-64.so.2 (0x00007fa789bb0000) [root@localhost sysbench]# ./sysbench --help //執行help成功 [root@localhost ~]# sysbench --help Missing required command argument. Usage: sysbench [general-options]... --test=<test-name> [test-options]... command General options: --num-threads=N 使用線程數 默認[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=<name> help' for a list of options for each test.
  • 測試fileio命令幫助:
[root@db-master ~]# sysbench --test=fileio help  
sysbench 0.4.12:  multi-threaded system evaluation benchmark
fileio options: 
參數詳解:
--file-num=N 表明生成測試文件的數量,默認爲128。 --file-block-size=N 測試時所使用文件塊的大小,若是想磁盤針對innodb存儲引擎進行測試,能夠將其設置爲16384,即innodb存儲引擎頁的大小。默認爲16384。 --file-total-size=SIZE 建立測試文件的總大小,默認爲2G大小。 --file-test-mode=STRING 文件測試模式,包含:seqwr(順序寫), seqrewr(順序讀寫), seqrd(順序讀), rndrd(隨機讀), rndwr(隨機寫), rndrw(隨機讀寫)。 --file-io-mode=STRING 文件操做的模式,sync(同步),async(異步),fastmmap(快速mmap),slowmmap(慢速mmap),默認爲sync同步模式。 --file-async-backlog=N 對應每一個線程隊列的異步操做數,默認爲128。 --file-extra-flags=STRING 打開文件時的選項,這是與API相關的參數。 --file-fsync-freq=N 執行fsync()函數的頻率。fsync主要是同步磁盤文件,由於可能有系統和磁盤緩衝的關係。 0表明不使用fsync函數。默認值爲100。 --file-fsync-all=[on|off] 每執行完一次寫操做,就執行一次fsync。默認爲off。 --file-fsync-end=[on|off] 在測試結束時執行fsync函數。默認爲on。 --file-fsync-mode=STRING文件同步函數的選擇,一樣是和API相關的參數,因爲多個操做系統對於fdatasync支持不一樣,所以不建議使用fdatasync。默認爲fsync。 --file-merged-requests=N 大多狀況下,合併可能的IO的請求數,默認爲0。 --file-rw-ratio=N 測試時的讀寫比例,默認時爲1.5,便可3:2。

測試cpu命令幫助:

[root@db-master ~]# sysbench --test=cpu help sysbench 0.4.12: multi-threaded system evaluation benchmark cpu options: 參數詳解: --cpu-max-prime=N 用來選項指定最大的素數,具體參數能夠根據CPU的性能來設置,默認爲10000

測試memory命令幫助:

[root@db-master ~]# sysbench --test=memory help sysbench 0.4.12: multi-threaded system evaluation benchmark memory options: 參數詳解: --memory-block-size=SIZE 測試內存塊的大小,默認爲1K --memory-total-size=SIZE 數據傳輸的總大小,默認爲100G --memory-scope=STRING 內存訪問的範圍,包括全局和本地範圍,默認爲global --memory-hugetlb=[on|off] 是否從HugeTLB池分配內存的開關,默認爲off --memory-oper=STRING 內存操做的類型,包括read, write, none,默認爲write --memory-access-mode=STRING 內存訪問模式,包括seq,rnd兩種模式,默認爲seq

測試threads命令幫助:

[root@db-master ~]# sysbench --test=threads help sysbench 0.4.12: multi-threaded system evaluation benchmark threads options: 參數詳解: --thread-yields=N 指定每一個請求的壓力,默認爲1000 --thread-locks=N 指定每一個線程的鎖數量,默認爲8

 

測試mutex命令幫助:

[root@db-master ~]# sysbench  --test=mutex help 
sysbench 0.4.12:  multi-threaded system evaluation benchmark
mutex options:
參數詳解:
  --mutex-num=N 數組互斥的總大小。默認是4096 --mutex-locks=N 每一個線程互斥鎖的數量。默認是50000 --mutex-loops=N 內部互斥鎖的空循環數量。默認是10000

 

測試oltp命令幫助:

[root@db-master ~]# sysbench --test=oltp help 
sysbench 0.4.12:  multi-threaded system evaluation benchmark
oltp options:
參數詳解:
  --oltp-test-mode=STRING 執行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默認是complex --oltp-reconnect-mode=STRING 從新鏈接模式{session(不使用從新鏈接。每一個線程斷開只在測試結束),transaction(在每次事務結束後從新鏈接),query(在每一個SQL語句執行完從新鏈接),random(對於每一個事務隨機選擇以上從新鏈接模式)}。默認是session --oltp-sp-name=STRING 存儲過程的名稱。默認爲空 --oltp-read-only=[on|off] 只讀模式。Update,delete,insert語句不可執行。默認是off --oltp-skip-trx=[on|off] 省略begin/commit語句。默認是off --oltp-range-size=N 範圍查詢的範圍大小,該值應比oltp-table-size小。默認是100 --oltp-point-selects=N 單個事務中指定的selec查詢個數 [10] --oltp-simple-ranges=N 單個事務中指定的簡單範圍查詢個數 [1] --oltp-sum-ranges=N 單個事務中指定的SUM範圍查詢個數 [1] --oltp-order-ranges=N 單個事務中指定的ORDER範圍查詢個數 [1] --oltp-distinct-ranges=N 單個事務中指定的DISTINCT範圍查詢個數 [1] --oltp-index-updates=N 單個事務中指定的使用索引更新的個數 [1] --oltp-non-index-updates=N 單個事務中指定的不使用索引更新的個數 [1] --oltp-nontrx-mode=STRING 查詢類型對於非事務執行模式{select, update_key, update_nokey, insert, delete} [select] --oltp-auto-inc=[on|off] AUTO_INCREMENT是否開啓。默認是on --oltp-connect-delay=N 在多少微秒後鏈接數據庫。默認是10000 --oltp-user-delay-min=N 每一個請求最短等待時間。單位是ms。默認是0 --oltp-user-delay-max=N 每一個請求最長等待時間。單位是ms。默認是0 --oltp-table-name=STRING 測試時使用到的表名。默認是sbtest --oltp-table-size=N 測試表的記錄數。默認是10000 --oltp-dist-type=STRING 分佈的隨機數{uniform(均勻分佈),Gaussian(高斯分佈),special(空間分佈)}。默認是special --oltp-dist-iter=N 產生數的迭代次數。默認是12 --oltp-dist-pct=N 特殊分佈的百分比值 (for special distribution)。 默認是1 --oltp-dist-res=N ‘special’的百分比值。默認是75 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 pgsql - PostgreSQL driver mysql options: --mysql-host=[LIST,...] MySQL server 地址 默認[localhost] --mysql-port=N MySQL server 端口 默認[3306] --mysql-socket=STRING MySQL socket --mysql-user=STRING MySQL 用戶名 默認[sbtest] --mysql-password=STRING MySQL 密碼 默認[] --mysql-db=STRING MySQL database name [sbtest] --mysql-table-engine=STRING 使用的存儲引擎包括{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 [] pgsql options: --pgsql-host=STRING PostgreSQL server host [localhost] --pgsql-port=N PostgreSQL server port [5432] --pgsql-user=STRING PostgreSQL user [sbtest] --pgsql-password=STRING PostgreSQL password [] --pgsql-db=STRING PostgreSQL database name [sbtest]
  • 總結: 

以上就是sysbench工具的安裝配置及相關選項參數的介紹,能夠根據本身的須要添加對應的參數進行壓力測試便可。在下一篇文檔中將會對上面的幾種模式進行相應的測試。

不用在目錄執行sysbench

[root@localhost sysbench]# cp /root/sysbench/sysbench/sysbench /usr/local/bin/ [root@localhost sysbench]# cd /root [root@localhost ~]# sysbench --help
  • 1
  • 2
  • 3

CPU測試:

sysbench CPU測試使用64位整數,測試計算素數直到某個最大值(cpu-max-prime)所須要的時間, 
查看CPU信息方法 
查看物理cpu個數 
grep "physical id" /proc/cpuinfo | sort -u | wc -l 
查看核心數量 
grep "core id" /proc/cpuinfo | sort -u | wc -l 
查看線程數量 
grep "processor" /proc/cpuinfo | sort -u | wc -l

在sysbench的測試中,–num-threads取值爲」線程數量」便可

[root@localhost ~]# sysbench --test=cpu --cpu-max-prime=10000 --num-threads=2 run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 2 Random number generator seed is 0 and will be ignored Primer numbers limit: 10000 Threads started! General statistics: total time: 6.0122s total number of events: 10000 total time taken by event execution: 12.0109s response time: min: 1.04ms avg: 1.20ms max: 7.87ms approx. 95 percentile: 1.43ms Threads fairness: events (avg/stddev): 5000.0000/9.00 execution time (avg/stddev): 6.0055/0.00

線程(thread)測試

測試線程調度器的性能。對於高負載狀況下測試線程調度器的行爲很是有用

[root@localhost ~]# sysbench --test=threads --num-threads=2 --thread-yields=100 --thread-locks=2 run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 2 Random number generator seed is 0 and will be ignored Threads started! General statistics: total time: 0.4479s total number of events: 10000 total time taken by event execution: 0.8868s response time: min: 0.02ms avg: 0.09ms max: 3.87ms approx. 95 percentile: 0.14ms Threads fairness: events (avg/stddev): 5000.0000/1.00 execution time (avg/stddev): 0.4434/0.00

文件IO性能測試

生成須要的測試文件,文件總大小5G,16個併發線程。執行完後會在當前目錄下生成一堆小文件。 
在測試以前先看下磁盤空間

[root@localhost ~]# df -hl Filesystem Size Used Avail Use% Mounted on /dev/sda1 52G 11G 41G 21% / tmpfs 497M 0 497M 0% /dev/shm [root@localhost ~]# sysbench --test=fileio --file-total-size=2g --file-test-mode=rndrw --num-threads=2 --init-rng=on --file-num=16 --file-block-size=16384 run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 2 Random number generator seed is 0 and will be ignored Extra file open flags: 0 16 files, 128Mb each 2Gb total file size Block size 16Kb Number of IO requests: 10000 Read/Write ratio for combined random IO test: 1.50 Periodic FSYNC enabled, calling fsync() each 100 requests. Calling fsync() at the end of test, Enabled. Using synchronous I/O mode Doing random r/w test Threads started! Operations performed: 5999 reads, 4001 writes, 1600 Other = 11600 Total Read(每秒隨機讀) 93.734Mb Written(隨機寫) 62.516Mb Total transferred 156.25Mb (27.144Mb/sec) 吞吐量 1737.20 Requests/sec executed General statistics: total time: 5.7564s total number of events: 10000 total time taken by event execution: 5.0908s response time: min: 0.00ms avg: 0.51ms max: 159.40ms approx. 95 percentile: 0.13ms Threads fairness: events (avg/stddev): 5000.0000/306.00 execution time (avg/stddev): 2.5454/0.50 測試完成執行cleanup 測試結束後,記得執行cleanup,以確保測試所產生的文件都已刪除: [root@localhost ~]# sysbench --test=fileio --file-num=16 --file-total-size=2g cleanup sysbench 0.5: multi-threaded system evaluation benchmark Removing test files...

互斥鎖(Mutex)測試

測試互斥鎖的性能,方式是模擬全部線程在同一時刻併發運行,並都短暫請求互斥鎖。

[root@localhost ~]# sysbench --test=mutex --num-threads=2 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 2 Random number generator seed is 0 and will be ignored Threads started! General statistics: total time: 0.0013s total number of events: 2 total time taken by event execution: 0.0010s response time: min: 0.46ms avg: 0.52ms max: 0.59ms approx. 95 percentile: 0.58ms Threads fairness: events (avg/stddev): 1.0000/0.00 execution time (avg/stddev): 0.0005/0.00

 

內存測試

內存測試測試了內存的連續讀寫性能。

[root@localhost ~]# sysbench --test=memory --num-threads=2 --memory-block-size=8192 --memory-total-size=1g run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 2 Random number generator seed is 0 and will be ignored Threads started! Operations performed: 131072 (1264058.81 ops/sec) 1024.00 MB transferred (9875.46 MB/sec) 吞吐量 General statistics: total time: 0.1037s total number of events: 131072 total time taken by event execution: 0.1677s response time: min: 0.00ms avg: 0.00ms max: 4.30ms approx. 95 percentile: 0.00ms 95%的時間分佈 Threads fairness: events (avg/stddev): 65536.0000/509.00 execution time (avg/stddev): 0.0839/0.00

對mysql事務型OLTP的測試

sysbench 0.5經過一系列LUA腳原本替換以前的oltp,來模擬更接近真實的基準測試環境。這些測試腳本包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua,腳本使用方式基本相似。 
sysbench 0.5默認使用sbtest庫,可是須要本身手工先建立好,也可使用–mysql-db指定,其餘非默認項指定選項:

-mysql-host -mysql-port -mysql-socket -mysql-user -mysql-password -mysql-db -mysql-ssl

prepare 
生成表並插入數據,可以使用parallel_prepare.lua腳原本並行準備數據。

–db-driver 服務器類型 mysql | drizzle,默認爲mysql –mysql-table-engine 表存數引擎 –myisam-max-rows MyISAM表MAX_ROWS選項(用於大表) –oltp-table-count 生成表數量[sbtest一、sbtest2...] –oltp-table-size 生成表的行數 –oltp-secondary ID列生成二級索引而不是主鍵 –oltp-auto-inc 設置ID列是否自增 on | off,默認爲on

1 prepare準備階段

首先要作的就是數據準備 
對於mysql的OLTP測試,和file同樣,一樣須要經歷prepare,run,cleanup三個階段。prepare階段會在數據庫中產生一張指定行數的表,默認表在sbtest架構下,表名爲 
sbtest(sysbench默認生成表的存儲引擎爲innodb),如建立一張100萬條記錄的表: 
create database sbtest; 
而後

[root@localhost ~]# cd /root/sysbench/sysbench/ ./sysbench --test=tests/db/parallel_prepare.lua --max-time=100 --oltp-dist-type=uniform --max-requests=0 --mysql-user=root --mysql-password="" --mysql-table-engine=innodb --oltp-table-size=100 --oltp-tables-count=8 --oltp-range-size=90 --oltp-point-selects=1 --oltp-simple-ranges=1 --oltp-sum-ranges=1 --oltp-order-ranges=1 --oltp-distinct-ranges=1 --oltp-non-index-updates=10 --num-threads=20 --mysql-host=127.0.0.1 --mysql-port=3306 prepare

測試:

./sysbench --test=tests/db/oltp.lua --max-time=100 --oltp-dist-type=uniform --max-requests=0 --mysql-user=root --mysql-password="" --mysql-table-engine=innodb --oltp-table-size=100 --oltp-tables-count=8 --oltp-range-size=90 --oltp-point-selects=1 --oltp-simple-ranges=1 --oltp-sum-ranges=1 --oltp-order-ranges=1 --oltp-distinct-ranges=1 --oltp-non-index-updates=10 --num-threads=20 --mysql-host=127.0.0.1 --mysql-port=3306 run

參數說明: 
–test 指定使用的測試腳本 
–max-time=100 指定測試時長爲100s 
–mysql-user 數據庫賬號 
–mysql-password 數據庫密碼 
–mysql-table-engine 存儲引擎類型 
–test 測試的類型oltp系統 
–num-threads 測試的線程數 
–mysql-host 數據庫地址 
–mysql-port 數據庫端口

測試結果:

Threads started!

OLTP test statistics:
    queries performed:
        read: 179470-- 讀總數 write: 453935-- 寫總數 other: 70678-- 其餘操做總數(SELECT、INSERT、UPDATE、DELETE以外的操做,例如COMMIT等) total: 704083 -- 所有總數 transactions事務量: 34784 (347.32 per sec.)-- 總事務數(每秒事務數) read/write requests讀寫總操做: 633405 (6324.57 per sec.) -- 讀寫總數(每秒讀寫次數) other operations其餘操做: 70678 (705.72 per sec.)-- 其餘操做總數(每秒其餘操做次數) ignored errors: 1110 (11.08 per sec.)-- 每秒忽略的錯誤 reconnects: 0 (0.00 per sec.)--每秒重連次數 General statistics: total time(總時長): 100.1499s -- 總耗時 total number of events: 34784 -- 共發生多少事務數 total time taken by event execution: 1996.2507s -- 全部事務耗時相加(不考慮並行因素) response time(相應時間): min最小: 2.54ms-- 最小耗時 avg平均: 57.39ms-- 平均耗時 max最大: 1074.85ms -- 最長耗時 approx. 95 percentile: 133.50ms-- 超過99%平均耗時 Threads fairness: events (avg/stddev): 1739.2000/35.03 execution time (avg/stddev): 99.8125/0.05

而後進mysql刪除sbtest庫

mysql> drop database sbtest; Query OK, 0 rows affected (0.54 sec)

能夠對數據庫進行調優後,再使用sysbench對OLTP進行測試,看看TPS是否是會有所提升。 
注意:sysbench的測試只是基準測試,並不能表明實際企業環境下的性能指標。

轉自 https://blog.csdn.net/johnstrive/article/details/46610541,若有侵權,請告知並當即刪除。
相關文章
相關標籤/搜索