Linux performance optimization (two)-sysbench stress test tool

1. Introduction to sysbench

1. Introduction to sysbench

sysBench is a modular, cross-platform, multi-threaded benchmark test tool, mainly used to evaluate and test the database load under various system parameters. sysbench provides the following tests:
(1) CPU performance
(2) Disk IO performance
(3) Scheduler performance
(4) Memory allocation and transmission speed 
(5) POSIX thread performance
(6) Database performance (OLTP benchmark test)      
sysbench supports MySQL, PostgreSQL, Oracle database.

2. sysbench installation

Build build dependency installation:

yum -y install make automake libtool pkgconfig libaio-devel
yum -y install mariadb-devel openssl-devel
yum -y install postgresql-devel

Source code download:
git clone https://github.com/akopytov/sysbench.git
Generate configuration tool:
autogen.sh
Configuration options:
--with-pgsql: support PostgreSQL
--with-oracle: support Oracle
--without-mysql: no MySQL support
configure [options]
compile:
make -j
install:
make install

3. sysbench command

sysbench [options]... [testname] [command]
testname is the type of test to be executed by sysbench. The options include fileio, cpu, memory, threads, mutex, and can be specified with the --test parameter.
Command is the command to be executed by sysbench, including prepare, run, and cleanup. Prepare prepares data for testing, run performs formal testing, and cleanup cleans up the database after the test is completed.
The general parameter options of
sysbench are as follows: --threads: the number of threads. If set to 2, sysbench will start two threads and perform prime number calculations respectively. The default value is 1.
--time: Run time, in seconds. If it is set to 5, sysbench will cycle prime number calculations within 5 seconds, and each round is an event, and the default value is 10.
--events: The maximum number of events. If set to 100, it means that after 100 events are completed, it will stop running even if there is time. The default value is 0, which means there is no limit to the number of events.
--forced-shutdown=STRING: Timeout forced interruption, the default is off. --thread-stack-size=SIZE: thread stack size, the default is 64K
--thread-init-timeout=N: thread initialization waiting time, the default is 30 seconds
--rate=N: average transaction rate, 0 means no limit, The default is 0.
--report-interval=N: The time interval for the test progress report output, 0 means off, and the default is 0.
--report-checkpoints=[LIST,...]: Dump complete statistics and reset all counters at a specified point in time. The parameter is a list of comma-separated values, indicating the elapsed time from the start of the test that must perform the report checkpoint (In seconds). By default, the report checkpoint is turned off [off].
--debug[=on|off]: Print debugging information, the default is off
--validate[=on|off]: Perform verification checks as much as possible, the default is off.
--help[=on|off]: print help information and exit, the default is off
--version[=on|off]: print version information and exit, the default is off
--config-file=FILENAME: command line option file
--luajit-cmd=STRING: execute LuaJIT control commands

Two, CPU performance benchmark test

1. Command options

sysbench --test=cpu help
--cpu-max-prime: The upper limit of the number of prime numbers generated. If set to 3, it means 2, 3, 5 (5 times to calculate 1-5), and the default value is 10000.

2. CPU performance test

sysbench cpu --cpu-max-prime=20000 --threads=8 --time=30 run
Linux performance optimization (two)-sysbench stress test tool
Prime numbers limit: 20000, the upper limit of prime numbers generated by each thread is 2000
events per second: 650.7, all threads complete 650.74 events per second
total time: 10.0017s, which takes 10 seconds
total number of events: 6510,10 In seconds, all threads completed a total of 6510 event
min: 3.03, the minimum time required to complete one event was 3.03 seconds
avg: 3.07, the average time required for all events was 3.07 milliseconds
max: 3.27, and the maximum time required to complete one event was 3.27 milliseconds
95th percentile: 3.13, 95% of the events are completed within 3.13 seconds and milliseconds.
sum: 19999.91, each thread takes 10 seconds, and the stacking time of 2 threads is 20 seconds
events (avg/stddev): 3255.0000/44.00 // average every Each thread completes 3255 events, the standard deviation is 44
execution time (avg/stddev): 10.0000/0.00 // Each thread takes an average of 10 seconds, and the standard deviation is 0

Three, memory load test

 1. Command options

sysbench  --test=memory help
--memory-block-size=SIZE: Test the size of the memory block, the default is 1K.
--memory-total-size=SIZE: The total size of data transmission, the default is 100G.
--memory-scope=STRING: The scope of memory access, including global and local scope, the default is global.
--memory-hugetlb=[on|off]: Whether to allocate memory from the HugeTLB pool, the default is off.
--memory-oper=STRING: the type of memory operation, including read, write, none, and the default is write
--memory-access-mode=STRING: memory access mode, including seq and rnd, the default is seq.

2. Memory load test

sysbench memory --threads=12 --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run
Start 12 threads, the memory block size is 8K, read and write sequentially
Linux performance optimization (two)-sysbench stress test tool
sysbench memory --threads=12 --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run
Linux performance optimization (two)-sysbench stress test tool

Fourth, disk IO performance benchmark test

1. Command options

 sysbench --test=fileio help
--file-num=N: The number of generated test files, the default is 128.
--file-block-size=N: The size of the file block used in the test. If you want the disk to be tested against the InnoDB storage engine, you can set it to 16384 (the size of the InnoDB storage engine page), and the default is 16384.
--file-total-size=SIZE: The total size of the created test file, the default is 2G.
--file-test-mode=STRING: file test mode, seqwr (sequential write), seqrewr (sequential read and write), seqrd (sequential read), rndrd (random read), rndwr (random write), rndrw (random read and write) ).
--file-io-mode=STRING: File operation mode, sync (synchronous), async (asynchronous), fastmmap (fast mmap), slowmmap (slow mmap), the default is sync.
--file-async-backlog=N: The number of asynchronous operations corresponding to each thread queue, the default is 128.
--file-extra-flags=STRING: options when opening files, and API-related parameters.
--file-fsync-freq=N: The frequency of executing the fsync function. fsync mainly synchronizes disk files. 0 means that the fsync function is not used, and the default value is 100.
--file-fsync-all=[on|off]: execute fsync every time a write operation is performed. The default is off.
--file-fsync-end=[on|off]: execute the fsync function at the end of the test, the default is on.
--file-fsync-mode=STRING: File synchronization function selection, and API-related parameters. Since multiple operating systems support different fdatasync, fdatasync is not recommended. The default is fsync.
--file-merged-requests=N: In most cases, the number of IO requests that may be merged, the default is 0.
--file-rw-ratio=N: The ratio of reading and writing during the test, the default is 1.5, that is, 3:2.

2. Data preparation

sysbench fileio --file-num=16 --file-total-size=2G prepare

3. Perform the test

sysbench fileio --file-total-size=2G --file-test-mode=rndrd --time=180 --threads=16 --file-num=16 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
Linux performance optimization (two)-sysbench stress test tool

4. Clean up data

sysbench fileio --file-num=16 --file-total-size=2G cleanup
Clean up test data

Five, multi-threaded scheduling benchmark test

1. Command options

sysbench  --test=mutex help 
--mutex-num=N: The total size of the array mutual exclusion, the default is 4096.
--mutex-locks=N: The number of mutex locks for each thread, the default is 50000.
--mutex-loops=N: The number of empty loops of the internal mutex, the default is 10000.

2. Multi-threaded scheduling test

sysbench mutex --threads=8 --mutex-num=2000 --mutex-locks=10000 --mutex-loops=5000 run
Linux performance optimization (two)-sysbench stress test tool

Six, POST multi-threaded benchmark test

 1. Command options

 sysbench  --test=threads help
--thread-yields=N: Specify the pressure of each request, the default is 1000
--thread-locks=N: Specify the number of locks for each thread, the default is 8

2. Multi-threaded test

sysbench threads --threads=8 --thread-yields=100 --thread-locks=2 run
Linux performance optimization (two)-sysbench stress test tool

Seven, OLTP benchmark test

1. Command options

sysbench --test=oltp help
--oltp-test-mode=STRING: Test mode, simple, complex, nontrx, sp, the default is complex.
--oltp-reconnect-mode=STRING: reconnection mode, session does not use reconnection, transaction reconnects after each transaction, query reconnects after each SQL statement is executed, random randomly selects reconnection for each transaction Mode, the default is session.
--oltp-sp-name=STRING: the name of the stored procedure, which is empty by default
--oltp-read-only=[on|off]: read-only mode. Update, delete, and insert statements cannot be executed, and the default is off
--oltp-skip-trx=[on|off]: omit the begin/commit statement, and the default is off.
--oltp-range-size=N: query range, the default is 100. --oltp-point-selects=N: number of point selects [10]
--oltp-simple-ranges=N number of simple ranges [1]
--oltp-sum-ranges=N number of sum ranges [1]
- -oltp-order-ranges=N number of ordered ranges [1]
--oltp-distinct-ranges=N number of distinct ranges [1]
--oltp-index-updates=N number of index update [1]
--oltp-non-index-updates=N number of non-index updates [1]
--oltp-nontrx-mode=STRING query type for non-transaction execution mode {select, update_key, update_nokey, insert, delete} [select]
--oltp-auto-inc=[on|off] Whether AUTO_INCREMENT is turned on. The default is on
--oltp-connect-delay=N How many microseconds to connect to the database. The default is 10000
--oltp-user-delay-min=N The minimum waiting time for each request. The unit is ms. The default is 0
--oltp-user-delay-max=N The maximum waiting time for each request. The unit is ms. The default is 0
--oltp-table-name=STRING the table name used in the test. The default is sbtest
--oltp-table-size=N the number of records in the test table. The default is 10000
--oltp-dist-type=STRING random number {uniform (uniform distribution), Gaussian (Gaussian distribution), special (spatial distribution)}. The default is special
--oltp-dist-iter=N The number of iterations of the generated number. The default is 12
--oltp-dist-pct=N The percentage of the value is regarded as'special' (for special distribution). The default is 1
--oltp-dist-res=N'special' percentage value. The default is 75

2. Lua script

/usr/share/sysbench/bulk_insert.lua
/usr/share/sysbench/oltp_common.lua
/usr/share/sysbench/oltp_delete.lua
/usr/share/sysbench/oltp_insert.lua
/usr/share/sysbench/oltp_point_select.lua
/usr/share/sysbench/oltp_read_only.lua
/usr/share/sysbench/oltp_read_write.lua
/usr/share/sysbench/oltp_update_index.lua
/usr/share/sysbench/oltp_update_non_index.lua
/usr/share/sysbench/oltp_write_only.lua
/usr/share/sysbench/select_random_points.lua
/usr/share/sysbench/select_random_ranges.lua

3. Prepare the data

sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host=192.168.10.10 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare
The execution mode is complex, 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.

4. Perform the test

sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host=192.168.10.10 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run >> /home/test/mysysbench.log

5. Clean up data

sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host=192.168.10.10 --mysql-port=3306 --mysql-user=root --mysql-password=123456 cleanup

Guess you like

Origin blog.51cto.com/9291927/2593580