• GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。

介绍

新业务上线的时候通常需要对数据库性能进行压力测试,以确认是否满足需要,今天简单介绍下sysbench的用法:

  • 1.sysbench 是一个开源跨平台的多线程性能测试工具。
  • 2.可以用来进行 CPU、内存、磁盘IO、线程、数据库的性能测试。
  • 3.目前支持的数据库是 MySQL、Oracle 和 PostgreSQL。

安装

1.YUM 安装

curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench

2.安装完成后会有一些 lua 脚本

[root@mgr1 src]# ll /usr/share/sysbench/
total 132
-rwxr-xr-x. 1 root root 1452 May 8 2020 bulk_insert.lua
-rw-r--r--. 1 root root 14369 May 8 2020 oltp_common.lua
-rwxr-xr-x. 1 root root 1290 May 8 2020 oltp_delete.lua
-rwxr-xr-x. 1 root root 2415 May 8 2020 oltp_insert.lua
......

3.部分lua脚本说明

  • insert.lua 单值插入数据
  • bulk_inert.lua 批量插入数据
  • delete.lua 删除数据
  • select.lua 简单主键查询
  • oltp.lua 混合读写测试

用法

1.sysbench 常用参数

sysbench [general-options]... --test=<test-name> [test-options]... command
--num-threads=N # 创建测试线程的数,默认为1.
--max-requests=N # 请求的最大数目,默认为10000,0 代表不限制。
--max-time=N # 最大执行时间,单位是s。默认是0,不限制。
--forced-shutdown=STRING # 超过 max-time 的时候会强制中断。默认是off。
--thread-stack-size=SIZE # 每个线程的堆栈大小。默认是32K。
--init-rng=[on|off] # 在测试开始时是否初始化随机数发生器。默认是off。
--test=STRING # 指定测试项目名称。
--debug=[on|off] # 是否显示更多的调试信息。默认是off。
--validate=[on|off] # 在可能情况下执行验证检查。默认是off。
--version=[on|off] # 版本信息。
--help=[on|off] # 帮助信息。

2.可以测试的项目

fileio # IO
cpu - # CPU
memory # 内存
threads # 线程
mutex # 互斥性能
oltp # 数据库,事务处理

3.各个测试项目查看帮助

# IO
sysbench --test=fileio help
# CPU
sysbench --test=cpu help
# 内存
sysbench --test=memory help
# 线程
sysbench --test=threads help
# 互斥性能
sysbench --test=mutex help
# 事务处理
sysbench --test=oltp help

4.测试阶段

prepare:测试前准备工作,例如为fileis测试在磁盘上创建必要的文件,为OLTP测试准备测试数据
run:执行完整的测试,必须指定–-test选项
cleanup:测试结束后删除数据

三、测试

3.1 文件IO测试

磁盘IO性能测试,主要查看请求数(request)和总体的吞吐量(total)。

[root@mgr1 src]# sysbench --test=fileio --num-threads=4 --file-total-size=1G --file-test-mode=rndrw prepare
sysbench 0.4.12.10: multi-threaded system evaluation benchmark 128 files, 8192Kb each, 1024Mb total
Creating files for the test...
Extra file open flags: 0
Reusing existing file test_file.0
Reusing existing file test_file.1
Reusing existing file test_file.2
Reusing existing file test_file.127
No bytes written. [root@mgr1 src]# sysbench --test=fileio --num-threads=4 --file-total-size=1G --file-test-mode=rndrw run
sysbench 0.4.12.10: 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 Extra file open flags: 0
128 files, 8Mb each
1Gb 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: 6000 reads, 4000 writes, 12800 Other = 22800 Total
Read 93.75Mb Written 62.5Mb Total transferred 156.25Mb (6.3811Mb/sec)
408.39 Requests/sec executed General statistics:
total time: 24.4863s
total number of events: 10000
total time taken by event execution: 0.1070
response time:
min: 0.00ms
avg: 0.01ms
max: 13.36ms
approx. 95 percentile: 0.01ms Threads fairness:
events (avg/stddev): 2500.0000/526.25
execution time (avg/stddev): 0.0267/0.01

3.2、CPU测试

CPU测试计算质数直到某个最大值所需要的时间,主要方法是进行素数的加法运算,在下面的例子中,指定了最大的素数为 10000

[root@mgr1 src]# sysbench --test=cpu --cpu-max-prime=10000 run
sysbench 0.4.12.10: 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 Doing CPU performance benchmark Primer numbers limit: 10000 Threads started!
Done. General statistics:
total time: 10.7192s
total number of events: 10000
total time taken by event execution: 10.7031
response time:
min: 0.90ms
avg: 1.07ms
max: 10.32ms
approx. 95 percentile: 1.30ms Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 10.7031/0.00

3.3 线程测试

  • --thread-yields=N 每个请求产生多少个线程。默认是1000
  • --thread-locks=N 每个线程的锁的数量。默认是8
[root@mgr1 src]# sysbench --test=threads --num-threads=32 --thread-yields=48 --thread-locks=2 run
sysbench 0.4.12.10: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 32
Random number generator seed is 0 and will be ignored Doing thread subsystem performance test
Thread yields per test: 48 Locks used: 2
Threads started!
Done. General statistics:
total time: 2.0646s
total number of events: 10000
total time taken by event execution: 66.0149
response time:
min: 0.03ms
avg: 6.60ms
max: 69.03ms
approx. 95 percentile: 24.01ms Threads fairness:
events (avg/stddev): 312.5000/22.72
execution time (avg/stddev): 2.0630/0.00

3.4 内存测试

  • 测试内存连续读写性能
[root@mgr1 src]# sysbench --test=memory --memory-block-size=8k --memory-total-size=1G run
sysbench 0.4.12.10: multi-threaded system evaluation benchmark
Operations performed: 1310720 (216525.32 ops/sec)
10140.00 MB transferred (2097.85 MB/sec)
Test execution summary:
total time: 3.6055s
total number of events: 1410720
total time taken by event execution: 201.0560
per-request statistics:
min: 0.00ms
avg: 0.16ms
max: 1071.04ms
approx. 95 percentile: 0.02ms
Threads fairness:
events (avg/stddev): 12107.2000/3870.38
execution time (avg/stddev): 2.0506/0.28

3.5 OLTP 测试

  • 测试事务处理数,和读写数
# prepare准备数据
[root@mgr1 src]# sysbench --test=oltp --mysql-table-engine=InnoDB --oltp-table-size=1000000 --mysql-socket=/data/GreatSQL/mysql.sock --mysql-user=root --mysql-password=GreatSQL --mysql-db=test prepare
sysbench 0.4.12.10: multi-threaded system evaluation benchmark No DB drivers specified, using mysql
Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'... # 正式run测试
[root@mgr1 src]# sysbench --test=oltp --mysql-table-engine=InnoDB --oltp-table-size=1000000 --mysql-socket=/data/GreatSQL/mysql.sock --mysql-user=root --mysql-password=GreatSQL --mysql-db=test run
sysbench 0.4.12.10: multi-threaded system evaluation benchmark No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored 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
Using 1 test tables
Threads started!
Done. OLTP test statistics:
queries performed:
read: 140000
write: 40000
other: 20000
total: 200000
transactions: 10000 (27.65 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 180000 (497.67 per sec.)
other operations: 20000 (55.30 per sec.) General statistics:
total time: 361.6868s
total number of events: 10000
total time taken by event execution: 361.5698
response time:
min: 18.73ms
avg: 36.16ms
max: 283.84ms
approx. 95 percentile: 63.45ms Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 361.5698/0.00 # 删除 sbtest 测试表
[root@mgr1 src]# sysbench --test=oltp --mysql-table-engine=InnoDB --oltp-table-size=1000000 --mysql-socket=/data/GreatSQL/mysql.sock --mysql-user=root --mysql-password=GreatSQL --mysql-db=test cleanup
sysbench 0.4.12.10: multi-threaded system evaluation benchmark No DB drivers specified, using mysql
Dropping table 'sbtest'...
Done.

Enjoy GreatSQL

本文由博客一文多发平台 OpenWrite 发布!

技术分享|sysbench 压测工具用法浅析的更多相关文章

  1. 内存压测工具Memtester

    在做压力测试时,发现一个内存压测工具Memtester,可以随意设置内存占用大小,非常方便 下载地址:http://pyropus.ca/software/memtester/old-versions ...

  2. 压测工具使用(vegeta)

    一.压测工具vegeta 1.介绍 Vegeta 是一个用 Go 语言编写的多功能的 HTTP 负载测试工具,它提供了命令行工具和一个开发库. 官方地址:https://github.com/tsen ...

  3. wrk压测工具使用

    介绍分为四部分 1.wrk简述 2.wrk安装 3.wrk运行参数 4.wrk高级用法 1.wrk简述 当使用ab做压测的时候发现,ab的客户端消耗很大,而且测试时性能较差,测试redis,sprin ...

  4. mysql常用压测工具

    关键字:mysql压测工具 mysqlslap.sysbench  基准测试sysbench 压力测试 tpcc  具体怎么使用百度

  5. 05:Sysbench压测-innodb_deadlock_detect参数对性能的影响

    目录 sysbench压测-innodb_deadlock_detect参数对性能的影响 一.OLTP测试前准备 二.进行OLTP测试 三.测试结果解读: 四.关于测试后的结论: 五.关于测试后的性能 ...

  6. 精准容量、秒级弹性,压测工具 + SAE 方案如何完美突破传统大促难关?

    作者 | 代序 阿里云云原生技术团队 本文整理自<Serverless 技术公开课>,"Serverless"公众号后台回复"入门",即可获取系列文 ...

  7. 3. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识bombardier

    目录 堪比JMeter的.Net压测工具 - Crank 入门篇 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识yml 堪比JMeter的.Net压测工具 - Crank 进阶篇 ...

  8. 4. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识wrk、wrk2

    目录 堪比JMeter的.Net压测工具 - Crank 入门篇 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识yml 堪比JMeter的.Net压测工具 - Crank 进阶篇 ...

  9. 5. 堪比JMeter的.Net压测工具 - Crank 实战篇 - 接口以及场景压测

    目录 堪比JMeter的.Net压测工具 - Crank 入门篇 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识yml 堪比JMeter的.Net压测工具 - Crank 进阶篇 ...

随机推荐

  1. unity---给物体施加普通力和位置力

    普通力 让物体沿着某一方向获得一个力,vector3方向 addForceObj.GetComponent<Rigidbody>().AddForce(1000,0,1000); 位置力 ...

  2. 安装Samba到CentOS(YUM)

    运行环境 系统版本:CentOS Linux release 7.3.1611 软件版本:Samba-4.6.2 硬件要求:无 安装过程 1.基础网络配置 配置一个静态IP,关闭防火墙.SeLinux ...

  3. 每天一个 HTTP 状态码 205

    205 Reset Content 205 Reset Content 表示服务器成功地处理了客户端的请求,要求客户端重置它发送请求时的文档视图.这个响应码跟 204 No Content 类似,也不 ...

  4. mongoDB 命令大全

    每日一句 There should be a better way to start a day than waking up every morning. 应该有更好的方式开始新一天, 而不是千篇一 ...

  5. hash和history路由的区别

    在了解路由模式前,我们先看下 什么是单页面应用,vue-router  的实现原理是怎样的,这样更容易理解路由. SPA与前端路由 SPA(单页面应用,全程为:Single-page Web appl ...

  6. C#与SQL Server连接时,如何编写连接字符串?

    一.Windows身份验证时: String conStr = "Data Source=数据库服务器地址;Initial Catalog=数据库名称;Integrated Security ...

  7. CabloyJS 4.12震撼发布,及新版教程尝鲜

    引言 凡是可以用 JavaScript 来写的应用,最终都会用 JavaScript 来写 | Atwood 定律 目前市面上出现的大多数与 NodeJS 相关的框架,基本都将 NodeJS 定位在工 ...

  8. 28.MysQL的日志管理及备份与恢复

    MySQL 索引.事务与存储引擎 目录 MySQL 索引.事务与存储引擎 MySQL 索引 索引的概念 索引的作用及副作用 索引的作用 索引的副作用 创建索引的原则依据 索引的分类和创建 普通索引 唯 ...

  9. Phantomjs实用代码段(持续更新中……)

    一.下载 下载链接二.解压安装包 直接解压即可三.配置环境变量 找到高级系统设置,打开它,出现以下图.点击环境变量. 分别点击编辑按钮 分别新建添加当初的解压路径,到bin文件夹.点击确定. 这样,环 ...

  10. 扩展-PageHelper分页插件

    1.PageHelper 分页插件简介 1) PageHelper是MyBatis中非常方便的第三方分页插件 2) 官方文档: https://github.com/pagehelper/Mybati ...