歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> sysbench使用總結

sysbench使用總結

日期:2017/2/27 15:58:16   编辑:Linux教程
sysbench 是一款多線程系統壓測工具。可以根據影響數據庫服務器性能的各種因素來評估系統的性能。可以用來測試文件I/O,操作系統調度器,內存分配和傳輸速度,POSIX 線程,以及數據庫服務器等。sysbench 支持 Lua 腳本語言以實現更加靈活的設置。屬於全能型的測試工具。

以下內容參考自《高性能 MySQL 》的第二章。

1. CPU 基准測試
測試內容:測試計算素數知道某個最大值所需的時間。
[root@Betty ~]# cat /proc/cpuinfo 
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      :         Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 1600.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6585.40
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      :         Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 1600.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 2
apicid          : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6585.00
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      :         Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 1600.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6584.95
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      :         Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 1600.000
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 2
apicid          : 3
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc nonstop_tsc arat pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6585.00
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]
執行結果:
[root@Betty ~]# sysbench --test=cpu --cpu-max-prime=20000 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1

Doing CPU performance benchmark

Threads started!
Done.

Maximum prime number checked in CPU test: 20000


Test execution summary:
    total time:                          25.6727s
    total number of events:              10000
    total time taken by event execution: 25.6696
    per-request statistics:
         min:                                  2.56ms
         avg:                                  2.57ms
         max:                                  5.36ms
         approx.  95 percentile:               2.57ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   25.6696/0.00
2. 文件 I/O 基准測試
用於測試系統在不同 I/O 負載下的性能。
a. 准備階段
生成測試用的數據文件,要求生成的數據文件至少要比內存大,否則數據由於被操作系統緩存而無法體現 I/O 密集型工作負載。
[root@Betty ~]# sysbench --test=fileio --file-total-size=10G prepare  
sysbench 0.4.12:  multi-threaded system evaluation benchmark

128 files, 81920Kb each, 10240Mb total
Creating files for the test...
查看生成的文件,共 128 個文件塊(80M * 128):
[root@Betty ~]# ll
total 10498016
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.0
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.1
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.10
-rw------- 1 root root 83886080 Aug 14 10:55 test_file.100
...
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.109
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.11
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.110
...
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.119
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.12
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.120
...
-rw------- 1 root root 83886080 Aug 14 10:56 test_file.127
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.13
...
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.19
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.2
-rw------- 1 root root 83886080 Aug 14 10:53 test_file.20
...
-rw------- 1 root root 83886080 Aug 14 10:55 test_file.98
-rw------- 1 root root 83886080 Aug 14 10:55 test_file.99
b. 運行階段
讀取前一步生成的數據文件進行測試。
[root@Betty ~]# sysbench --test=fileio --file-total-size=10G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1
Initializing random number generator from timer.


Extra file open flags: 0
128 files, 80Mb each
10Gb total file size
Block size 16Kb
Number of random requests for random IO: 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
Threads started!
Time limit exceeded, exiting...
Done.

Operations performed:  25981 Read, 17320 Write, 55424 Other = 98725 Total
Read 405.95Mb  Written 270.62Mb  Total transferred 676.58Mb  (2.255Mb/sec)
  144.32 Requests/sec executed

Test execution summary:
    total time:                          300.0315s
    total number of events:              43301
    total time taken by event execution: 176.0072
    per-request statistics:
         min:                                  0.01ms
         avg:                                  4.06ms
         max:                                 76.53ms
         approx.  95 percentile:              13.04ms

Threads fairness:
    events (avg/stddev):           43301.0000/0.00
    execution time (avg/stddev):   176.0072/0.00
c. 清除階段
刪除第一步生成的測試文件。
[root@Betty ~]# sysbench --test=fileio --file-total-size=10G cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Removing test files...
3. OLTP 基准測試
測試內容:模擬事務處理系統的工作負載。使用一張超過百萬行記錄的表。
a. 生成表
[root@Betty ~]# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --db-driver=mysql --mysql-socket=/tmp/mysql.sock --mysql-user=root prepare
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...
查看 MySQL 數據庫內容:
mysql> show tables;      
+----------------+
| Tables_in_test |
+----------------+
| sbtest         | 
+----------------+
1 row in set (0.00 sec)

mysql> 
mysql> 
mysql> select count(*) from sbtest;
+----------+
| count(*) |
+----------+
|  1000000 | 
+----------+
1 row in set (0.19 sec)
b. 運行測試
8 線程並發、只讀模式、測試時長為 60s 。
[root@Betty ~]# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 --db-driver=mysql --mysql-socket=/tmp/mysql.sock run  
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 8

Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.

OLTP test statistics:
    queries performed:
        read:                            1442434
        write:                           0
        other:                           206062
        total:                           1648496
    transactions:                        103031 (1717.12 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 1442434 (24039.63 per sec.)
    other operations:                    206062 (3434.23 per sec.)

Test execution summary:
    total time:                          60.0023s
    total number of events:              103031
    total time taken by event execution: 479.5035
    per-request statistics:
         min:                                  1.49ms
         avg:                                  4.65ms
         max:                               3493.99ms
         approx.  95 percentile:               2.41ms

Threads fairness:
    events (avg/stddev):           12878.8750/1194.34
    execution time (avg/stddev):   59.9379/0.01
測試結果信息中包括:
  • 總的事務數/每秒事務數
  • 時間統計信息(最小、平均、最大響應時間、95% 百分比響應時間)
  • 線程公平性統計信息,用於表示模擬負載的公平性
c. 刪除表
[root@Betty ~]# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --db-driver=mysql --mysql-socket=/tmp/mysql.sock cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Dropping table 'sbtest'...
Done.
Copyright © Linux教程網 All Rights Reserved