mysql基准测试


摘要:使用sysbench对mysql做基准测试

安装sysbench

1、下载:https://codeload.github.com/akopytov/sysbench/zip/0.5
2、安装:

[root@mysql ~]# cd sysbench-0.5
[root@mysql sysbench-0.5]# ls
autogen.sh ChangeLog config configure.ac COPYING doc install-sh m4 Makefile.am missing mkinstalldirs README.md README-WIN.txt sysbench tests TODO
[root@mysql sysbench-0.5]# ./autogen.sh
遇到报错:libtoolize 1.4+ wasn't found, exiting
解决办法:[root@mysql sysbench-0.5]# yum install libtool -y
[root@mysql sysbench-0.5]# ./autogen.sh
./autogen.sh: running `aclocal -I m4'
./autogen.sh: running `libtoolize --copy --force'
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'.
libtoolize: copying file `config/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
./autogen.sh: running `autoheader'
./autogen.sh: running `automake -c --foreign --add-missing'
configure.ac:25: installing `config/compile'
configure.ac:11: installing `config/config.guess'
configure.ac:11: installing `config/config.sub'
configure.ac:16: installing `config/install-sh'
configure.ac:16: installing `config/missing'
sysbench/Makefile.am: installing `config/depcomp'
./autogen.sh: running `autoconf'
Libtoolized with: libtoolize (GNU libtool) 2.2.6b
Automade with: automake (GNU automake) 1.11.1
Configured with: autoconf (GNU Autoconf) 2.63
[root@mysql sysbench-0.5]#
[root@mysql sysbench-0.5]# ./configure --with-mysql-includes=/opt/mysql/include --with-mysql-libs=/opt/mysql/lib && make
[root@mysql sysbench-0.5]# make install
遇到报错:
[root@mysql sysbench-0.5]# sysbench --help
sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
临时解决(只适用当前会话):
[root@mysql sysbench-0.5]# export LD_LIBRARY_PATH=/opt/mysql/lib
永久解决:
[root@mysql ~]# ln -s /opt/mysql/lib/libmysqlclient.so.18 /usr/lib64
[root@mysql ~]# ldconfig
查看sysbench帮助:
[root@mysql sysbench-0.5]# sysbench --help
Missing required command argument.
Usage:
sysbench --test=<test-name> [options]... <command>
Commands: prepare run cleanup help version
General options:
--num-threads=N number of threads to use [1]
--max-requests=N limit for total number of requests [10000]
--max-time=N limit for total execution time in seconds [0]
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]
--thread-stack-size=SIZE size of stack per thread [64K]
--tx-rate=N target transaction rate (tps) [0]
--report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
--report-checkpoints=[LIST,...]dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
--test=STRING test to run
--debug=[on|off] print more debugging info [off]
--validate=[on|off] perform validation checks where possible [off]
--help=[on|off] print help and exit
--version=[on|off] print version and exit [off]
--rand-init=[on|off] initialize random number generator [off]
--rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
--rand-spec-iter=N number of iterations used for numbers generation [12]
--rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]
--rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]
--rand-seed=N seed for random number generator, ignored when 0 [0]
--rand-pareto-h=N parameter h for pareto distibution [0.2]
--config-file=FILENAME File containing command line options
Log options:
--verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
--percentile=N percentile rank of query response times to count [95]
General database options:
--db-driver=STRING specifies database driver to use ('help' to get list of available drivers)
--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
--db-debug=[on|off] print database-specific debug information [off]
Compiled-in database drivers:
mysql - MySQL driver
mysql options:
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=N MySQL server port [3306]
--mysql-socket=[LIST,...] MySQL socket
--mysql-user=STRING MySQL user [sbtest]
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
--mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]
--mysql-ssl=[on|off] use SSL connections, if available in the client library [off]
--mysql-compression=[on|off] use compression, if available in the client library [off]
--myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]
--mysql-debug=[on|off] dump all client library calls [off]
--mysql-ignore-errors=[LIST,...]list of errors to ignore, or "all" [1213,1020,1205]
--mysql-dry-run=[on|off] Dry run, pretent that all MySQL client API calls are successful without executing them [off]
Compiled-in tests:
fileio - File I/O test
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test
See 'sysbench --test=<name> help' for a list of options for each test.
可以看到帮助信息说明安装完毕!

准备工作

1、查看机器配置

查看CPU信息:
[root@mysql db]# grep "physical id" /proc/cpuinfo | sort -u | wc -l
1
[root@mysql db]# grep "core id" /proc/cpuinfo | sort -u | wc -l
2
[root@mysql db]# grep "processor" /proc/cpuinfo | sort -u | wc -l
4
该机器配置:CPU(单颗双核4线程),内存(16G),硬盘(HDD)

2、准备测试数据

[root@mysql db]# sysbench --test=/root/sysbench-0.5/sysbench/tests/db/select.lua --oltp-table-size=20000 --mysql-table-engine=innodb --mysql-user=root --mysql-pas
sword=test --mysql-port=3306 --mysql-host=192.168.1.3 --mysql-db=test --max-requests=0 --max-time=60 --oltp-tables-count=20 --report-interval=10 --num_threads
=4 prepare
sysbench 0.5: multi-threaded system evaluation benchmark
Creating table 'sbtest1'...
Inserting 20000 records into 'sbtest1'
Creating secondary indexes on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 20000 records into 'sbtest2'
Creating secondary indexes on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 20000 records into 'sbtest3'
Creating secondary indexes on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 20000 records into 'sbtest4'
Creating secondary indexes on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 20000 records into 'sbtest5'
Creating secondary indexes on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 20000 records into 'sbtest6'
Creating secondary indexes on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 20000 records into 'sbtest7'
Creating secondary indexes on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 20000 records into 'sbtest8'
Creating secondary indexes on 'sbtest8'...
Creating table 'sbtest9'...
Inserting 20000 records into 'sbtest9'
Creating secondary indexes on 'sbtest9'...
Creating table 'sbtest10'...
Inserting 20000 records into 'sbtest10'
Creating secondary indexes on 'sbtest10'...
Creating table 'sbtest11'...
Inserting 20000 records into 'sbtest11'
Creating secondary indexes on 'sbtest11'...
Creating table 'sbtest12'...
Inserting 20000 records into 'sbtest12'
Creating secondary indexes on 'sbtest12'...
Creating table 'sbtest13'...
Inserting 20000 records into 'sbtest13'
Creating secondary indexes on 'sbtest13'...
Creating table 'sbtest14'...
Inserting 20000 records into 'sbtest14'
Creating secondary indexes on 'sbtest14'...
Creating table 'sbtest15'...
Inserting 20000 records into 'sbtest15'
Creating secondary indexes on 'sbtest15'...
Creating table 'sbtest16'...
Inserting 20000 records into 'sbtest16'
Creating secondary indexes on 'sbtest16'...
Creating table 'sbtest17'...
Inserting 20000 records into 'sbtest17'
Creating secondary indexes on 'sbtest17'...
Creating table 'sbtest18'...
Inserting 20000 records into 'sbtest18'
Creating secondary indexes on 'sbtest18'...
Creating table 'sbtest19'...
Inserting 20000 records into 'sbtest19'
Creating secondary indexes on 'sbtest19'...
Creating table 'sbtest20'...
Inserting 20000 records into 'sbtest20'
Creating secondary indexes on 'sbtest20'...

测试QPS

测试脚本放在:/root/sysbench-0.5/sysbench/tests/db
测试QPS使用:select.lua

[root@mysql db]# sysbench --test=/root/sysbench-0.5/sysbench/tests/db/select.lua --oltp-table-size=20000 --mysql-table-engine=innodb --mysql-user=root --mysql-pas
sword=test --mysql-port=3306 --mysql-host=192.168.1.3 --mysql-db=test --max-requests=0 --max-time=60 --oltp-tables-count=20 --report-interval=10 --num_threads
=10 run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 10
Report intermediate results every 10 second(s)
Random number generator seed is 0 and will be ignored
Initializing worker threads...
Threads started!
[ 10s] threads: 10, tps: 0.00, reads: 48798.78, writes: 0.00, response time: 0.27ms (95%), errors: 0.00, reconnects: 0.00
[ 20s] threads: 10, tps: 0.00, reads: 49039.11, writes: 0.00, response time: 0.27ms (95%), errors: 0.00, reconnects: 0.00
[ 30s] threads: 10, tps: 0.00, reads: 48814.40, writes: 0.00, response time: 0.27ms (95%), errors: 0.00, reconnects: 0.00
[ 40s] threads: 10, tps: 0.00, reads: 48619.99, writes: 0.00, response time: 0.27ms (95%), errors: 0.00, reconnects: 0.00
[ 50s] threads: 10, tps: 0.00, reads: 49057.90, writes: 0.00, response time: 0.27ms (95%), errors: 0.00, reconnects: 0.00
OLTP test statistics:
queries performed:
read: 2932213
write: 0
other: 0
total: 2932213
transactions: 0 (0.00 per sec.)
read/write requests: 2932213 (48870.07 per sec.) #QPS
other operations: 0 (0.00 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0002s
total number of events: 2932213
total time taken by event execution: 597.0825s
response time:
min: 0.05ms
avg: 0.20ms
max: 159.91ms
approx. 95 percentile: 0.27ms
Threads fairness:
events (avg/stddev): 293221.3000/4766.23
execution time (avg/stddev): 59.7083/0.01

查看OS资源:
图1
可以看到当QPS达到5W时,CPU已耗光,load也已达到极限。

测试混合读写

使用oltp.lua

[root@mysql db]# sysbench --test=/root/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=20000 --mysql-table-engine=innodb --mysql-user=root --mysql-passw
ord=test --mysql-port=3306 --mysql-host=192.168.1.3 --mysql-db=test --max-requests=0 --max-time=60 --oltp-tables-count=20 --report-interval=10 --num_threads=1
0 run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 10
Report intermediate results every 10 second(s)
Random number generator seed is 0 and will be ignored
Initializing worker threads...
Threads started!
[ 10s] threads: 10, tps: 785.09, reads: 11005.28, writes: 3144.37, response time: 52.92ms (95%), errors: 0.00, reconnects: 0.00
[ 20s] threads: 10, tps: 758.80, reads: 10619.20, writes: 3032.10, response time: 57.15ms (95%), errors: 0.00, reconnects: 0.00
[ 30s] threads: 10, tps: 648.80, reads: 9085.42, writes: 2595.21, response time: 63.73ms (95%), errors: 0.00, reconnects: 0.00
[ 40s] threads: 10, tps: 600.10, reads: 8401.50, writes: 2400.50, response time: 72.53ms (95%), errors: 0.00, reconnects: 0.00
[ 50s] threads: 10, tps: 508.10, reads: 7113.60, writes: 2032.20, response time: 79.97ms (95%), errors: 0.00, reconnects: 0.00
[ 60s] threads: 10, tps: 694.40, reads: 9720.67, writes: 2778.09, response time: 60.92ms (95%), errors: 0.00, reconnects: 0.00
OLTP test statistics:
queries performed:
read: 559482
write: 159852
other: 79926
total: 799260
transactions: 39963 (665.74 per sec.) #TPS(每秒事务数)
read/write requests: 719334 (11983.35 per sec.) #读写总数(每秒读写次数)
other operations: 79926 (1331.48 per sec.) #其他操作总数(每秒其他操作次数)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0278s
total number of events: 39963
total time taken by event execution: 600.1355s
response time:
min: 1.84ms
avg: 15.02ms
max: 355.07ms
approx. 95 percentile: 63.13ms
Threads fairness:
events (avg/stddev): 3996.3000/34.31
execution time (avg/stddev): 60.0136/0.01

查看OS资源:
图2
可以看到TPS达到:665.74,QPS达到:11983.35,CPU已耗光,load也已达到极限。

内存测试

[root@mysql db]# sysbench --test=memory --num-threads=4 --memory-block-size=16384 --memory-total-size=16G run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 4
Random number generator seed is 0 and will be ignored
Initializing worker threads...
Threads started!
Operations performed: 1048576 (1277174.93 ops/sec)
16384.00 MB transferred (19955.86 MB/sec)
General statistics:
total time: 0.8210s
total number of events: 1048576
total time taken by event execution: 2.9372s
response time:
min: 0.00ms
avg: 0.00ms
max: 0.28ms
approx. 95 percentile: 0.00ms
Threads fairness:
events (avg/stddev): 262144.0000/609.13
execution time (avg/stddev): 0.7343/0.00

CPU测试

[root@mysql db]# sysbench --test=cpu --cpu-max-prime=2000 run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored
Prime numbers limit: 2000
Initializing worker threads...
Threads started!
General statistics:
total time: 1.0350s
total number of events: 10000
total time taken by event execution: 1.0334s
response time:
min: 0.10ms
avg: 0.10ms
max: 0.50ms
approx. 95 percentile: 0.10ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 1.0334/0.00

还可以进行文件IO性能测试、线程测试、互斥锁(Mutex)测试。
通过sysbench来压测单机的极限值,然后根据业务需求来做容量预估!

文章目录
  1. 1. 安装sysbench
  2. 2. 准备工作
  3. 3. 测试QPS
  4. 4. 测试混合读写
  5. 5. 内存测试
  6. 6. CPU测试
|