sysbench在mysql中的使用

2024-01-24 19:28
文章标签 mysql 使用 database sysbench

本文主要是介绍sysbench在mysql中的使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

sysbench安装

[root@gip ~]# yum install epel-release -y

[root@gip ~]#  yum install sysbench -y

查看sysbench的版本:

[root@gip ~]# sysbench --version
sysbench 1.1.0-df89d34

基于sysbench构造测试表和测试数据

sysbench --db-driver=mysql --time=5 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb --mysql-db=test_db --tables=2 --table_size=10 oltp_read_write --db-ps-mode=disable prepare

命令行中的参数说明:

--db-driver=mysql:代表数据库驱动 
--time=300:这个就是说连续访问300秒 
--threads=10:这个就是说用10个线程模拟并发访问
--report-interval=1:这个就是说每隔1秒输出一下压测情况 
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb:数据库的用户和密码等信息 
--mysql-db=test_db --tables=2 --table_size=10:这一串的意思,就是说在test_db这个库里,构造2个测试表,每个测试表里构造10条测试数据,测试表的名字会是类似于sbtest1,sbtest2这个样子的 
oltp_read_write:这个就是说,执行oltp数据库的读写测试 
--db-ps-mode=disable:这个就是禁止ps模式 最后有一个prepare,意思是参照这个命令的设置去构造出来我们需要的数据库里的数据,他会自动创建20个测试表,每个表里创建100万条测试数据。

下面是命令执行后,输出的信息:

    sysbench 1.1.0-df89d34 (using bundled LuaJIT 2.1.0-beta3)
    
    Initializing worker threads...
    
    Creating table 'sbtest1'...
    Creating table 'sbtest2'...
    Inserting 10 records into 'sbtest2'
    Inserting 10 records into 'sbtest1'
    Creating a secondary index on 'sbtest2'...
    Creating a secondary index on 'sbtest1'...

查看创建的表信息:

mysql> show tables;
+-------------------+
| Tables_in_test_db |
+-------------------+
| sbtest1           |
| sbtest2           |
+-------------------+
2 rows in set (0.01 sec)

mysql> select count(*) from sbtest1;
+----------+
| count(*) |
+----------+
|       10 |
+----------+
1 row in set (0.01 sec)
 

数据库读写性能测试

做性能测试前,需要先创建数据

[root@localhost bin]# sysbench --db-driver=mysql --time=50 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb --mysql-db=test_db --tables=10 --table_size=1000 oltp_read_write --db-ps-mode=disable prepare

数据库读写性能测试,将执行指令最后的prepare修改成run

[root@localhost bin]# sysbench --db-driver=mysql --time=50 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb --mysql-db=test_db --tables=10 --table_size=1000 oltp_read_write --db-ps-mode=disable run

执行run命令后数据显示:

[ 10s ] thds: 10 tps: 800.11 qps: 16012.28 (r/w/o: 11207.60/3204.46/1600.23) lat (ms,95%): 15.27 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 10 tps: 697.26 qps: 13957.21 (r/w/o: 9771.64/2791.04/1394.52) lat (ms,95%): 13.46 err/s: 0.00 reconn/s: 0.00

对表中的数据进行说明,以第一条数据做解释描述:

​ thds: 10,这个意思就是有10个线程在压测

​ tps: 800.11,这个意思就是每秒执行了800.11个事务

​ qps:  16012.28,这个意思就是每秒可以执行2996.03个请求

​ (r/w/o: 11544.02/3298.07/1642.90),这个意思就是说,在每秒16012.28个请求中,有11544.02个请求是读请求,3298.07个请求是写请求,1642.90个请求是其他的请求,就是对QPS进行了拆解

​ lat (ms, 95%): 10.27,这个意思就是说,95%的请求的延迟都在 10.27毫秒以下

​ err/s: 0.00 reconn/s: 0.00,这两个的意思就是说,每秒有0个请求是失败的,发生了0次网络重连

下面是执行完成后控制台输出的数据:

SQL statistics:
    queries performed:
        read:                            482034 // 这就是说在50s的压测期间执行了482034 次的读请求
        write:                           137724 // 这就是说在50s的压测期间执行了137724 次的写请求
        other:                           68862  // 这就是说在50s的压测期间执行了68862  次其他请求
        total:                           688620 // 这就是说在300s的压测期间执行了688620 次总的请求
    transactions:                        34431  (684.29 per sec.)  //共执行了34431  次事务 平均1秒执行684.29 次事务
    queries:                             688620 (13685.79 per sec.) //共执行688620次查询 平均每秒13685.79次
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

Throughput:
    events/s (eps):                      684.2895
    time elapsed:                        50.3164s
    total number of events:              34431

Latency (ms):
         min:                                    4.15  //请求中延迟最小的是4.15ms
         avg:                                   14.61  //请求中延迟平均的是14.61ms
         max:                                  499.87  //请求中延迟最大的是499.87ms
         95th percentile:                       13.46  //95%的请求中延迟在13.46ms以内
         sum:                               502991.87

Threads fairness:
    events (avg/stddev):           3443.1000/21.30
    execution time (avg/stddev):   50.2992/0.00

数据库读性能测试

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=10000 oltp_read_only --db-ps-mode=disable run

数据库删除性能测试

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=10000 oltp_delete --db-ps-mode=disable run

数据库更新索引字段性能测

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=10000 oltp_update_index --db-ps-mode=disable run

数据库更新非索引字段性能测试

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_update_non_index --db-ps-mode=disable run

数据库插入数据性能测试

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=10000 oltp_insert --db-ps-mode=disable run

数据库写性能测试

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=10000 oltp_write_only --db-ps-mode=disable run

清除数据,将run改成cleanup

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=10000 oltp_read_write --db-ps-mode=disable cleanup


[root@gip ~]# sysbench --db-driver=mysql --time=50 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb --mysql-db=test_db --tables=10 --table_size=1000 oltp_read_write --db-ps-mode=disable cleanup
sysbench 1.1.0-df89d34 (using bundled LuaJIT 2.1.0-beta3)Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
Dropping table 'sbtest6'...
Dropping table 'sbtest7'...
Dropping table 'sbtest8'...
Dropping table 'sbtest9'...
Dropping table 'sbtest10'...

这篇关于sysbench在mysql中的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/640746

相关文章

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

C#中Guid类使用小结

《C#中Guid类使用小结》本文主要介绍了C#中Guid类用于生成和操作128位的唯一标识符,用于数据库主键及分布式系统,支持通过NewGuid、Parse等方法生成,感兴趣的可以了解一下... 目录前言一、什么是 Guid二、生成 Guid1. 使用 Guid.NewGuid() 方法2. 从字符串创建

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

MySQL 中的 CAST 函数详解及常见用法

《MySQL中的CAST函数详解及常见用法》CAST函数是MySQL中用于数据类型转换的重要函数,它允许你将一个值从一种数据类型转换为另一种数据类型,本文给大家介绍MySQL中的CAST... 目录mysql 中的 CAST 函数详解一、基本语法二、支持的数据类型三、常见用法示例1. 字符串转数字2. 数字

Mysql实现范围分区表(新增、删除、重组、查看)

《Mysql实现范围分区表(新增、删除、重组、查看)》MySQL分区表的四种类型(范围、哈希、列表、键值),主要介绍了范围分区的创建、查询、添加、删除及重组织操作,具有一定的参考价值,感兴趣的可以了解... 目录一、mysql分区表分类二、范围分区(Range Partitioning1、新建分区表:2、分

MySQL 定时新增分区的实现示例

《MySQL定时新增分区的实现示例》本文主要介绍了通过存储过程和定时任务实现MySQL分区的自动创建,解决大数据量下手动维护的繁琐问题,具有一定的参考价值,感兴趣的可以了解一下... mysql创建好分区之后,有时候会需要自动创建分区。比如,一些表数据量非常大,有些数据是热点数据,按照日期分区MululbU

SQL Server配置管理器无法打开的四种解决方法

《SQLServer配置管理器无法打开的四种解决方法》本文总结了SQLServer配置管理器无法打开的四种解决方法,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录方法一:桌面图标进入方法二:运行窗口进入检查版本号对照表php方法三:查找文件路径方法四:检查 S

Spring IoC 容器的使用详解(最新整理)

《SpringIoC容器的使用详解(最新整理)》文章介绍了Spring框架中的应用分层思想与IoC容器原理,通过分层解耦业务逻辑、数据访问等模块,IoC容器利用@Component注解管理Bean... 目录1. 应用分层2. IoC 的介绍3. IoC 容器的使用3.1. bean 的存储3.2. 方法注