服務(wù)器性能測試?yán)髦畇ysbench詳解
前言
sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,可以用來進(jìn)行CPU、內(nèi)存、磁盤I/O、線程、數(shù)據(jù)庫的性能測試。sysbench是基于LuaJIT的可編寫腳本的多線程基準(zhǔn)測試工具。
sysbench附帶以下捆綁的基準(zhǔn)測試:
oltp_*.lua:類似OLTP的數(shù)據(jù)庫基準(zhǔn)測試的集合fileio:文件系統(tǒng)級基準(zhǔn)cpu:簡單的CPU基準(zhǔn)測試memory:內(nèi)存訪問基準(zhǔn)threads:基于線程的調(diào)度程序基準(zhǔn)mutex:POSIX互斥基準(zhǔn)測試
特征
- 提供有關(guān)速率和延遲的大量統(tǒng)計信息,包括延遲百分位數(shù)和直方圖;
- 即使有數(shù)千個并發(fā)線程,開銷也很低。sysbench每秒能夠生成和跟蹤數(shù)億個事件。
- 通過在用戶提供的Lua腳本中實現(xiàn)預(yù)定義的掛鉤,可以輕松創(chuàng)建新的基準(zhǔn)測試;
- 可以也可以作為一個通用的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測試主要是進(jìn)行素數(shù)的加法運(yùn)算,我們的例子中,指定了最大的質(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秒(這個測試最好是兩臺機(jī)器進(jìn)行對比測試,才能發(fā)現(xiàn)那個機(jī)器有問題)
2.對內(nèi)存(memory)進(jìn)行測試
測試是在內(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.00totaltime為1.8045s
3.對disk 的IO測試
新建一個臨時目錄,并確保磁盤剩余空間足夠(--file-total-size不要超過剩余容量)
測試場景:16個線程,創(chuàng)建128個文件,總共占用磁盤空間10GB,測試磁盤讀寫效率
運(yùn)行結(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ù)應(yīng)用,使用sysbench自帶的腳本就足夠了。不同版本的sysbench中,lua腳本的位置可能不同,可以自己在sysbench路徑下使用find命令搜索oltp.lua。
P.S.:大多數(shù)數(shù)據(jù)服務(wù)都是oltp類型的,如果你不了解什么是oltp,那么大概率你的數(shù)據(jù)服務(wù)就是oltp類型的。MySQL OLTP(On-Line Transaction Processing聯(lián)機(jī)事務(wù)處理過程);
- (1)盡量不要在MySQL服務(wù)器運(yùn)行的機(jī)器上進(jìn)行測試,一方面可能無法體現(xiàn)網(wǎng)絡(luò)(哪怕是局域網(wǎng))的影響,另一方面,sysbench的運(yùn)行(尤其是設(shè)置的并發(fā)數(shù)較高時)會影響MySQL服務(wù)器的表現(xiàn)。
- (2)可以逐步增加客戶端的并發(fā)連接數(shù)(--thread參數(shù)),觀察在連接數(shù)不同情況下,MySQL服務(wù)器的表現(xiàn);如分別設(shè)置為10,20,50,100等。
- (3)一般執(zhí)行模式選擇complex即可,如果需要特別測試服務(wù)器只讀性能,或不使用事務(wù)時的性能,可以選擇simple模式或nontrx模式。
- (4)如果連續(xù)進(jìn)行多次測試,注意確保之前測試的數(shù)據(jù)已經(jīng)被清理干凈。
下面是sysbench使用的一個例子:
注意:先準(zhǔn)備數(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 runRunning 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:事務(wù)總數(shù)及tps
Latency-95th percentile:前95%的請求的最大響應(yīng)時間,本例中是344毫秒,這個延遲非常大,是因為我用的MySQL服務(wù)器性能很差;在正式環(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)于服務(wù)器性能測試?yán)髦畇ysbench的文章就介紹到這了,更多相關(guān)服務(wù)器性能測試sysbench內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- MySQL性能壓力基準(zhǔn)測試工具sysbench的使用簡介
- 通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法
- 數(shù)據(jù)庫性能測試之sysbench工具的安裝與用法詳解
- sysbench對mysql壓力測試的詳細(xì)教程
- 使用sysbench來測試MySQL性能的詳細(xì)教程
- 服務(wù)器性能測試?yán)髦畇ysbench詳解
- node+Express測試服務(wù)器性能
- VPS服務(wù)器常用性能測試腳本匯總
- MySQL服務(wù)器的SSD性能問題分析和測試詳解
- 編寫Go程序?qū)ginx服務(wù)器進(jìn)行性能測試的方法
相關(guān)文章
rsync 只同步目錄結(jié)構(gòu)不同步文件的方法
這篇文章主要介紹了rsync 只同步目錄結(jié)構(gòu)不同步文件的方法,需要的朋友可以參考下2015-01-01
MongoDB學(xué)習(xí)筆記(二) 通過samus驅(qū)動實現(xiàn)基本數(shù)據(jù)操作
傳統(tǒng)的關(guān)系數(shù)據(jù)庫一般由數(shù)據(jù)庫(database)、表(table)、記錄(record)三個層次概念組成,MongoDB是由(database)、集合(collection)、文檔對象(document)三個層次組成2013-07-07
koa?TS?ESLint搭建服務(wù)器重構(gòu)版過程詳解
這篇文章主要為大家介紹了koa?TS?ESLint搭建服務(wù)器重構(gòu)版過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
開啟OCSP提升https證書驗證效率解決Let’s Encrypt SSL證書訪問慢的問題
這篇文章主要介紹了Apache、Nginx開啟OCSP提升https證書驗證效率解決Let’s Encrypt SSL證書訪問慢的問題,需要的朋友可以參考下2020-11-11
在Windows上使用qemu安裝ubuntu24.04服務(wù)器的詳細(xì)指南
本文介紹了在Windows上使用QEMU安裝Ubuntu 24.04的全流程:安裝QEMU、準(zhǔn)備ISO鏡像、創(chuàng)建虛擬磁盤、配置啟動參數(shù)(含加速和圖形界面選項)、完成安裝及網(wǎng)絡(luò)設(shè)置,并提供常見問題解決方案,如性能優(yōu)化和鍵盤響應(yīng)問題,感興趣的朋友一起看看吧2025-06-06

