亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

服務(wù)器性能測(cè)試?yán)髦畇ysbench詳解

 更新時(shí)間:2024年12月17日 08:53:18   作者:心冰之海  
bench是一個(gè)開源的、模塊化的、跨平臺(tái)的多線程性能測(cè)試工具,可以用來(lái)進(jìn)行CPU、內(nèi)存、磁盤I/O、線程、數(shù)據(jù)庫(kù)的性能測(cè)試,sysbench是基于LuaJIT的可編寫腳本的多線程基準(zhǔn)測(cè)試工具,這篇文章主要介紹了服務(wù)器性能測(cè)試?yán)髦畇ysbench,需要的朋友可以參考下

前言

sysbench是一個(gè)開源的、模塊化的、跨平臺(tái)的多線程性能測(cè)試工具,可以用來(lái)進(jìn)行CPU、內(nèi)存、磁盤I/O、線程、數(shù)據(jù)庫(kù)的性能測(cè)試。sysbench是基于LuaJIT的可編寫腳本的多線程基準(zhǔn)測(cè)試工具。

sysbench附帶以下捆綁的基準(zhǔn)測(cè)試:

  • oltp_*.lua:類似OLTP的數(shù)據(jù)庫(kù)基準(zhǔn)測(cè)試的集合
  • fileio:文件系統(tǒng)級(jí)基準(zhǔn)
  • cpu:簡(jiǎn)單的CPU基準(zhǔn)測(cè)試
  • memory:內(nèi)存訪問(wèn)基準(zhǔn)
  • threads:基于線程的調(diào)度程序基準(zhǔn)
  • mutex:POSIX互斥基準(zhǔn)測(cè)試

特征

  • 提供有關(guān)速率和延遲的大量統(tǒng)計(jì)信息,包括延遲百分位數(shù)和直方圖;
  • 即使有數(shù)千個(gè)并發(fā)線程,開銷也很低。sysbench每秒能夠生成和跟蹤數(shù)億個(gè)事件。
  • 通過(guò)在用戶提供的Lua腳本中實(shí)現(xiàn)預(yù)定義的掛鉤,可以輕松創(chuàng)建新的基準(zhǔn)測(cè)試;
  • 可以也可以作為一個(gè)通用的Lua解釋,只需更換#!/usr/bin/lua#!/usr/bin/sysbench在你的腳本。

安裝

    安裝以Centos為例,其他版本或者mac請(qǐng)參考sysbench說(shuō)明

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)測(cè)是否安裝成功

[root@guanbin-k8s-master ~]# sysbench --version
sysbench 1.0.19  

測(cè)試

1. cpu測(cè)試

   cpu測(cè)試主要是進(jìn)行素?cái)?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í)行時(shí)間 大約為10秒(這個(gè)測(cè)試最好是兩臺(tái)機(jī)器進(jìn)行對(duì)比測(cè)試,才能發(fā)現(xiàn)那個(gè)機(jī)器有問(wèn)題)

2.對(duì)內(nèi)存(memory)進(jìn)行測(cè)試 

   測(cè)試是在內(nèi)存中傳輸 10G 的數(shù)據(jù)量,每個(gè) 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.對(duì)disk 的IO測(cè)試

新建一個(gè)臨時(shí)目錄,并確保磁盤剩余空間足夠(--file-total-size不要超過(guò)剩余容量)

測(cè)試場(chǎng)景:16個(gè)線程,創(chuàng)建128個(gè)文件,總共占用磁盤空間10GB,測(cè)試磁盤讀寫效率

運(yùn)行結(jié)束后要?jiǎng)h除臨時(shí)測(cè)試文件: 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.測(cè)試mysql性能

       測(cè)試時(shí)使用的腳本為lua腳本,可以使用sysbench自帶腳本,也可以自己開發(fā)。對(duì)于大多數(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ù)處理過(guò)程);

  • (1)盡量不要在MySQL服務(wù)器運(yùn)行的機(jī)器上進(jìn)行測(cè)試,一方面可能無(wú)法體現(xiàn)網(wǎng)絡(luò)(哪怕是局域網(wǎng))的影響,另一方面,sysbench的運(yùn)行(尤其是設(shè)置的并發(fā)數(shù)較高時(shí))會(huì)影響MySQL服務(wù)器的表現(xiàn)。
  • (2)可以逐步增加客戶端的并發(fā)連接數(shù)(--thread參數(shù)),觀察在連接數(shù)不同情況下,MySQL服務(wù)器的表現(xiàn);如分別設(shè)置為10,20,50,100等。
  • (3)一般執(zhí)行模式選擇complex即可,如果需要特別測(cè)試服務(wù)器只讀性能,或不使用事務(wù)時(shí)的性能,可以選擇simple模式或nontrx模式。
  • (4)如果連續(xù)進(jìn)行多次測(cè)試,注意確保之前測(cè)試的數(shù)據(jù)已經(jīng)被清理干凈。

下面是sysbench使用的一個(gè)例子:

 注意:先準(zhǔn)備數(shù)據(jù)庫(kù)

mysql> create database sbtest;

 其中,執(zhí)行模式為complex,使用了10個(gè)表,每個(gè)表有10萬(wàn)條數(shù)據(jù),客戶端的并發(fā)線程數(shù)為10,執(zhí)行時(shí)間為120秒,每10秒生成一次報(bào)告。

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請(qǐng)自行切換為自己真實(shí)的環(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

其中,對(duì)于我們比較重要的信息包括:

queries:查詢總數(shù)及qps

transactions:事務(wù)總數(shù)及tps

Latency-95th percentile:前95%的請(qǐng)求的最大響應(yīng)時(shí)間,本例中是344毫秒,這個(gè)延遲非常大,是因?yàn)槲矣玫腗ySQL服務(wù)器性能很差;在正式環(huán)境中這個(gè)數(shù)值是絕對(duì)不能接受的。

最后清理數(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ù)器性能測(cè)試?yán)髦畇ysbench的文章就介紹到這了,更多相關(guān)服務(wù)器性能測(cè)試sysbench內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論