本文主要介绍了如何使用Sysbench进行CPU、 内存、 IO 、线程、 mutex压力测试。
CPU测试
sysbench cpu help
1 sysbench cpu help 2 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 3 4 cpu options: 5 --cpu-max-prime=N upper limit for primes generator [10000] 最大质数发生器数量。默认是10000
测试结果
1 ➜ ~ sysbench cpu --cpu-max-prime=2000 run 2 3 4 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 5 6 Running the test with following options: 7 Number of threads: 1 8 Initializing random number generator from current time 9 10 11 Prime numbers limit: 2000 12 13 Initializing worker threads... 14 15 Threads started! 16 17 18 General statistics: 19 total time: 10.0001s 20 total number of events: 73827 21 22 Latency (ms): 23 min: 0.12 24 avg: 0.13 25 max: 5.69 26 95th percentile: 0.19 27 sum: 9961.81 28 29 Threads fairness: 30 events (avg/stddev): 73827.0000/0.00 31 execution time (avg/stddev): 9.9618/0.00
内存测试
1 sysbench memory help 2 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 3 4 memory options: 5 --memory-block-size=SIZE size of memory block for test [1K] 测试时内存块大小。默认是1K 6 --memory-total-size=SIZE total size of data to transfer [100G] 传输数据的总大小。默认是100G 7 --memory-scope=STRING memory access scope {global,local} [global] 内存访问范围{global,local}。默认是global 8 --memory-oper=STRING type of memory operations {read, write, none} [write] 内存操作类型。{read, write, none} 默认是write 9 --memory-access-mode=STRING memory access mode {seq,rnd} [seq] 存储器存取方式{seq,rnd} 默认是seq
测试结果
1 sysbench memory --memory-block-size=8k --memory-total-size=1G run 2 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 3 4 Running the test with following options: 5 Number of threads: 1 6 Initializing random number generator from current time 7 8 9 Running memory speed test with the following options: 10 block size: 8KiB 11 total size: 1024MiB 12 operation: write 13 scope: global 14 15 Initializing worker threads... 16 17 Threads started! 18 19 Total operations: 131072 (940750.90 per second) 20 21 1024.00 MiB transferred (7349.62 MiB/sec) 22 23 24 General statistics: 25 total time: 0.1369s 26 total number of events: 131072 27 28 Latency (ms): 29 min: 0.00 30 avg: 0.00 31 max: 1.18 32 95th percentile: 0.00 33 sum: 100.88 34 35 Threads fairness: 36 events (avg/stddev): 131072.0000/0.00 37 execution time (avg/stddev): 0.1009/0.00
I/O测试
1 sysbench fileio help 2 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 3 4 fileio options: 5 --file-num=N number of files to create [128] 创建测试文件的数量。默认是128 6 --file-block-size=N block size to use in all IO operations [16384] 测试时文件块的大小。默认是16384(16K) 7 --file-total-size=SIZE total size of files to create [2G] 测试文件的总大小。默认是2G 8 --file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw} 文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)} 9 --file-io-mode=STRING file operations mode {sync,async,mmap} [sync] 文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync 10 --file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} [] 使用额外的标志来打开文件{sync,dsync,direct} 。默认为空 11 --file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100] 执行fsync()的频率。(0 – 不使用fsync())。默认是100 12 --file-fsync-all[=on|off] do fsync() after each write operation [off] 每执行完一次写操作就执行一次fsync。默认是off 13 --file-fsync-end[=on|off] do fsync() at the end of test [on] 在测试结束时才执行fsync。默认是on 14 --file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]使用哪种方法进行同步{fsync, fdatasync}。默认是fsync 15 --file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]如果可以,合并最多的IO请求数(0 – 表示不合并)。默认是0 16 --file-rw-ratio=N reads/writes ratio for combined test [1.5] 测试时的读写比例。默认是1.5
1,prepare阶段,生成需要的测试文件,完成后会在当前目录下生成很多小文件。
1 sysbench fileio --threads=16 --file-total-size=2G --file-test-mode=rndrw prepare
2,run阶段
1 sysbench fileio --threads=20 --file-total-size=2G --file-test-mode=rndrw run
3,清理测试时生成的文件
1 sysbench fileio --threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup
执行过程如下:
1 sysbench fileio --threads=16 --file-total-size=2G --file-test-mode=rndrw prepare 2 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 3 4 128 files, 16384Kb each, 2048Mb total 5 Creating files for the test... 6 Extra file open flags: 0 7 Creating file test_file.0 8 Creating file test_file.1 9 Creating file test_file.2 10 Creating file test_file.3 11 Creating file test_file.4 12 Creating file test_file.5 13 Creating file test_file.6 14 Creating file test_file.7 15 Creating file test_file.8 16 Creating file test_file.9 17 Creating file test_file.10 18 Creating file test_file.11 19 Creating file test_file.12 20 Creating file test_file.13 21 Creating file test_file.14 22 Creating file test_file.15 23 Creating file test_file.16 24 Creating file test_file.17 25 Creating file test_file.18 26 Creating file test_file.19 27 Creating file test_file.20 28 Creating file test_file.21 29 Creating file test_file.22 30 Creating file test_file.23 31 Creating file test_file.24 32 Creating file test_file.25 33 Creating file test_file.26 34 Creating file test_file.27 35 Creating file test_file.28 36 Creating file test_file.29 37 Creating file test_file.30 38 Creating file test_file.31 39 Creating file test_file.32 40 Creating file test_file.33 41 Creating file test_file.34 42 Creating file test_file.35 43 Creating file test_file.36 44 Creating file test_file.37 45 Creating file test_file.38 46 Creating file test_file.39 47 Creating file test_file.40 48 Creating file test_file.41 49 Creating file test_file.42 50 Creating file test_file.43 51 Creating file test_file.44 52 Creating file test_file.45 53 Creating file test_file.46 54 Creating file test_file.47 55 Creating file test_file.48 56 Creating file test_file.49 57 Creating file test_file.50 58 Creating file test_file.51 59 Creating file test_file.52 60 Creating file test_file.53 61 Creating file test_file.54 62 Creating file test_file.55 63 Creating file test_file.56 64 Creating file test_file.57 65 Creating file test_file.58 66 Creating file test_file.59 67 Creating file test_file.60 68 Creating file test_file.61 69 Creating file test_file.62 70 Creating file test_file.63 71 Creating file test_file.64 72 Creating file test_file.65 73 Creating file test_file.66 74 Creating file test_file.67 75 Creating file test_file.68 76 Creating file test_file.69 77 Creating file test_file.70 78 Creating file test_file.71 79 Creating file test_file.72 80 Creating file test_file.73 81 Creating file test_file.74 82 Creating file test_file.75 83 Creating file test_file.76 84 Creating file test_file.77 85 Creating file test_file.78 86 Creating file test_file.79 87 Creating file test_file.80 88 Creating file test_file.81 89 Creating file test_file.82 90 Creating file test_file.83 91 Creating file test_file.84 92 Creating file test_file.85 93 Creating file test_file.86 94 Creating file test_file.87 95 Creating file test_file.88 96 Creating file test_file.89 97 Creating file test_file.90 98 Creating file test_file.91 99 Creating file test_file.92 100 Creating file test_file.93 101 Creating file test_file.94 102 Creating file test_file.95 103 Creating file test_file.96 104 Creating file test_file.97 105 Creating file test_file.98 106 Creating file test_file.99 107 Creating file test_file.100 108 Creating file test_file.101 109 Creating file test_file.102 110 Creating file test_file.103 111 Creating file test_file.104 112 Creating file test_file.105 113 Creating file test_file.106 114 Creating file test_file.107 115 Creating file test_file.108 116 Creating file test_file.109 117 Creating file test_file.110 118 Creating file test_file.111 119 Creating file test_file.112 120 Creating file test_file.113 121 Creating file test_file.114 122 Creating file test_file.115 123 Creating file test_file.116 124 Creating file test_file.117 125 Creating file test_file.118 126 Creating file test_file.119 127 Creating file test_file.120 128 Creating file test_file.121 129 Creating file test_file.122 130 Creating file test_file.123 131 Creating file test_file.124 132 Creating file test_file.125 133 Creating file test_file.126 134 Creating file test_file.127 135 2147483648 bytes written in 2.48 seconds (826.62 MiB/sec). 136 ➜ ~ 137 ➜ ~ 138 ➜ ~ sysbench fileio --threads=20 --file-total-size=2G --file-test-mode=rndrw run 139 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 140 141 Running the test with following options: 142 Number of threads: 20 143 Initializing random number generator from current time 144 145 146 Extra file open flags: 0 147 128 files, 16MiB each 148 2GiB total file size 149 Block size 16KiB 150 Number of IO requests: 0 151 Read/Write ratio for combined random IO test: 1.50 152 Periodic FSYNC enabled, calling fsync() each 100 requests. 153 Calling fsync() at the end of test, Enabled. 154 Using synchronous I/O mode 155 Doing random r/w test 156 Initializing worker threads... 157 158 Threads started! 159 160 161 File operations: 162 reads/s: 15512.76 163 writes/s: 10341.51 164 fsyncs/s: 33093.17 165 166 Throughput: 167 read, MiB/s: 242.39 168 written, MiB/s: 161.59 169 170 General statistics: 171 total time: 10.0005s 172 total number of events: 589605 173 174 Latency (ms): 175 min: 0.00 176 avg: 0.22 177 max: 6.39 178 95th percentile: 0.50 179 sum: 130617.03 180 181 Threads fairness: 182 events (avg/stddev): 29480.2500/81.36 183 execution time (avg/stddev): 6.5309/0.01 184 185 ➜ ~ sysbench fileio --threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup 186 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 187 188 Removing test files...
线程测试
1 sysbench threads help 2 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 3 4 threads options: 5 --thread-yields=N number of yields to do per request [1000] 每个请求产生多少个线程。默认是1000 6 --thread-locks=N number of locks per thread [8] 每个线程的锁的数量。默认是8
1 sysbench threads --num-threads=500 --thread-yields=100 --thread-locks=4 run 2 WARNING: --num-threads is deprecated, use --threads instead 3 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 4 5 Running the test with following options: 6 Number of threads: 500 7 Initializing random number generator from current time 8 9 10 Initializing worker threads... 11 12 Threads started! 13 14 15 General statistics: 16 total time: 10.0902s 17 total number of events: 25095 18 19 Latency (ms): 20 min: 78.56 21 avg: 200.33 22 max: 258.32 23 95th percentile: 235.74 24 sum: 5027387.63 25 26 Threads fairness: 27 events (avg/stddev): 50.1900/0.40 28 execution time (avg/stddev): 10.0548/0.02
mutex测试
1 sysbench mutex help 2 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 3 4 mutex options: 5 --mutex-num=N total size of mutex array [4096] 数组互斥的总大小。默认是4096 6 --mutex-locks=N number of mutex locks to do per thread [50000] 每个线程互斥锁的数量。默认是50000 7 --mutex-loops=N number of empty loops to do outside mutex lock [10000] 内部互斥锁的空循环数量。默认是10000
执行过程
1 sysbench mutex --num-threads=100 --mutex-num=1000 --mutex-locks=100000 --mutex-loops=10000 run 2 3 4 WARNING: --num-threads is deprecated, use --threads instead 5 sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2) 6 7 Running the test with following options: 8 Number of threads: 100 9 Initializing random number generator from current time 10 11 12 Initializing worker threads... 13 14 Threads started! 15 16 17 General statistics: 18 total time: 17.9762s 19 total number of events: 100 20 21 Latency (ms): 22 min: 15479.16 23 avg: 17200.68 24 max: 17910.48 25 95th percentile: 17752.80 26 sum: 1720067.67 27 28 Threads fairness: 29 events (avg/stddev): 1.0000/0.00 30 execution time (avg/stddev): 17.2007/0.59
参考博客:http://wangshengzhuang.com/2017/05/22/%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9B%B8%E5%85%B3/MySQL/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/Sysbench%E8%BF%9B%E8%A1%8CCPU%20%E5%86%85%E5%AD%98%20IO%20%E7%BA%BF%E7%A8%8B%20mutex%E6%B5%8B%E8%AF%95%E4%BE%8B%E5%AD%90/