sysbench服務器性能測試

2023-01-10 18:16:20 來源:51CTO博客

1,sysbench簡介

sysbench是一款開源的??多線程????性能測試??工具,可以執行cpu/內存/線程/IO/數據庫等方面的性能測試;包含以下幾種測試:

cpu性能磁盤IO性能調度程序性能內存分配及傳輸速度POSIX線程性能數據庫性能(OLTP基準測試)數據庫目前支持MySQL/PostgreSQL/Oracle?

2,工具安裝

編譯好的離線二進制rpm包下載鏈接:

??????https://github.com/sqm-sys/other-packages/raw/main/sysbench.tar.gz??


(資料圖片僅供參考)

[root@server1 home]# tar zxf sysbench.tar.gz[root@server1 home]# rpm -ivh sysbench/*.rpmwarning: sysbench/ck-0.5.2-2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEYPreparing...                          ################################# [100%]Updating / installing...1:postgresql-libs-9.2.24-8.el7_9   ################################# [ 25%]2:luajit-2.0.4-3.el7               ################################# [ 50%]3:ck-0.5.2-2.el7                   ################################# [ 75%]4:sysbench-1.0.17-2.el7            ################################# [100%]

3,配置參數詳解

[root@server1 home]# sysbench --helpUsage:  sysbench [options]... [testname] [command]General options(常用選項):  --threads=N       //創建測試線程的數目。默認為1                  --events=N        //設置期望執行的時間總數。默認是0,不限制  --time=N          //最大執行時間,單位是s。默認是0,不限制。                 --forced-shutdown=STRING      //超過max-time強制中斷。默認是off。    --thread-stack-size=SIZE      //每個線程的堆棧大小。默認是32k。  --rate=N                      //平均事物速率。0表示不限速  --report-interval=N            //以秒為單位定期報告具有指定間隔的統計信息。0禁用中間報告  --report-checkpoints=[LIST,...] //轉儲全部統計數據并在指定時間點重置所有計數器。參數是一個以逗號分隔的值列表,表示從測試開始到必須執行報告檢查點所經過的時間(以秒為單位)。默認情況下報表檢查點是關閉的。  --debug[=on|off]               //打印更多的調試信息,默認關閉  --validate[=on|off]             //在可能的情況下執行驗證檢查,默認關閉  --help[=on|off]                 //獲取help幫助,以獲取參數使用方式  --version[=on|off]              //查看當前版本信息  --config-file=FILENAME         //包含命令行選項的文件Pseudo-Random Numbers Generator options(偽隨機數發生器選項):  --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. When 0, the current time is used as a RNG seed. [0]  --rand-pareto-h=N  parameter h for pareto distribution [0.2]Log options(日志相關選項):  --verbosity=N   //日志詳細級別 {5 - debug, 0 - 僅critical messages}  默認值 3  --percentile=N      //延時統計(latency statistics)中,需要計算的百分比 (1-100)。設置為0表示禁用百分比值計算。 Use the special  --histogram[=on|off] //在報告中打印延遲直方圖,默認關閉General database options(常用數據庫選項):  --db-driver=STRING  //設置程序使用的數據驅動。默認值mysql;  --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]  --db-debug[=on|off]  //打印數據庫的調試信息,默認關閉Compiled-in database drivers:  mysql - MySQL driver  pgsql - PostgreSQL drivermysql options:  --mysql-host=[LIST,...]          MySQL server host [localhost]  --mysql-port=[LIST,...]          MySQL server port [3306]  --mysql-socket=[LIST,...]        MySQL socket  --mysql-user=STRING              MySQL user [sbtest]  --mysql-password=STRING          MySQL password []  --mysql-db=STRING                MySQL database name [sbtest]  --mysql-ssl[=on|off]             //使用SSL連接,默認關閉  --mysql-ssl-cipher=STRING        //為SSL連接使用特定的密碼  --mysql-compression[=on|off]     //使用壓縮,默認關閉  --mysql-debug[=on|off]          //跟蹤所有客戶端庫調用信息,默認關閉  --mysql-ignore-errors=[LIST,...] //要忽略的錯誤列表,或"all" [1213,1020,1205]  --mysql-dry-run[=on|off]         試運行,假裝所有MySQL客戶端API調用都是成功的,而不執行它們,默認關閉pgsql options:  --pgsql-host=STRING     PostgreSQL server host [localhost]  --pgsql-port=N          PostgreSQL server port [5432]  --pgsql-user=STRING       --pgsql-password=STRING   --pgsql-db=STRING

4,開始測試

1,cpu性能測試

常用參數:

??--cpu-max-prime: 素數生成數量的上限 (默認值10000)??

??--threads: 線程數(默認值1)??

??--time: 運行時長,單位秒??

??--events: event上限次數,默認值為0,若設置100,則表示當完成100次event后,即使時間還有剩,也停止運行;??

執行命令進行cpu測試,cpu測試主要是進行素數的加法運算,下圖中指定了最大的質數發生器數量為20000,我的測試服務器(1C)執行時間大約為9.9s;

//素數上限2萬,默認10秒,2個線程sysbench --test=cpu --cpu-max-prime=20000 --threads=2  run
Running the test with following options:Number of threads: 2   //指定線程數為1(默認值)Initializing random number generator from current timePrime numbers limit: 20000     //每個線程產生的素數上限均為2萬個Initializing worker threads...Threads started!CPU speed:    events per second:   387.24      //所有線程每秒完成了 387.24次eventGeneral statistics:    total time:                          10.0046s   //共耗時10秒    total number of events:              3875    //10秒內所有線程一共完成了3875次eventLatency (ms):         min:                                    2.12     // 完成1次event的最少耗時2.12毫秒         avg:                                    5.15     // 所有event的平均耗時5.15毫秒         max:                                   25.78     // 完成1次event的最多耗時25.78毫秒         95th percentile:                       14.73     // 95%次event在14.73秒毫秒內完成         sum:                                 19956.33     // 所有線程的耗時總和(每個線程耗時10秒,2個線程疊加耗時就是20秒)Threads fairness:    events (avg/stddev):           1937.5000/1.50  // 平均每個線程完成 1937次event,標準差為1.5    execution time (avg/stddev):   9.9782/0.0      // 每個線程平均耗時9.9秒,標準差為0

event:完成了幾輪的素數計算;

stddev(標準差):在相同時間內,多個線程分別完成的素數計算次數是否穩定,如果數值越低,則表示多個線程的結果越接近(越穩定)。該參數對于單線程無意義;

性能指標:

如果有2臺服務器進行cpu性能對比,當素數上限和線程數一致時:相同時間,比較event相同event,比較時間

2,線程測試

常用參數:

??--thread-yields:每個請求產生多少線程,默認值100??

??--thread-locks: 每個線程鎖的數量,默認值8??

??--num-threads: 發送請求線程的數量??

//64個測試線程請求,每個線程請求產生100個數量,每個線程的鎖數量為2sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
sysbench 1.0.17 (using system LuaJIT 2.0.4)Running the test with following options:Number of threads: 64    //指定線程數為64Initializing random number generator from current timeInitializing worker threads...Threads started!General statistics:    total time:                          10.0072s      //共耗時10秒    total number of events:              46303        //10秒內所有線程一共完成了46303次eventLatency (ms):         min:                                    0.19     // 完成1次event的最少耗時0.19毫秒         avg:                                   13.83     // 所有event的平均耗時13.83毫秒         max:                                 4636.20     // 完成1次event的最多耗時4636毫秒         95th percentile:                       36.89     // 95%次event在36.89毫秒內完成         sum:                               640152.82     // 所有線程的耗時總和(每個線程耗時10秒,64個線程疊加耗時就是64秒(1分04s)Threads fairness:    events (avg/stddev):           723.4844/1075.89       // 平均每個線程完成 723次event,標準差為1075    execution time (avg/stddev):   10.0024/0.00            // 每個線程平均耗時10秒,標準差為0

性能指標:

線程并發執行,循環響應信號量花費的時間越少越好。

3,磁盤IO性能測試

常用參數:

??file-num=N 創建測試文件的數量,默認128個????file-block-size=N block size大小,默認16K????file-total-size=SIZE 所有文件的總大小,默認2G????file-test-mode=STRING 測試類型(seqwr:順序寫, seqrewr:順序讀寫, seqrd:順序讀, rndrd:隨機讀, rndwr:隨機寫, rndrw:隨機讀寫)????file-io-mode=STRING I/O模式,需要系統支持,默認sync[sync(同步IO),async(異步IO),mmap()]????file-async-backlog=N每個線程的異步操作隊列數,默認128個,需要--file-io-mode=async;????file-extra-flags=STRING 使用額外的標志來打開文件{sync,dsync,direct} 。默認為空????file-fsync-freq=N 當請求數達到多少時執行fsync()刷新,默認100,0代表過程中不執行????file-fsync-all=[on|off] 執行每一個寫操作后執行fsync()刷新操作,默認關閉off????file-fsync-end=[on|off] 測試結束執行fsync()操作,默認開啟on????file-fsync-mode=STRING 同步刷新方法,默認fsync {fsync, fdatasync}????file-merged-requests=N合并指定數量的IO請求,0代表不合并,默認0????file-rw-ratio=N 讀寫比例,默認1.5/1??

sysbench的性能測試都需要做prepare,run,cleanup這三步,準備數據,跑測試,刪除數據。在準備階段創建測試所需數據,在清理階段刪除這些數據。

//準備測試數據sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare
//磁盤IO壓測測試(指定最大創建16個線程,創建的文件總大小為3G,文件讀寫模式為隨機讀。)sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run
sysbench 1.0.17 (using system LuaJIT 2.0.4)Running the test with following options:Number of threads: 16Initializing random number generator from current timeExtra file open flags: (none)128 files, 24MiB each3GiB total file sizeBlock size 16KiBNumber of IO requests: 0Read/Write ratio for combined random IO test: 1.50Periodic FSYNC enabled, calling fsync() each 100 requests.Calling fsync() at the end of test, Enabled.Using synchronous I/O modeDoing random r/w testInitializing worker threads...Threads started!File operations:    reads/s:                      11466.89    //讀操作耗時/s     writes/s:                     7644.56     //寫操作耗時/s    fsyncs/s:                     24661.17    //fsyncs操作耗時/sThroughput:    read, MiB/s:                  179.17      //讀的速度/s      written, MiB/s:               119.45      //寫的速度/sGeneral statistics:    total time:                          10.0054s   //共耗時時間/s    total number of events:              435984     //共完成的event總數Latency (ms):         min:                                    0.00   //最小耗時         avg:                                    0.37   //平均耗時          max:                                   80.65   //最大耗時         95th percentile:                        1.86   //95% event操作耗時         sum:                               159664.15   //所有線程的耗時總和Threads fairness:    events (avg/stddev):           27249.0000/364.02  //平均每個線程完成events數/標準差    execution time (avg/stddev):   9.9790/0.00        //平均每個線程執行時間/標準差
//清除測試數據sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup

性能指標:

1)衡量磁盤io性能,一般主要看以下幾個指標:

IOPS:每秒讀/寫次數,單位為次(計數)吞吐量:每秒的讀寫數據量,單位為MB/s時延:I/O 操作的發送時間到接收確認所經過的時間

2)不同場景下read/s, writes/s, readMiB/s和writtent MiB/s越大越好

4,內存測試

常用參數:

??memory-block-size=SIZE 測試時內存塊大小 [1K]??

??memory-total-size=SIZE 傳輸數據總大小 [100G]??

??memory-scope=STRING 內存訪問范圍{global,local}。默認是global??

??memory-oper=STRING 內存操作類型 {read, write, none} [write]??

??memory-access-mode=STRING 存儲器存取方式 {seq:順序,rnd:隨機}[默認:seq]??

sysbench內存性能測試,主要是針對不同大小的塊進行連續讀寫或者隨機讀寫操作。在內存性能測試中,events指的是讀/寫一個內存塊。

//指定本次測試整個過程是在內存中傳輸 3G 的數據量,每個 block 大小為 8K,存儲器存取方式為隨機sysbench --test=memory --memory-block-size=8k --memory-total-size=3G  --memory-access-mode=rnd  run
sysbench 1.0.17 (using system LuaJIT 2.0.4)Running the test with following options:Number of threads: 1    //指定默認線程1Initializing random number generator from current timeRunning memory speed test with the following options:  block size: 8KiB    #block塊大小8k  total size: 3072MiB  #總大小8G  operation: write    #內存操作類型(寫)  scope: global   #內存訪問范圍globalInitializing worker threads...Threads started!Total operations: 393216 (112796.84 per second)  //每秒處理大小3072.00 MiB transferred (881.23 MiB/sec)      //每秒傳輸量(881/s)General statistics:    total time:                          3.4843s   //總耗時3.4s    total number of events:              393216    //總events數,即讀寫一個內存塊Latency (ms):         min:                                    0.00   //最小耗時,這里等于0是因為內存塊太小,返回的結果數值精度不夠         avg:                                    0.01   //平均耗時         max:                                   14.63   //最大耗時         95th percentile:                        0.01   //95%events耗時范圍         sum:                                 3301.64   //所有線程總耗時Threads fairness:    events (avg/stddev):           393216.0000/0.00   //平均每個線程完成events數/標準差    execution time (avg/stddev):   3.3016/0.00        //平均每個線程執行時間/標準差

性能指標:

以不同塊的大小傳輸一定得數量的數據吞吐量越大越好。

小結:本文僅實踐cpu,線程,磁盤,內存性能測試,OLTP測試后續補充;

?- mem- memory-block-size=SIZE 測試時內存塊大小 [1K]

- memory-total-size=SIZE 傳輸數據總大小 [100G]

- memory-scope=STRING 內存訪問范圍{global,local}。默認是global

- memory-oper=STRING 內存操作類型 {read, write, none} [write]

- memory-access-mode=STRING 存儲器存取方式 {seq:順序,rnd:隨機} [默認:seq]

ory-block-size=SIZE 測試時內存塊大小 [1K]

- memory-total-size=SIZE 傳輸數據總大小 [100G]

- memory-scope=STRING 內存訪問范圍{global,local}。默認是global

- memory-oper=STRING 內存操作類型 {read, write, none} [write]

- memory-access-mode=STRING 存儲器存取方式 {seq:順序,rnd:隨機} [默認:seq]

標簽: 性能測試 執行時間 內存操作

上一篇:c語言模擬用戶輸入三次密碼并判斷是否正確
下一篇:【獨家焦點】LeetCode.209 長度最小的子數組