0
点赞
收藏
分享

微信扫一扫

sysbench压测mysql

文档说明

本编文章的目的,一方面是为了学习sysbenc测试工具的使用。另外一方面是为了了解mysql数据库的性能情况,主要想要了解TPS(每秒事务数)和QPS(每秒读写数)。

步骤

创建数据库

命令如下:

mysql -p
show databases;
create database test;

制造测试表

命令如下:

cd /opt/soft/sysbench-0.4.8/sysbench
./sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=test --oltp-table-size=100000 --db-driver=mysql --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=XXXXX prepare

参数说明:
--test :测试类型,设置为oltp,表示进行oltp模式测试
--mysql-table-engine :表示存储引擎类型,这里选择innodb
--mysql-db :指定数据库
--oltp-table-size :指定产生的测试表的行数
--db-driver :表示数据库的驱动类型,我们使用的是 MySQL 所以填mysql ,如果使用 Oracle 则填写相应的oracle
--mysql-socket :如果在本机测试,可以使用 -–mysql-socket 指定 socket文件来连接。
--mysql-user :用户名
--mysql-host :MySQL服务器主机名,默认localhost;如果在本机上使用localhost报错,提示无法连接MySQL服务器,改成本机的IP地址应该就可以了
--mysql-password :密码
prepare :准备数据,表示按照命令设置去构建出我们的测试表及测试数据

 

验证是否产生了测试数据

mysql -p
use test;
desc sbtest;
select count(*) from sbtest;

 

进行性能测试

命令如下:

cd /opt/soft/sysbench-0.4.8/sysbench
./sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=test --oltp-table-size=100000 --db-driver=mysql --num-threads=16 --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=XXXXX run

参数说明:
--test :测试类型,设置为oltp,表示进行oltp模式测试
--mysql-table-engine :表示存储引擎类型,这里选择innodb
--mysql-db :指定数据库
--oltp-table-size :指定产生的测试表的行数
--db-driver :表示数据库的驱动类型,我们使用的是 MySQL 所以填mysql ,如果使用 Oracle 则填写相应的oracle
--mysql-socket :如果在本机测试,可以使用 -–mysql-socket 指定 socket文件来连接。
--mysql-user :用户名
--mysql-host :MySQL服务器主机名,默认localhost;如果在本机上使用localhost报错,提示无法连接MySQL服务器,改成本机的IP地址应该就可以了
--mysql-password :密码
--num-threads :表示发起 多少个并发连接
run :运行测试

测试记录

 

[root@centos65 sysbench]# pwd
/opt/soft/sysbench-0.4.8/sysbench
[root@centos65 sysbench]# ll
total 616
-rw-r--r--. 1 50475 users  11527 Mar 10  2006 db_driver.c
-rw-r--r--. 1 50475 users   8009 Jan 31  2006 db_driver.h
-rw-r--r--. 1 root  root   36688 Apr 19 17:34 db_driver.o
drwxr-xr-x. 5 50475 users   4096 Apr 19 17:33 drivers
-rw-r--r--. 1 root  root   20285 Apr 19 17:33 Makefile
-rw-r--r--. 1 50475 users   1556 Jan 31  2006 Makefile.am
-rw-r--r--. 1 50475 users  21278 Oct 11  2006 Makefile.in
-rw-r--r--. 1 50475 users   3321 Jan 31  2006 sb_list.h
-rw-r--r--. 1 50475 users  18404 Apr  3  2006 sb_logger.c
-rw-r--r--. 1 50475 users   3890 Jan 31  2006 sb_logger.h
-rw-r--r--. 1 root  root   44904 Apr 19 17:34 sb_logger.o
-rw-r--r--. 1 50475 users  11911 Mar  2  2006 sb_options.c
-rw-r--r--. 1 50475 users   2770 Feb 27  2006 sb_options.h
-rw-r--r--. 1 root  root   33896 Apr 19 17:34 sb_options.o
-rw-r--r--. 1 50475 users   3925 Jan 31  2006 sb_timer.c
-rw-r--r--. 1 50475 users   2819 Mar 10  2006 sb_timer.h
-rw-r--r--. 1 root  root   11488 Apr 19 17:34 sb_timer.o
-rwxr-xr-x. 1 root  root  297660 Apr 19 17:34 sysbench
-rw-r--r--. 1 50475 users  14765 Jan 31  2006 sysbench.c
-rw-r--r--. 1 50475 users   5605 May  5  2006 sysbench.h
-rw-r--r--. 1 root  root   41864 Apr 19 17:34 sysbench.o
drwxr-xr-x. 8 50475 users   4096 Apr 19 17:33 tests

[root@centos65 sysbench]# ./sysbench --help
Usage:
  sysbench [general-options]... --test=<test-name> [test-options]... commandGeneral 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]
  --thread-stack-size=SIZE   size of stack per thread [32K]
  --init-rng=[on|off]        initialize random number generator [off]
  --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 exitCompiled-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
  oltp - OLTP testCommands: prepare run cleanup help
See 'sysbench --test=<name> help' for a list of options for each test.

[root@centos65 sysbench]# ./sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=test --oltp-table-size=100000 --db-driver=mysql --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=oracle prepare
sysbench v0.4.8:  multi-threaded system evaluation benchmarkCreating table 'sbtest'...
Creating 100000 records in table 'sbtest'...

[root@centos65 sysbench]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.20 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@db 17:56:  [(none)]> use test;
Database changed
root@db 17:56:  [test]> 
root@db 17:56:  [test]> desc sbtest;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| k     | int(10) unsigned | NO   | MUL | 0       |                |
| c     | char(120)        | NO   |     |         |                |
| pad   | char(60)         | NO   |     |         |                |
+-------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)root@db 17:57:  [test]> select count(*) from sbtest;
+----------+
| count(*) |
+----------+
|   100000 |
+----------+
1 row in set (0.03 sec)

[root@centos65 sysbench]# ./sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=test --oltp-table-size=100000 --db-driver=mysql --num-threads=16--mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=oracle run

sysbench v0.4.8:  multi-threaded system evaluation benchmarkWARNING: Preparing of "BEGIN" is unsupported, using emulation
(last message repeated 15 times)
Running the test with following options:
Number of threads: 16Doing OLTP test.
Running mixed OLTP 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
Maximum number of requests for OLTP test is limited to 10000
Threads started!
Done.

OLTP test statistics:
    queries performed:
        read:                            140294
        write:                           50046
        other:                           20021
        total:                           210361
    transactions:                        10000  (629.01 per sec.)
    deadlocks:                           21     (1.32 per sec.)
    read/write requests:                 190340 (11972.48 per sec.)
    other operations:                    20021  (1259.33 per sec.)Test execution summary:
    total time:                          15.8981s
    total number of events:              10000
    total time taken by event execution: 254.1802
    per-request statistics:
         min:                            0.0024s
         avg:                            0.0254s
         max:                            0.4542s
         approx.  95 percentile:         0.1522sThreads fairness:
    events (avg/stddev):           625.0000/7.29
    execution time (avg/stddev):   15.8863/0.00

 

性能指标说明

测试数据解说:
通过在test库中构造一张100000记录的表进行测试。测试总耗时约15.8981s,期间总共发生了10000次事务,TPS(每秒事务数)为629.01。总的读写次数为190340,QPS(每秒读写数)为11972.48。总死锁数21次,平均每秒1.32次死锁。


举报

相关推荐

0 条评论