服務器性能測試利器之sysbench詳解
前言
sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,可以用來進行CPU、內(nèi)存、磁盤I/O、線程、數(shù)據(jù)庫的性能測試。sysbench是基于LuaJIT的可編寫腳本的多線程基準測試工具。
sysbench附帶以下捆綁的基準測試:
oltp_*.lua
:類似OLTP的數(shù)據(jù)庫基準測試的集合fileio
:文件系統(tǒng)級基準cpu
:簡單的CPU基準測試memory
:內(nèi)存訪問基準threads
:基于線程的調(diào)度程序基準mutex
:POSIX互斥基準測試
特征
- 提供有關(guān)速率和延遲的大量統(tǒng)計信息,包括延遲百分位數(shù)和直方圖;
- 即使有數(shù)千個并發(fā)線程,開銷也很低。sysbench每秒能夠生成和跟蹤數(shù)億個事件。
- 通過在用戶提供的Lua腳本中實現(xiàn)預定義的掛鉤,可以輕松創(chuàng)建新的基準測試;
- 可以也可以作為一個通用的Lua解釋,只需更換
#!/usr/bin/lua
用#!/usr/bin/sysbench
在你的腳本。
安裝
安裝以Centos為例,其他版本或者mac請參考sysbench說明
1.下載安轉(zhuǎn)
wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0.zip" unzip sysbench-1.0.zip cd sysbench-1.0 //安裝依賴 yum install -y automake libtool
2.編譯安裝
./autogen.sh ./configure export LD_LIBRARY_PATH=/usr/include/mysql make make install
3.監(jiān)測是否安裝成功
[root@guanbin-k8s-master ~]# sysbench --version sysbench 1.0.19
測試
1. cpu測試
cpu測試主要是進行素數(shù)的加法運算,我們的例子中,指定了最大的質(zhì)數(shù)發(fā)生器數(shù)量為 20000
[root@guanbin-k8s-master ~]# sysbench --test=cpu --cpu-max-prime=20000 run WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options. sysbench 1.0.19 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Prime numbers limit: 20000 Initializing worker threads... Threads started! CPU speed: events per second: 168.59 General statistics: total time: 10.0027s total number of events: 1687 Latency (ms): min: 5.63 avg: 5.93 max: 66.09 95th percentile: 6.43 sum: 9999.10 Threads fairness: events (avg/stddev): 1687.0000/0.00 execution time (avg/stddev): 9.9991/0.00
執(zhí)行時間 大約為10秒(這個測試最好是兩臺機器進行對比測試,才能發(fā)現(xiàn)那個機器有問題)
2.對內(nèi)存(memory)進行測試
測試是在內(nèi)存中傳輸 10G 的數(shù)據(jù)量,每個 block 大小為 8K
[root@guanbin-k8s-master ~]# sysbench --test=memory --memory-block-size=8k --memory-total-size=10G run WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options. sysbench 1.0.19 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Running memory speed test with the following options: block size: 8KiB total size: 10240MiB operation: write scope: global Initializing worker threads... Threads started! Total operations: 1310720 (724931.70 per second) 10240.00 MiB transferred (5663.53 MiB/sec) General statistics: total time: 1.8045s total number of events: 1310720 Latency (ms): min: 0.00 avg: 0.00 max: 12.44 95th percentile: 0.00 sum: 1441.61 Threads fairness: events (avg/stddev): 1310720.0000/0.00 execution time (avg/stddev): 1.4416/0.00
totaltime為1.8045s
3.對disk 的IO測試
新建一個臨時目錄,并確保磁盤剩余空間足夠(--file-total-size不要超過剩余容量)
測試場景:16個線程,創(chuàng)建128個文件,總共占用磁盤空間10GB,測試磁盤讀寫效率
運行結(jié)束后要刪除臨時測試文件: rm -rf test_file.*
root@guanbin-k8s-master tmp]# sysbench --test=fileio --num-threads=16 --file-total-size=1G --file-test-mode=rndrw prepare WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options. WARNING: --num-threads is deprecated, use --threads instead sysbench 1.0.19 (using bundled LuaJIT 2.1.0-beta2) 128 files, 8192Kb each, 1024Mb total Creating files for the test... Extra file open flags: (none) 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 Creating file test_file.10 Creating file test_file.11 Creating file test_file.12 Creating file test_file.13 Creating file test_file.14 Creating file test_file.15 Creating file test_file.16 Creating file test_file.17 Creating file test_file.18 Creating file test_file.19 Creating file test_file.20 Creating file test_file.21 Creating file test_file.22 Creating file test_file.23 Creating file test_file.24 Creating file test_file.25 Creating file test_file.26 Creating file test_file.27 Creating file test_file.28 Creating file test_file.29 Creating file test_file.30 Creating file test_file.31 Creating file test_file.32 Creating file test_file.33 Creating file test_file.34 Creating file test_file.35 Creating file test_file.36 Creating file test_file.37 Creating file test_file.38 Creating file test_file.39 Creating file test_file.40 Creating file test_file.41 Creating file test_file.42 Creating file test_file.43 Creating file test_file.44 Creating file test_file.45 Creating file test_file.46 Creating file test_file.47 Creating file test_file.48 Creating file test_file.49 Creating file test_file.50 Creating file test_file.51 Creating file test_file.52 Creating file test_file.53 Creating file test_file.54 Creating file test_file.55 Creating file test_file.56 Creating file test_file.57 Creating file test_file.58 Creating file test_file.59 Creating file test_file.60 Creating file test_file.61 Creating file test_file.62 Creating file test_file.63 Creating file test_file.64 Creating file test_file.65 Creating file test_file.66 Creating file test_file.67 Creating file test_file.68 Creating file test_file.69 Creating file test_file.70 Creating file test_file.71 Creating file test_file.72 Creating file test_file.73 Creating file test_file.74 Creating file test_file.75 Creating file test_file.76 Creating file test_file.77 Creating file test_file.78 Creating file test_file.79 Creating file test_file.80 Creating file test_file.81 Creating file test_file.82 Creating file test_file.83 Creating file test_file.84 Creating file test_file.85 Creating file test_file.86 Creating file test_file.87 Creating file test_file.88 Creating file test_file.89 Creating file test_file.90 Creating file test_file.91 Creating file test_file.92 Creating file test_file.93 Creating file test_file.94 Creating file test_file.95 Creating file test_file.96 Creating file test_file.97 Creating file test_file.98 Creating file test_file.99 Creating file test_file.100 Creating file test_file.101 Creating file test_file.102 Creating file test_file.103 Creating file test_file.104 Creating file test_file.105 Creating file test_file.106 Creating file test_file.107 Creating file test_file.108 Creating file test_file.109 Creating file test_file.110 Creating file test_file.111 Creating file test_file.112 Creating file test_file.113 Creating file test_file.114 Creating file test_file.115 Creating file test_file.116 Creating file test_file.117 Creating file test_file.118 Creating file test_file.119 Creating file test_file.120 Creating file test_file.121 Creating file test_file.122 Creating file test_file.123 Creating file test_file.124 Creating file test_file.125 Creating file test_file.126 Creating file test_file.127 1073741824 bytes written in 110.77 seconds (9.24 MiB/sec). [root@guanbin-k8s-master tmp]# sysbench --test=fileio --num-threads=16 --file-total-size=1G --file-test-mode=rndrw run WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options. WARNING: --num-threads is deprecated, use --threads instead sysbench 1.0.19 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 16 Initializing random number generator from current time Extra file open flags: (none) 128 files, 8MiB each 1GiB total file size Block size 16KiB Number of IO requests: 0 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 Initializing worker threads... Threads started! File operations: reads/s: 157.44 writes/s: 104.96 fsyncs/s: 480.79 Throughput: read, MiB/s: 2.46 written, MiB/s: 1.64 General statistics: total time: 13.3355s total number of events: 7865 Latency (ms): min: 0.00 avg: 20.61 max: 1115.85 95th percentile: 142.39 sum: 162071.40 Threads fairness: events (avg/stddev): 491.5625/141.20 execution time (avg/stddev): 10.1295/0.03
吞吐量:讀2.46MiB/s,寫1.64MiB/s; 95%延遲 142.39ms
4.測試mysql性能
測試時使用的腳本為lua腳本,可以使用sysbench自帶腳本,也可以自己開發(fā)。對于大多數(shù)應用,使用sysbench自帶的腳本就足夠了。不同版本的sysbench中,lua腳本的位置可能不同,可以自己在sysbench路徑下使用find命令搜索oltp.lua。
P.S.:大多數(shù)數(shù)據(jù)服務都是oltp類型的,如果你不了解什么是oltp,那么大概率你的數(shù)據(jù)服務就是oltp類型的。MySQL OLTP(On-Line Transaction Processing聯(lián)機事務處理過程);
- (1)盡量不要在MySQL服務器運行的機器上進行測試,一方面可能無法體現(xiàn)網(wǎng)絡(哪怕是局域網(wǎng))的影響,另一方面,sysbench的運行(尤其是設(shè)置的并發(fā)數(shù)較高時)會影響MySQL服務器的表現(xiàn)。
- (2)可以逐步增加客戶端的并發(fā)連接數(shù)(--thread參數(shù)),觀察在連接數(shù)不同情況下,MySQL服務器的表現(xiàn);如分別設(shè)置為10,20,50,100等。
- (3)一般執(zhí)行模式選擇complex即可,如果需要特別測試服務器只讀性能,或不使用事務時的性能,可以選擇simple模式或nontrx模式。
- (4)如果連續(xù)進行多次測試,注意確保之前測試的數(shù)據(jù)已經(jīng)被清理干凈。
下面是sysbench使用的一個例子:
注意:先準備數(shù)據(jù)庫
mysql> create database sbtest;
其中,執(zhí)行模式為complex,使用了10個表,每個表有10萬條數(shù)據(jù),客戶端的并發(fā)線程數(shù)為10,執(zhí)行時間為120秒,每10秒生成一次報告。
sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host={yourhostip} --mysql-port=3306 --mysql-user={username} --mysql-password={password} --oltp-test-mode=complex --mysql-table-engine=innodb --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare
其中的hostip、username、password請自行切換為自己真實的環(huán)境數(shù)據(jù)
查看執(zhí)行結(jié)果
sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host={yourhostip} --mysql-port=3306 --mysql-user={username} --mysql-password={password} --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run
Running the test with following options: Number of threads: 10 Report intermediate results every 10 second(s) Initializing random number generator from current time Initializing worker threads... Threads started! [ 10s ] thds: 10 tps: 17.19 qps: 362.78 (r/w/o: 254.64/72.76/35.38) lat (ms,95%): 1589.90 err/s: 0.00 reconn/s: 0.00 [ 20s ] thds: 10 tps: 33.50 qps: 670.08 (r/w/o: 469.06/134.02/67.01) lat (ms,95%): 530.08 err/s: 0.00 reconn/s: 0.00 [ 30s ] thds: 10 tps: 39.30 qps: 786.00 (r/w/o: 550.20/157.20/78.60) lat (ms,95%): 458.96 err/s: 0.00 reconn/s: 0.00 [ 40s ] thds: 10 tps: 38.80 qps: 775.45 (r/w/o: 543.16/154.69/77.59) lat (ms,95%): 634.66 err/s: 0.00 reconn/s: 0.00 [ 50s ] thds: 10 tps: 30.10 qps: 602.54 (r/w/o: 421.43/120.91/60.20) lat (ms,95%): 590.56 err/s: 0.00 reconn/s: 0.00 [ 60s ] thds: 10 tps: 33.90 qps: 678.00 (r/w/o: 474.60/135.60/67.80) lat (ms,95%): 419.45 err/s: 0.00 reconn/s: 0.00 [ 70s ] thds: 10 tps: 29.50 qps: 589.98 (r/w/o: 412.99/118.00/59.00) lat (ms,95%): 787.74 err/s: 0.00 reconn/s: 0.00 [ 80s ] thds: 10 tps: 39.90 qps: 798.02 (r/w/o: 558.62/159.60/79.80) lat (ms,95%): 569.67 err/s: 0.00 reconn/s: 0.00 [ 90s ] thds: 10 tps: 38.10 qps: 761.99 (r/w/o: 533.40/152.40/76.20) lat (ms,95%): 484.44 err/s: 0.00 reconn/s: 0.00 [ 100s ] thds: 10 tps: 43.90 qps: 877.99 (r/w/o: 614.60/175.60/87.80) lat (ms,95%): 383.33 err/s: 0.00 reconn/s: 0.00 [ 110s ] thds: 10 tps: 37.80 qps: 756.00 (r/w/o: 529.20/151.20/75.60) lat (ms,95%): 530.08 err/s: 0.00 reconn/s: 0.00 [ 120s ] thds: 10 tps: 44.40 qps: 888.01 (r/w/o: 621.60/177.60/88.80) lat (ms,95%): 419.45 err/s: 0.00 reconn/s: 0.00 SQL statistics: queries performed: read: 59836 write: 17096 other: 8548 total: 85480 transactions: 4274 (35.59 per sec.) queries: 85480 (711.77 per sec.) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) General statistics: total time: 120.0919s total number of events: 4274 Latency (ms): min: 50.07 avg: 280.96 max: 2486.17 95th percentile: 559.50 sum: 1200810.10 Threads fairness: events (avg/stddev): 427.4000/4.20 execution time (avg/stddev): 120.0810/0.01
其中,對于我們比較重要的信息包括:
queries:查詢總數(shù)及qps
transactions:事務總數(shù)及tps
Latency-95th percentile:前95%的請求的最大響應時間,本例中是344毫秒,這個延遲非常大,是因為我用的MySQL服務器性能很差;在正式環(huán)境中這個數(shù)值是絕對不能接受的。
最后清理數(shù)據(jù):
sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host={yourhostip} --mysql-port=3306 --mysql-user={username} --mysql-password={password} --oltp-tables-count=10 cleanup
清理的日志輸出
sysbench 1.0.19 (using bundled LuaJIT 2.1.0-beta2) Dropping table 'sbtest1'... Dropping table 'sbtest2'... Dropping table 'sbtest3'... Dropping table 'sbtest4'... Dropping table 'sbtest5'... Dropping table 'sbtest6'... Dropping table 'sbtest7'... Dropping table 'sbtest8'... Dropping table 'sbtest9'... Dropping table 'sbtest10'...
到此這篇關(guān)于服務器性能測試利器之sysbench的文章就介紹到這了,更多相關(guān)服務器性能測試sysbench內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Microi 吾碼低代碼解鎖服務器虛擬化無限潛能(最新推薦)
在當今數(shù)字化轉(zhuǎn)型加速的時代背景下,服務器虛擬化技術(shù)已成為信息技術(shù)領(lǐng)域的關(guān)鍵驅(qū)動力之一,這篇文章主要介紹了Microi 吾碼低代碼解鎖服務器虛擬化無限潛能(最新推薦),需要的朋友可以參考下2024-12-12windows服務器如何創(chuàng)建.開頭(.well-known)的文件夾
國內(nèi)的云服務商騰訊云提供免費有效期一年的SSL證書,申請過程中需要身份驗證,需要dns域名解析或者服務器文件驗證。如果想使用文件驗證,必須創(chuàng)建一個以.開頭的文件,使用windows服務器如何創(chuàng)建.開頭的文件夾。2023-04-04jenkins插件pipeline集成持續(xù)交付管道全面介紹
這篇文章主要就jenkins插件pipeline集成持續(xù)交付管道相關(guān)內(nèi)容做一個全面介紹,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步2022-03-03開啟OCSP提升https證書驗證效率解決Let’s Encrypt SSL證書訪問慢的問題
這篇文章主要介紹了Apache、Nginx開啟OCSP提升https證書驗證效率解決Let’s Encrypt SSL證書訪問慢的問題,需要的朋友可以參考下2020-11-11Apache,IIS下Discuz x1.5偽靜態(tài)設(shè)置方法
有時候我們在假設(shè)論壇的時候,為了優(yōu)化搜索引擎收錄效果,需要設(shè)為偽靜態(tài),除了后臺的設(shè)置,也需要服務器支持,下面的具體的實現(xiàn)方法,2011-05-05通過StatefulSet部署有狀態(tài)服務應用實現(xiàn)方式
這篇文章主要為大家介紹了通過StatefulSet部署有狀態(tài)服務應用的實現(xiàn)方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-03-03Red Hat 8.0 使用yum報錯的解決方法:This system&nbs
紅帽使用yum源時提示報錯,因為yum源需要付費注冊,解決方法包括查看已安裝的yum包,刪除所有yum包并檢查,查看系統(tǒng)版本及內(nèi)核信息,下載適合的新的鏡像源,配置依賴源,備份原始repo文件并下載阿里云的repo文件,清除原始配置并使其生效,感興趣的朋友一起看看吧2024-11-11