ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

linux 安装 sysbench 和 使用

2022-07-21 11:34:18  阅读:208  来源: 互联网

标签:-- mysql db oltp user linux test 安装 sysbench


安装  

执行 下载命令

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

  安装

sudo yum -y install sysbench

  查看版本

sysbench --version

  

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

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare

  参数的大概意思

  1、--db-driver=mysql:这个很简单,就是说他基于mysql的驱动去连接mysql数据库,你要是oracle,或者sqlserver,那自然就是其他的数据库的驱动了

  2、--time=300:这个就是说连续访问300秒

  3、--threads=10:这个就是说用10个线程模拟并发访问

  4、--report-interval=1:这个就是说每隔1秒输出一下压测情况

  5、--mysql-host=127.0.0.1:这是你要连接的sql服务连接

  6、--mysql-port=3306:这是你要连接的sql服务端口

  7、--mysql-user=test_user:这是你要连接的sql服务用户名

  8、--mysql-password=test_user:这是你要连接的sql服务密码

  9、--mysql-db=test_db --tables=20 --table_size=1000000:这一串的意思,就是说在test_db这个库里()这里并不会自动创建数据库),构造20个测试表,每个测试表里构造100万条测试数据,测试表的名字会是类似于sbtest1,sbtest2这个样子的

  10、oltp_read_write:这个就是说,执行oltp数据库的读写测试

  11、--db-ps-mode=disable:这个就是禁止ps模式

  12、最后有一个prepare,意思是参照这个命令的设置去构造出来我们需要的数据库里的数据,他会自动创建20个测试表,每个表里创建100万条测试数据,所以这个工具是非常的方便的。

 

对数据库进行360度的全方位测试

测试数据库的综合读写TPS

使用oltp_read_write模式 命令最后不是prepare,是run了,就是运行压测

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

测试数据库的只读性能

使用oltp_read_only模式 命令最后oltp_read_write已经变成oltp_read_only了

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

测试数据库的删除性能

使用oltp_delete

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

测试数据路更新索引字段的性能

使用oltp_update_index

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

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

使用oltp_update_non_index

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

测试数据库的插入性能

使用oltp_insert

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

测试数据库的写入性能

使用oltp_write_only

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_write_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_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable cleanup

压测结果分析

按照我们上面的命令,我们是让他每隔1秒都会输出一次压测报告的,此时他每隔一秒会输出类似下面的一段东西:

 

 

[ 22s ] thds: 10 tps: 380.99 qps: 7312.66 (r/w/o: 5132.99/1155.86/1321.35) lat (ms, 95%): 21.33 err/s: 0.00 reconn/s: 0.00

解释一下这是什么意思,首先他说的这是第22s输出的一段压测统计报告,然后是其他的一些统计字段:

thds: 10 这个意思就是有10个线程在压测
tps: 380.99 这个意思就是每秒执行了380.99个事务
qps: 7610.20 这个意思就是每秒可以执行7610.20个请求
(r/w/o: 5132.99/1155.86/1321.35) 这个意思就是说,在每秒7610.20个请求中,有5132.99个请求是读请求,1155.86个请求是写请求,1321.35个请求是其他的请求,就是对QPS进行了拆解l
at (ms, 95%): 21.33 这个意思就是说,95%的请求的延迟都在21.33毫秒以下
err/s: 0.00 reconn/s: 0.00 这两个的意思就是说,每秒有0个请求是失败的,发生了0次网络重连

 

 

 

 

 

 

 

 

这个压测结果会根据每个人的机器的性能不同有很大的差距,你要是机器性能特别高,那你可以开很多的并发线程去压测,比如100个线程,此时可能会发现数据库每秒的TPS有上千个,如果你的机器性能很低,可能压测出来你的TPS才二三十个,QPS才几百个,这都是有可能的。

另外在完成压测之后,最后会显示一个总的压测报告,我把解释写在下面了:

 

 

SQL statistics:

  queries performed:

    read: 1480084 // 这就是说在300s的压测期间执行了148万多次的读请求

    write: 298457 // 这是说在压测期间执行了29万多次的写请求

    other: 325436 // 这是说在压测期间执行了30万多次的其他请求

    total: 2103977 // 这是说一共执行了210万多次的请求

  transactions: 105180( 350.6 per sec. ) // 这是说一共执行了10万多个事务,每秒执行350多个事务

  queries: 2103977 ( 7013.26 per sec. )// 这是说一共执行了210万多次的请求,每秒执行7000+请求

  ignored errors: 0 (0.00 per sec.)

  reconnects: 0 (0.00 per sec.)

// 下面就是说,一共执行了300s的压测,执行了10万+的事务

General staticstics:

  total time: 300.0052s

  total number of events: 105180

Latency (ms):

  min: 4.32 // 请求中延迟最小的是4.32ms

  avg: 13.42 // 所有请求平均延迟是13.42ms

  max: 45.56 // 延迟最大的请求是45.56ms

  95th percentile: 21.33 // 95%的请求延迟都在21.33ms以内

  sum: 3003811.21 总共耗时xx ms

标签:--,mysql,db,oltp,user,linux,test,安装,sysbench
来源: https://www.cnblogs.com/hg-super-man/p/16501359.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有