sysbench性能压测以及mysql性能压测

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

    sysbench性能压测以及mysql性能压测

一、Sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于各种不同系统的参数下的数据库负载情况。

 

主要测试方式






cpu性能

磁盘io性能

调度程序性能

内存分配及传输速度

posix线程性能

数据库性能(OLTP基准测试)

找范围内最大素数{时间越短越好}

不同场景下iops{越大越好}

线程并发执行,循环响应信号量花费的时间{越少越好}

以不同块大小传输一定的数量的数据吞吐量大小{越大越好}

并发线程同时申请互斥锁循环一定次数花费的时间{越少越好}

qpstps越高越好

目前sysbench主要支持MYSQL,pgsql,oracle 3种数据库

 

二、安装测试环境:centos6.8   mysql5.7.19

三、安装sysbench-0.5

源码地址https://github.com/BoobooWei/sysbench/archive/master.zip

下载到电脑桌面,然后xshell连接服务器,下载上传软件工具

#cd /usr/local/src/

#yum install lrzsz -y

#rz      #选中下载的软件进行上传

#unzip sysbench-master.zip

#cd sysbench-master

#yum install -y automake libtool -y

#./autogen.sh

报错:autom4te: /usr/bin/m4 failed with exit status: 63

      aclocal: autom4te failed with exit status: 63

显示版本太低了

#查看版本信息 :yum info autoconf

#查看路径:which autoconf

#移除低版本的:rpm -qf /usr/bin/autoconf  rpm -e --nodeps autoconf-2.63

#cd /usr/local/src

#下载新版本软件:wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz

#tar -xzf autoconf-2.69.tar.gz

#cd autoconf-2.69

#./configure

#make && make install

#检查版本是否正确   autoconf -V   #显示路径还是错的

#如果报错重新安装如果没有跳过  make uninstall   make clean

#./configure --prefix=/usr

#make && make install

#autoconf -V   显示正常

#cd /usr/local/src/sysbench-master

#./autogen.sh  显示正常

#./configure    

报错:cannot find MySQL libraries. If you want to compile with MySQL support,缺少mysql依赖

# yum install mysql-devel -y

#./configure      显示正常

#make && make install

四、安装mysql5.7.19

#wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm

#rpm -Uvh mysql57-community-release-el6-9.noarch.rpm

#yum install mysql-community-server

#service mysqld start

#grep 'temporary password' /var/log/mysqld.log

#mysql -uroot -p

#输入过滤出来的密码

#set global validate_password_policy=0;      #设置密码复杂度

#set global validate_password_length=6;      #设置密码长度

#ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc123';   #更改密码

#create database sbtest;

#quit

 

五、测试

Mysql数据库测试

sysbench 0.5通过一系列LUA脚本来替换之前的oltp,来模拟更接近真实的基准测试环境。这些测试脚本包含:insert.luaoltp.luaparallel_prepare.luaselect_random_points.luaupdate_index.luadelete.luaoltp_simple.luaselect.luaselect_random_ranges.luaupdate_non_index.lua,脚本使用方式基本类似。

 

sysbench 0.5默认使用sbtest库,但是需要自己手工先创建好,也可以使用--mysql-db指定,其他非默认项指定选项:

 

--mysql-host

 

--mysql-port

 

--mysql-socket

 

--mysql-user

 

--mysql-password

 

--mysql-db

 

--mysql-ssl

 

prepare

 

生成表并插入数据,可使用parallel_prepare.lua脚本来并行准备数据。

 

-db-driver 服务器类型mysql | drizzle,默认为mysql

 

-mysql-table-engine 表存数引擎

 

-myisam-max-rows MyISAMMAX_ROWS选项(用于大表)

 

-oltp-table-count 生成表数量[sbtest1sbtest2...]

 

-oltp-table-size 生成表的行数

 

-oltp-secondary ID列生成二级索引而不是主键

 

-oltp-auto-inc设置ID列是否自增 on | off,默认为on --oltp-read-only=on

 

--test=sysbench-0.5/sysbench/tests目录下测试脚本

 

sysbench \

--test=/root/sysbench-master/sysbench/tests/db/oltp.lua  \

--mysql-host=localhost  \

--mysql-port=3306  \

--mysql-user=root  \

--mysql-password=abc123 \

--oltp-table-size=100000 \

--num-threads=8 \

--max-time=10 \

--mysql-db=sbtest \

--max-requests=0 \

--oltp-test-mode=complex \

--report-interval=1 \

--mysql-table-engine=innodb  \

[prepare|run|cleanup]准备/测试/清除

 

六、#测试8个线程,我的测试服务器是单核1cpu,准备

#[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua   --mysql-host=localhost  --mysql-port=3306  --mysql-user=root --mysql-password=abc123   --oltp-table-size=100000  --num-threads=8  --max-time=10  --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex  --report-interval=1  --mysql-table-engine=innodb prepare

 

#测试

#[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua   --mysql-host=localhost  --mysql-port=3306  --mysql-user=root --mysql-password=abc123   --oltp-table-size=100000  --num-threads=8  --max-time=10  --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex  --report-interval=1  --mysql-table-engine=innodb run

sysbench 1.0 (using bundled LuaJIT 2.1.0-beta2)

 

Running the test with following options:

Number of threads: 8

Report intermediate results every 1 second(s)

Initializing random number generator from current time

 

 

Initializing worker threads...

 

Threads started!

 

[   1s] threads: 8, tps: 149.71, reads: 2204.79, writes: 613.41, response time: 164.45ms (95%), errors: 0.00, reconnects:  0.00

[   2s] threads: 8, tps: 253.17, reads: 3543.39, writes: 1019.89, response time: 164.45ms (95%), errors: 0.00, reconnects:  0.00

[   3s] threads: 8, tps: 270.37, reads: 3784.14, writes: 1082.47, response time: 170.48ms (95%), errors: 0.00, reconnects:  0.00

[   4s] threads: 8, tps: 314.77, reads: 4402.71, writes: 1248.04, response time: 94.10ms (95%), errors: 0.00, reconnects:  0.00

[   5s] threads: 8, tps: 251.90, reads: 3528.67, writes: 1008.62, response time: 137.35ms (95%), errors: 0.00, reconnects:  0.00

[   6s] threads: 8, tps: 261.96, reads: 3670.37, writes: 1053.82, response time: 142.39ms (95%), errors: 0.00, reconnects:  0.00

[   7s] threads: 8, tps: 309.18, reads: 4328.47, writes: 1243.71, response time: 95.81ms (95%), errors: 0.00, reconnects:  0.00

[   8s] threads: 8, tps: 264.82, reads: 3701.52, writes: 1054.29, response time: 193.38ms (95%), errors: 0.00, reconnects:  0.00

[   9s] threads: 8, tps: 227.02, reads: 3185.27, writes: 919.08, response time: 179.94ms (95%), errors: 0.00, reconnects:  0.00

[  10s] threads: 8, tps: 248.11, reads: 3457.55, writes: 973.44, response time: 144.97ms (95%), errors: 0.00, reconnects:  0.00

OLTP test statistics:

    queries performed:

        read:                            35784

        write:                           10224

        other:                           5112

        total:                           51120

    transactions:                        2556   (255.33 per sec.)

    read/write requests:                 46008  (4595.97 per sec.)

    other operations:                    5112   (510.66 per sec.)

    ignored errors:                      0      (0.00 per sec.)

    reconnects:                          0      (0.00 per sec.)

 

General statistics:

    total time:                          10.1611s

    total number of events:              2556

    total time taken by event execution: 80.0554s

 

Latency statistics:

         min:                                  2.88ms

         avg:                                 31.32ms

         max:                                330.98ms

         approx.  95th percentile:           137.35ms

 

Threads fairness:

    events (avg/stddev):           319.5000/6.71

execution time (avg/stddev):   10.0069/0.00

#单核,超多线程碾压的时候试一试64128个线程

[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua  --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=abc123 --oltp-table-size=10000 --num-threads=64 --max-time=30 --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex --report-interval=1 --mysql-table-engine=innodb run

 

[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua  --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=abc123 --oltp-table-size=10000 --num-threads=128 --max-time=60 --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex --report-interval=1 --mysql-table-engine=innodb run

 

#清除

#[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua   --mysql-host=localhost  --mysql-port=3306  --mysql-user=root --mysql-password=abc123   --oltp-table-size=100000  --num-threads=8  --max-time=10  --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex  --report-interval=1  --mysql-table-engine=innodb  cleanup

sysbench 1.0 (using bundled LuaJIT 2.1.0-beta2)

 

Dropping table 'sbtest1'...

 

如果是多表呢并增加表的大小,情况又会如何呢?

 [root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=abc123 --oltp-tables-count=10 --oltp-table-size=100000 --num-threads=128 --max-time=60 --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex --report-interval=1 --mysql-table-engine=innodb prepare

 

[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=abc123 --oltp-tables-count=10 --oltp-table-size=100000 --num-threads=130 --max-time=20 --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex --report-interval=1 --mysql-table-engine=innodb run

 

CPU测试

 

使用64位整数,测试计算素数直到某个最大值所需要的时间

sysbench --test=cpu --cpu-max-prime=2000 run

 

查看CPU信息方法,查看物理cpu个数

 

grep "physical id" /proc/cpuinfo | sort -u | wc -l 查看核心数量

 

grep "core id" /proc/cpuinfo | sort -u | wc -l 查看线程数量

 

grep "processor" /proc/cpuinfo | sort -u | wc -l

 

sysbench的测试中,--num-threads取值为"线程数量"即可

 

线程(thread)测试

 

测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用

sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run

 

文件IO性能测试

 

生成需要的测试文件,文件总大小5G16个并发线程。执行完后会在当前目录下生成一堆小文件

sysbench --test=fileio --num-threads=16 --file-total-size=5G prepare

 

执行测试,指定随机读写模式:

 

seqwr顺序写入

seqrewr顺序重写

seqrd顺序读取

rndrd随机读取

rndwr随机写入

rndrw混合随机读/

sysbench --test=fileio --num-threads=16 --init-rng=on --file-total-size=5G --file-test-mode=rndrw run

 

除测试文件

 

sysbench --test=fileio --num-threads=16 --file-total-size=5G cleanup

 

内存测试

 

内存测试测试了内存的连续读写性能。

sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=1G run

 

互斥锁(Mutex)测试

 

测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁X

sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run

 











本文转自去轻狂书生51CTO博客,原文链接:http://blog.51cto.com/8999a/1971927,如需转载请自行联系原作者



相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
测试技术
性能场景之压测策略设计
【2月更文挑战第19天】性能场景之压测策略设计
289 4
性能场景之压测策略设计
|
2月前
|
安全 关系型数据库 MySQL
mysql安全性能
mysql安全性能
37 10
|
3月前
|
缓存 关系型数据库 MySQL
如何优化MySQL性能
对于使用MySQL数据库的开发人员来说,优化数据库性能是一个非常重要的任务。本文将介绍一些优化MySQL性能的方法,包括索引优化、查询优化、硬件升级等方面,帮助开发人员提高应用程序的性能和响应速度。
113 0
|
16天前
|
存储 关系型数据库 MySQL
MySQL数据库性能大揭秘:表设计优化的高效策略(优化数据类型、增加冗余字段、拆分表以及使用非空约束)
MySQL数据库性能大揭秘:表设计优化的高效策略(优化数据类型、增加冗余字段、拆分表以及使用非空约束)
|
16天前
|
缓存 关系型数据库 MySQL
MySQL查询优化:提速查询效率的13大秘籍(合理使用索引合并、优化配置参数、使用分区优化性能、避免不必要的排序和group by操作)(下)
MySQL查询优化:提速查询效率的13大秘籍(合理使用索引合并、优化配置参数、使用分区优化性能、避免不必要的排序和group by操作)(下)
|
1月前
|
消息中间件 弹性计算 测试技术
如何快速实现 Kafka 性能压测
如何快速实现 Kafka 性能压测
89801 1
|
1月前
|
算法 Java 测试技术
性能工具之代码级性能测试工具ContiPerf
【2月更文挑战第23天】性能工具之代码级性能测试工具ContiPerf
266 1
性能工具之代码级性能测试工具ContiPerf
|
1月前
|
负载均衡 NoSQL 关系型数据库
性能基础之全链路压测知识整理
【2月更文挑战第16天】性能基础之全链路压测知识整理
178 11
|
2月前
|
关系型数据库 MySQL 数据库
RDS数据库测评:性能超出预期,双11优惠还在继续
RDS数据库测评:性能超出预期,双11优惠还在继续
30 0
|
3月前
|
SQL 关系型数据库 MySQL
MySQL数据库进阶实战:优化性能、提高安全性和实现高可用性
MySQL数据库进阶实战:优化性能、提高安全性和实现高可用性
102 0