Mysql 压力测试-sysbench

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: sysbench安装、测试,主要从OLTP、CPU,IO,Memory四个方面测试 报错处理 checking build system type.

sysbench安装

./configure  --prefix=/sysbench/sysbench/ --with-mysql-includes=/mysql/mysql/include/ --with-mysql-libs=/mysql/mysql/lib/  --with-mysql

make

make install


安装过程报错处理

checking build system type... Invalid configuration `x86_64-unknown-linux-': machine `x86_64-unknown-linux' not recognized

configure: error: /bin/sh config/config.sub x86_64-unknown-linux- failed


解决方法:安装相关依赖包

yum install libtool


报错信息:

/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
make[2]: *** [sysbench] Error 1
make[2]: Leaving directory `/sysbench/sysbench/sysbench'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/sysbench/sysbench/sysbench'
make: *** [all-recursive] Error 1


解决方法:

ln -s libmysqlclient.so.20.3.4 libmysqlclient_r.so


##sysbench测试,主要从OLTP、CPU,IO,Memory四个方面测试

1、OLTP测试


sysbench --test=oltp help

--oltp-test-mode=STRING                    测试类型:simple(简单select测试),complex(事务测试),nontrx(非事务测试),sp(存储过程) ;默认complex
  --oltp-reconnect-mode=STRING             连接类型:session(每个线程到测试结束不重新连接),transaction(执行每个事务重新连接),query(每一个查询重新连接),random(随机);默认 [session]
  --oltp-sp-name=STRING                    指定执行测试的存储过程名
  --oltp-read-only=[on|off]                仅执行select测试,默认关闭
  --oltp-avoid-deadlocks=[on|off]          更新过程中忽略死锁,默认[off]
  --oltp-skip-trx=[on|off]                 语句以bigin/commit开始结尾,默认[off]
  --oltp-range-size=N                      范围查询的范围大小,默认 [100],例如begin 100 and 200
  --oltp-point-selects=N                   单个事务中select查询的数量,默认 [10]
  --oltp-use-in-statement=N                每个查询中主键查找(in 10个值)的数量,默认 [0]
  --oltp-simple-ranges=N                   单个事务中执行范围查询的数量(SELECT c  FROM sbtest WHERE id BETWEEN  N AND  M),默认[1]
  --oltp-sum-ranges=N                      单个事务中执行范围sum查询的数量,默认 [1]
  --oltp-order-ranges=N                    单个事务中执行范围order by查询的数量,默认[1]
  --oltp-distinct-ranges=N                 单个事务中执行范围distinct查询的数量,默认[1]
  --oltp-index-updates=N                   单个事务中执行索引更新的操作的数量,默认[1]
  --oltp-non-index-updates=N               单个事务中执行非索引更新操作的数量,默认[1]
  --oltp-nontrx-mode=STRING                指定单独非事务测试类型进行测试,默认select {select, update_key, update_nokey, insert, delete} [select]
  --oltp-auto-inc=[on|off]                 id列默认自增,默认[on]
  --oltp-connect-delay=N                   指定每一次重新连接延时的时长,默认1秒 [10000]
  --oltp-user-delay-min=N                  minimum time in microseconds to sleep after each request [0]
  --oltp-user-delay-max=N                  maximum time in microseconds to sleep after each request [0]
  --oltp-table-name=STRING                 指定测试的表名,默认[sbtest]
  --oltp-table-size=N                      指定表的记录大小,默认[10000]
  --oltp-dist-type=STRING                  随机数分布状态。uniform(均匀分布)、gauss(高斯分布)、special(特殊分布),默认 [special]
  --oltp-dist-iter=N                       number of iterations used for numbers generation [12]
  --oltp-dist-pct=N                        启用百分比特殊分布,默认 [1]
  --oltp-dist-res=N                        special 百分比[75]
  --oltp-point-select-mysql-handler=[on|off] Use MySQL HANDLER for point select [off]
  --oltp-point-select-all-cols=[on|off]    select查询测试时select所有列,默认[off]
  --oltp-secondary=[on|off]                索引不是主键索引而是二级索引,默认[off]
  --oltp-num-partitions=N                  指定表分区的数量,默认 [0]
  --oltp-num-tables=N                      指定测试表的数量,默认[1]
General database options:
  --db-driver=STRING  指定测试数据库类型,默认mysql
  --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
 
 
prepare --生成需要的测试表
sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=bhs --oltp-table-size=100000 --db-driver=mysql --num-threads=2 --mysql-socket=/mysql/data/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root prepare

run     --性能测试阶段
sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=bhs --oltp-table-size=100000 --db-driver=mysql --num-threads=2 --mysql-socket=/mysql/data/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root run

cleanup  --清理测试时的测试表
[root@slv2 ~]# sysbench --test=oltp --mysql-table-engine=innodb --mysql-db=bhs --oltp-table-size=100000 --db-driver=mysql --num-threads=2 --mysql-socket=/mysql/data/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root cleanup


Doing 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:                            140000
        write:                           50000
        other:                           20000
        total:                           210000
    transactions:                        10000  (141.69 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 190000 (2692.10 per sec.)
    other operations:                    20000  (283.38 per sec.)

Test execution summary:
    total time:                          70.5769s
    total number of events:              10000
    total time taken by event execution: 141.0690
    per-request statistics:
         min:                            0.0063s
         avg:                            0.0141s
         max:                            0.0886s
         approx.  95 percentile:         0.0224s

Threads fairness:
    events (avg/stddev):           5000.0000/69.00
    execution time (avg/stddev):   70.5345/0.00

结果:测试执行时间:70.5769秒,TPS:141.69/s RQ:2692.10/s  95%的请求花费了0.0224s   
   
2、cpu测试
sysbench --test=cpu --num-threads=12 --max-requests=10000 --cpu-max-prime=20000 run

Doing CPU performance benchmark

Threads started!
Done.

Maximum prime number checked in CPU test: 20000


Test execution summary:
    total time:                          31.1477s
    total number of events:              10000
    total time taken by event execution: 373.0990
    per-request statistics:
         min:                            0.0024s
         avg:                            0.0373s
         max:                            0.1288s
         approx.  95 percentile:         0.0532s

Threads fairness:
    events (avg/stddev):           833.3333/2.75
    execution time (avg/stddev):   31.0916/0.03
   
   
3、文件IO测试
/sysbench --test=fileio help

--file-num=N                   创建测试文件的数量,默认128个
  --file-block-size=N          block size大小,默认16K
  --file-total-size=SIZE       所有文件的总大小,默认2G
  --file-test-mode=STRING      测试类型 {seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}
  --file-io-mode=STRING         I/O模式,需要系统支持默认sync[sync(同步IO),async(异步IO),mmap()]
  --file-async-backlog=N        每个线程的异步操作队列数,默认128个,需要--file-io-mode=async;
  --file-extra-flags=STRING     additional flags to use on opening files {sync,dsync,direct} []
  --file-fsync-freq=N           当请求数达到多少时执行fsync()刷新,默认100,0代表过程中不执行fsync()
  --file-fsync-all=[on|off]     执行每一个写操作后执行fsync()刷新操作,默认关闭off
  --file-fsync-end=[on|off]     测试结束执行fsync()操作,默认开启on
  --file-fsync-mode=STRING      同步刷新方法,默认fsync {fsync, fdatasync}
  --file-merged-requests=N      合并指定数量的IO请求,0代表不合并,默认0
  --file-rw-ratio=N            读写比例,默认1.5/1
 

sysbench  --test=fileio --num-threads=12 --max-requests=10000 --file-total-size=3G --file-test-mode=rndrw prepare
128 files, 24576Kb each, 3072Mb total
Creating files for the test...

sysbench  --test=fileio --num-threads=12 --max-requests=10000 --file-total-size=3G --file-test-mode=rndrw run

Running the test with following options:
Number of threads: 12

Extra file open flags: 0
128 files, 24Mb each
3Gb total file size
Block size 16Kb
Number of random requests for random IO: 10000
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
Threads started!
Done.

Operations performed:  6004 Read, 3996 Write, 12800 Other = 22800 Total
Read 93.812Mb  Written 62.438Mb  Total transferred 156.25Mb  (16.923Mb/sec)
 1083.05 Requests/sec executed

Test execution summary:
    total time:                          9.2332s
    total number of events:              10000
    total time taken by event execution: 14.3464
    per-request statistics:
         min:                            0.0000s
         avg:                            0.0014s
         max:                            0.6224s
         approx.  95 percentile:         0.0063s

Threads fairness:
    events (avg/stddev):           833.3333/67.54
    execution time (avg/stddev):   1.1955/0.13
   
   

sysbench  --test=fileio --num-threads=12 --max-requests=10000 --file-total-size=3G --file-test-mode=rndrw  cleanup
Removing test files...


thread测试  --用于高负载下的线程性能测试
thread-yields  每个请求执行“lock/yield/unlock" 循环次数 默认1000
thread-locks    每个线程的互斥锁 默认8个


sysbench  --test=threads --num-threads=12 --max-requests=10000 --thread-yields=100  --thread-locks=2  run

Running the test with following options:
Number of threads: 12

Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 2
Threads started!
Done.


Test execution summary:
    total time:                          1.0595s
    total number of events:              10000
    total time taken by event execution: 12.6745
    per-request statistics:
         min:                            0.0000s
         avg:                            0.0013s
         max:                            0.0374s
         approx.  95 percentile:         0.0086s

Threads fairness:
    events (avg/stddev):           833.3333/36.08
    execution time (avg/stddev):   1.0562/0.00
   
4、memory测试   --主要是针对不同的块大小进行内存的连续读写或者随机读写测试

--memory-access-mode=seq --顺序分配
sysbench  --test=memory --num-threads=12 --max-requests=10000 --memory-block-size=8K --memory-total-size=1G --memory-access-mode=seq  run


Running the test with following options:
Number of threads: 12

Doing memory operations speed test
Memory block size: 8K

Memory transfer size: 1024M

Memory operations type: write
Memory scope type: global
Threads started!
Done.

Operations performed: 131072 (624394.96 ops/sec)

1024.00 MB transferred (4878.09 MB/sec)


Test execution summary:
    total time:                          0.2099s
    total number of events:              131072
    total time taken by event execution: 2.1804
    per-request statistics:
         min:                            0.0000s
         avg:                            0.0000s
         max:                            0.0336s
         approx.  95 percentile:         0.0000s

Threads fairness:
    events (avg/stddev):           10922.6667/1094.34
    execution time (avg/stddev):   0.1817/0.02
   
--memory-access-mode=rnd --随机分配
sysbench  --test=memory --num-threads=12 --max-requests=10000 --memory-block-size=8K --memory-total-size=1G --memory-access-mode=rnd  run

Operations performed: 131072 (961669.38 ops/sec)

1024.00 MB transferred (7513.04 MB/sec)


Test execution summary:
    total time:                          0.1363s
    total number of events:              131072
    total time taken by event execution: 1.0696
    per-request statistics:
         min:                            0.0000s
         avg:                            0.0000s
         max:                            0.0310s
         approx.  95 percentile:         0.0000s

Threads fairness:
    events (avg/stddev):           10922.6667/2127.00
    execution time (avg/stddev):   0.0891/0.01

   
sysbench  --test=memory --num-threads=12 --max-requests=10000 --memory-block-size=16K --memory-total-size=1G --memory-access-mode=rnd  run

Doing memory operations speed test
Memory block size: 16K

Memory transfer size: 1024M

Memory operations type: write
Memory scope type: global
Threads started!
Done.

Operations performed: 65536 (973518.40 ops/sec)

1024.00 MB transferred (15211.23 MB/sec)


Test execution summary:
    total time:                          0.0673s
    total number of events:              65536
    total time taken by event execution: 0.4436
    per-request statistics:
         min:                            0.0000s
         avg:                            0.0000s
         max:                            0.0272s
         approx.  95 percentile:         0.0000s

Threads fairness:
    events (avg/stddev):           5461.3333/1120.48
    execution time (avg/stddev):   0.0370/0.01

sysbench  --test=memory --num-threads=12 --max-requests=10000 --memory-block-size=16K --memory-total-size=1G --memory-access-mode=seq  run

Doing memory operations speed test
Memory block size: 16K

Memory transfer size: 1024M

Memory operations type: write
Memory scope type: global
Threads started!
Done.

Operations performed: 65536 (284231.81 ops/sec)

1024.00 MB transferred (4441.12 MB/sec)


Test execution summary:
    total time:                          0.2306s
    total number of events:              65536
    total time taken by event execution: 2.4985
    per-request statistics:
         min:                            0.0000s
         avg:                            0.0000s
         max:                            0.0504s
         approx.  95 percentile:         0.0000s

Threads fairness:
    events (avg/stddev):           5461.3333/462.35
    execution time (avg/stddev):   0.2082/0.01

 测试结果:分配同样大小的内存 块越大分配速率越快,随机分配比顺序分配的速度快







相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
2月前
Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
22 1
|
2月前
|
Java 关系型数据库 数据库连接
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
35 1
|
11天前
|
关系型数据库 MySQL 测试技术
sysbench 对MySQL压测100分钟的命令
使用 `sysbench` 对 MySQL 数据库进行性能测试(压测)时,首先确保 `sysbench` 和 MySQL 数据库已经安装,并且你有一个测试数据库可以使用。下面是一个针对 MySQL 数据库进行压测的示例命令,测试时长为 100 分钟(6000 秒)。 在运行此命令之前,请确保以下内容: - 使用适当的数据库连接参数(主机、端口、用户名、密码、数据库名)。 - 根据你的需求调整测试参数(如并发数、线程数、事务数等)。 以下是一个示例命令,使用 `sysbench` 对 MySQL 数据库进行压测 100 分钟: ```shell sysbench --db-driver=m
|
12天前
|
DataWorks NoSQL 关系型数据库
DataWorks操作报错合集之在使用 DataWorks 进行 MongoDB 同步时遇到了连通性测试失败,实例配置和 MongoDB 白名单配置均正确,且同 VPC 下 MySQL 可以成功连接并同步,但 MongoDB 却无法完成同样的操作如何解决
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
30 1
|
12天前
|
存储 关系型数据库 MySQL
RDS for MySQL测试
【4月更文挑战第28天】
|
18天前
|
存储 SQL 关系型数据库
Mysqlslap性能测试MySQL三种存储引擎
Mysqlslap性能测试MySQL三种存储引擎
|
1月前
|
关系型数据库 MySQL C语言
mysql的压力测试软件sysbench
mysql的压力测试软件sysbench
6 1
|
2月前
|
监控 关系型数据库 MySQL
Flink CDC产品常见问题之使用3.0测试mysql到starrocks启动报错如何解决
Flink CDC(Change Data Capture)是一个基于Apache Flink的实时数据变更捕获库,用于实现数据库的实时同步和变更流的处理;在本汇总中,我们组织了关于Flink CDC产品在实践中用户经常提出的问题及其解答,目的是辅助用户更好地理解和应用这一技术,优化实时数据处理流程。
|
3月前
|
关系型数据库 MySQL Java
Mysql专栏 - 线上调优与压力测试
Mysql专栏 - 线上调优与压力测试
93 0
|
20天前
|
网络协议 安全 测试技术
性能工具之emqtt-bench BenchMark 测试示例
【4月更文挑战第19天】在前面两篇文章中介绍了emqtt-bench工具和MQTT的入门压测,本文示例 emqtt_bench 对 MQTT Broker 做 Beachmark 测试,让大家对 MQTT消息中间 BenchMark 测试有个整体了解,方便平常在压测工作查阅。
114 7
性能工具之emqtt-bench BenchMark 测试示例