日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sysbench 压测 详解

發布時間:2025/3/19 编程问答 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sysbench 压测 详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下載sysbench(mysql官網就有)
解壓,進入解壓以后的目錄
./autogen.sh
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
make && make install
export LD_LIBRARY_PATH=/usr/local/mysql/lib

開始進行測試
通用配置
接下來我們來分別看一下各個模式的相關參數、測試方法和結果分析。
sysbench的基本命令格式為:
sysbench –test=< test-name> [options]… < command>
主要分為三個部分:

1、–test=< test-name>
這部分是指定測試類型,基本類型有fileio,cpu,memory,threads,mutex,oltp(或者指定lua腳本)

2、[options]…
這部分包括測試需要的各種選項,有全局的也有每個測試模式自由的選項
(每個測試模式的選項可以用./sysbench –test=< test-name> help來獲取)

3、< command>
控制命令,總共有五個
prepare #準備測試,主要是生成測試數據
run #執行測試,根據選項限制來執行測試
cleanup #清除準備階段生成的測試數據
help #獲取幫助文檔
version #獲取版本信息

幾個重要的全局參數:
–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] #測試過程總共執行多長時間(和–max-requests效果同樣,但是兩個同時限定的時候誰優先還沒有測試)
–report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] #每隔多少秒輸出測試概況(這個過程你可以觀察到mysql redolog的切換情況)
–db-driver=STRING specifies database driver to use (‘help’ to get list of available drivers) #指定需求測試的數據庫類型,默認是mysql
#mysql鏈接選項
–mysql-host=[LIST,…] MySQL server host [localhost] #mysql主機地址
–mysql-port=N MySQL server port [3306] #mysql端口
–mysql-socket=[LIST,…] MySQL socket #mysql socket文件位置,指定這個之后 其他的鏈接選項均可以不指定
–mysql-user=STRING MySQL user [sbtest] #用來測試的mysql用戶名
–mysql-password=STRING MySQL password [] #密碼
–mysql-db=STRING MySQL database name [sbtest] #測試數據庫名 默認sbtest

1、測試磁盤IO性能

參數詳解: –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。 1)生成測試文件 sysbench --test=fileio --file-num=10 --file-total-size=5G prepare 2)測試 sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on --file-num=10 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run 3)結果如下 sysbench 0.4.12.10: multi-threaded system evaluation benchmarkRunning the test with following options: Number of threads: 16 Initializing random number generator from timer.Random number generator seed is 0 and will be ignoredExtra file open flags: 4000 10 files, 512Mb each 5Gb total file size Block size 16Kb Number of random requests for random IO: 100000000 Read/Write ratio for combined random IO test: 1.50 Calling fsync() at the end of test, Enabled. Using synchronous I/O mode Doing random r/w test Threads started!Time limit exceeded, exiting... (last message repeated 15 times) Done.Operations performed: 17981 reads, 11990 writes, 0 Other = 29971 Total Read 280.95Mb Written 187.34Mb Total transferred 468.3Mb (2.6012Mb/sec)166.48 Requests/sec executedGeneral statistics:total time: 180.0298stotal number of events: 29971total time taken by event execution: 2880.3206response time:min: 0.38msavg: 96.10msmax: 390.42msapprox. 95 percentile: 209.91msThreads fairness:events (avg/stddev): 1873.1875/11.51execution time (avg/stddev): 180.0200/0.01##注意:主要看這里Read 280.95Mb Written 187.34Mb Total transferred 468.3Mb (2.6012Mb/sec) 166.48 Requests/sec executed大概是在180秒里面總共隨機讀取280.95MB ,寫入187.24MB ,平均每秒隨機讀寫的效率時2.6012MB ,IOPS為166.48 Requests/sec 4)清楚測試數據sysbench --test=fileio --file-num=10 --file-total-size=5G cleanup

2、cpu測試
參數詳解:
–cpu-max-prime=N 用來選項指定最大的素數,具體參數可以根據CPU的性能來設置,默認為10000

sysbench --test=cpu --cpu-max-prime=20000 run測試結果sysbench 0.4.12.10: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Random number generator seed is 0 and will be ignoredDoing CPU performance benchmarkPrimer numbers limit: 20000Threads started!Done.General statistics:total time: 20.8126stotal number of events: 10000total time taken by event execution: 20.8006response time:min: 1.91msavg: 2.08msmax: 13.94msapprox. 95 percentile: 2.71msThreads fairness:events (avg/stddev): 10000.0000/0.00execution time (avg/stddev): 20.8006/0.00##注意:測試的總時間(total time)即可(越小越憂)

3、內存分配及傳輸速度(測試了內存的連續讀寫性能)
參數詳解:
–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

sysbench --test=memory --memory-block-size=8K --memory-total-size=1G --num-threads=16 run結果:sysbench 0.4.12.10: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 16Random number generator seed is 0 and will be ignoredDoing memory operations speed testMemory block size: 8KMemory transfer size: 1024MMemory operations type: writeMemory scope type: globalThreads started!Done.Operations performed: 131072 (1223663.93 ops/sec)1024.00 MB transferred (9559.87 MB/sec)General statistics:total time: 0.1071stotal number of events: 131072total time taken by event execution: 0.3210response time:min: 0.00msavg: 0.00msmax: 96.20msapprox. 95 percentile: 0.00msThreads fairness:events (avg/stddev): 8192.0000/7510.93execution time (avg/stddev): 0.0201/0.03

4、oltp-數據庫性能測試
參數詳解:
–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 查詢范圍。默認是100
–oltp-point-selects=N number of point selects [10]
–oltp-simple-ranges=N number of simple ranges [1]
–oltp-sum-ranges=N number of sum ranges [1]
–oltp-order-ranges=N number of ordered ranges [1]
–oltp-distinct-ranges=N number of distinct ranges [1]
–oltp-index-updates=N number of index update [1]
–oltp-non-index-updates=N number of non-index updates [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 值的百分比被視為’special’ (for special distribution)。默認是1
–oltp-dist-res=N ‘special’的百分比值。默認是75

1)創建測試用的數據sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 prepare2)開始測試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=off --max-requests=0 --num-threads=8 run3)結果如下sysbench 0.4.12.10: multi-threaded system evaluation benchmarkNo DB drivers specified, using mysqlRunning the test with following options:Number of threads: 8Random number generator seed is 0 and will be ignoredDoing OLTP test.Running mixed OLTP testUsing Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)Using "BEGIN" for starting transactionsUsing auto_inc on the id columnUsing 1 test tablesThreads started!Time limit exceeded, exiting...(last message repeated 7 times)Done.OLTP test statistics:queries performed:read: 263046write: 93934other: 37574total: 394554transactions: 18785 (313.05 per sec.)deadlocks: 4 (0.07 per sec.)read/write requests: 356980 (5948.98 per sec.)other operations: 37574 (626.16 per sec.)General statistics:total time: 60.0069stotal number of events: 18785total time taken by event execution: 479.9184response time:min: 2.23msavg: 25.55msmax: 1696.98msapprox. 95 percentile: 54.14msThreads fairness:events (avg/stddev): 2348.1250/6.21execution time (avg/stddev): 59.9898/0.00

##主要注意這幾個參數 transactions: 18785 (313.05 per sec.)
read/write requests: 356980 (5948.98 per sec.)
other operations: 37574 (626.16 per sec.)

4)清除數據
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=off --max-requests=0 --num-threads=8 cleanup

轉載于:https://blog.51cto.com/13214087/2140038

總結

以上是生活随笔為你收集整理的sysbench 压测 详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。