Preface
sysbench is an open source, modular, cross-platform multi-threaded performance testing tool that can be used to perform performance testing of CPU, memory, disk I/O, threads, and databases. sysbench is a scriptable multithreaded benchmarking tool based on LuaJIT.
sysbench comes with the following bundle of benchmarks:
-
oltp_*.lua
: A collection of OLTP-like database benchmarks -
fileio
: File system-level benchmark -
cpu
: Simple CPU benchmarking -
memory
: Memory access benchmark -
threads
: Thread-based scheduler benchmark -
mutex
POSIX Mutex Benchmark Test
feature
- Provides extensive statistics about rates and delays, including delay percentiles and histograms;
- Even with thousands of concurrent threads, the overhead is low. sysbench is able to generate and track hundreds of millions of events per second.
- New benchmarks can be easily created by implementing predefined hooks in user-provided Lua scripts;
- It can or can be used as a general Lua explanation, just replace it
#!/usr/bin/lua
use#!/usr/bin/sysbench
In your script.
Install
Installation takes Centos as an example. Please refer to other versions or macsysbenchillustrate
1. Download and transfer
wget /akopytov/sysbench/archive/1. -O "sysbench-1." unzip sysbench-1. cd sysbench-1.0 //Installation dependenciesyum install -y automake libtool
2. Compile and install
./ ./configure export LD_LIBRARY_PATH=/usr/include/mysql make make install
3. Monitor whether the installation is successful
[root@guanbin-k8s-master ~]# sysbench --version sysbench 1.0.19
test
1. cpu test
The CPU test mainly performs the addition of prime numbers. In our example, the maximum number of prime generators is specified as 20,000.
[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
Execution time is about 10 seconds (it is best for two machines to compare and test to find that there is a problem with that machine)
2. Test memory
The test is to transfer 10G of data in memory, with each block size of 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 is 1.8045s
3. IO test of disk
Create a new temporary directory and make sure that the remaining space of the disk is sufficient (--file-total-size should not exceed the remaining capacity)
Test scenario: 16 threads, 128 files are created, and a total of 10GB of disk space is occupied, testing disk read and write efficiency
After the run is completed, you need to delete the temporary test file: 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
Throughput: Read2.46MiB/s, write 1.64MiB/s; 95% delay 142.39ms
4. Test mysql performance
The script used during testing is a lua script. You can use the scripts that come with sysbench or you can develop them yourself. For most applications, using the scripts that come with sysbench is enough. In different versions of sysbench, the location of the lua script may be different. You can search by yourself using the find command under the sysbench path.
.: Most data services are of oltp type. If you don’t understand what oltp is, then there is a high probability that your data services are of oltp type. MySQL OLTP (On-Line Transaction Processing Online Transaction Processing);
- (1) Try not to test on the machine running on the MySQL server. On the one hand, it may not reflect the impact of the network (even a LAN). On the other hand, the operation of sysbench (especially when the number of concurrencies is set high) will affect the performance of the MySQL server.
- (2) You can gradually increase the number of concurrent connections (--thread parameter) of the client and observe the performance of the MySQL server under different connections; for example, set to 10, 20, 50, 100, etc.
- (3) Select complex in general. If you need to specially test the read-only performance of the server, or the performance when not using transactions, you can choose simple mode or nontrx mode.
- (4) If you conduct multiple tests in succession, be careful to ensure that the data tested has been cleaned up.
Here is an example of sysbench use:
Note: Prepare the database first
mysql> create database sbtest;
Among them, the execution mode is complex, and 10 tables are used, each table has 100,000 pieces of data, the number of concurrent threads on the client is 10, the execution time is 120 seconds, and a report is generated every 10 seconds.
sysbench ./tests/include/oltp_legacy/ --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
Please switch to your real environment data by yourself.
View execution results
sysbench ./tests/include/oltp_legacy/ --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
Among them, the more important information for us include:
queries: total number of queries and qps
transactions: total number of transactions and tps
Latency-95th percentile: The maximum response time for the first 95% of the requests, in this case it is 344 milliseconds, which is very large because the MySQL server I use is very poor in performance; this value is absolutely unacceptable in a formal environment.
Finally clean up the data:
sysbench ./tests/include/oltp_legacy/ --mysql-host={yourhostip} --mysql-port=3306 --mysql-user={username} --mysql-password={password} --oltp-tables-count=10 cleanup
Cleaned log output
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'...
This is the end of this article about sysbench, a powerful server performance testing tool. For more related sysbench content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!