基于华为云云耀云服务器L实例开展性能评测|MySQL性能测评
- 1. 测试环境介绍
- 2. 测试环境搭建
- 3. 测试工具
- 3.1. mysqlslap
- 3.2. sysbench
1. 测试环境介绍
随着云计算时代的进一步深入,越来越多的中小企业企业与开发者需要一款简单易用、高能高效的云计算基础设施产品来支撑自身业务运营和创新开发。基于这种需求,华为云焕新推出华为云云服务器实例新品。
华为云云服务器具有智能不卡顿、价优随心用、上手更简单、管理特省心这四个优点,从而帮您快速上云。
本文将使用华为云云耀云服务器L实例针对MySQL服务做一个性能基准测试。
购买方式:官方渠道链接-华为云耀云服务器L实例
2. 测试环境搭建
型号 | 实例操作系统系统 | CPU | 内存 | 硬盘 | MySQL版本 |
---|---|---|---|---|---|
云耀云服务器L实例 | Huawei Cloud EulerOS 2.0 | 2核 | 2G | 系统盘 40 GiB | MySQL8.0.33 |
操作系统选择:Huawei Cloud EulerOS
(简称HCE OS),是基于华为开源社区openEuler构建的Linux操作系统,提供云原生、高性能、安全稳定的执行环境来开发和运行应用程序,助力企业客户快速上云及开发者创新。
MySQL的性能指标主要有:
● TPS
:Transactions Per Second
,即数据库每秒执行的事务数,以commit
成功次数为准。
● QPS
:Queries Per Second
,即数据库每秒执行的SQL
数(含 insert、select、update、delete 等)。
● RT
:Response Time
,响应时间。包括平均响应时间、最小响应时间、最大响应时间、每个响应时间的查询占比。需要重点关注的是前95-99%的最大响应时间,因为它决定了大多数情况下的短板。
● Concurrency Threads
:并发量,每秒可处理的查询请求的数量。
本次性能测试主要关注吞吐量和延时两个指标
在Huawei Cloud EulerOS
操作系统中安装部署MySQL 8.0.3
:
[root@hcss-ecs-3501 ~]# yum install -y gcc-c++ openssl openssl-devel make bison ncurses-devel
[root@hcss-ecs-3501 ~]# yum install -y libtirpc libtirpc-devel rpcgen m4
[root@hcss-ecs-3501 ~]# tar xvf cmake-3.25.3.tar.gz
[root@hcss-ecs-3501 ~]# cd cmake-3.25.3
[root@hcss-ecs-3501 ~]# ./bootstrap
[root@hcss-ecs-3501 ~]# make && make install
[root@hcss-ecs-3501 ~]# ln -s /usr/local/bin/cmake /usr/bin/
[root@hcss-ecs-3501 ~]# cmake --version
cmake version 3.25.3
[root@hcss-ecs-3501 ~]# tar xvf boost_1_77_0.tar.gz
[root@hcss-ecs-3501 ~]# cd boost_1_77_0
[root@hcss-ecs-3501 boost_1_77_0]# ./bootstrap.sh --prefix=/usr/local/
[root@hcss-ecs-3501 boost_1_77_0]# ./b2 install[root@hcss-ecs-3501 ~]# tar xvf mysql-8.0.33.tar.gz
[root@hcss-ecs-3501 ~]# cd mysql-8.0.33
[root@hcss-ecs-3501 mysql-8.0.33]# mkdir build
[root@hcss-ecs-3501 mysql-8.0.33]# cd build/
[root@hcss-ecs-3501 mysql-8.0.33]# cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/var/lib/mysql \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost[root@hcss-ecs-3501 mysql-8.0.33]# make && make install
配置MySQL:
[root@hcss-ecs-3501 ~]# groupadd mysql
[root@hcss-ecs-3501 ~]# useradd -r -g mysql -s /bin/false mysql
[root@hcss-ecs-3501 ~]# cd /usr/local/mysql
[root@hcss-ecs-3501 mysql]# chown -R mysql:mysql .
[root@hcss-ecs-3501 mysql]# bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql
设置MySQL开机自启动:
[root@hcss-ecs-3501 mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@hcss-ecs-3501 mysql]# chkconfig --add mysql
[root@hcss-ecs-3501 mysql]# chkconfig mysql on
cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
log-error=/var/lib/mysql/mysql.log
pid-file=/var/lib/mysql/mysql.pid
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections=1024 # 设置最大连接数
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]
log-error=/var/lib/mysql/mysql.log
pid-file=/var/lib/mysql/mysql.pid
socket=/tmp/mysql.sock
进行安全性配置:
/usr/local/mysql/bin/mysql_secure_installation
ln -s /usr/local/mysql/bin/mysqlslap /usr/bin/
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql -u root -p
Enter password: # 查看最大连接数
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1024 |
+-----------------+-------+
1 row in set (0.01 sec)
操作系统没有做优化配置,使用的默认配置。针对MySQL的最大连接数进行了更改。
3. 测试工具
3.1. mysqlslap
mysqlslap是MySQL官方所提供,并且提供多种引擎的性能测试,相比sysbench来说,mysqlslap的测试过程还是比较简洁的,一个命令,即可完成整个过程
mysqlslap \
--defaults-file=/etc/my.cnf \
--concurrency=100,1000 \
--iterations=3 \
--number-int-cols=20 \
--number-char-cols=30 \
--auto-generate-sql \
--auto-generate-sql-add-autoincrement \
--auto-generate-sql-load-type=mixed \
--engine=innodb \
--number-of-queries=10000 \
--create-schema=mydb \
-uroot \
-p123456
模拟测试两次读写并发,第一次100,第二次1000,测试表包含20个init字段,30个char字段,每次执行10000查询请求。测试引擎是innodb。
● --concurrency
:并发量,也就是模拟多少个客户端同时执行命令。可指定多个值,以逗号或者--delimiter
参数指定的值做为分隔符。
● --iterations
:测试执行的迭代次数。
● --number-int-cols
:自动生成的测试表中包含多少个数字类型的列,默认1 。
● --number-char-cols
:自动生成的测试表中包含多少个字符类型的列,默认1 。
●--auto-generate-sql
:自动生成测试表和数据。这个命令,带来的效果,就类似sysbench
命令的prepare
指令。
●--auto-generate-sql-add-autoincrement
:增加auto_increment
一列
如果想看,生成的具体脚本,可以用 –only-print
指令,只打印测试语句而不实际执行。
●--engine
:创建测试表所使用的存储引擎,可指定多个。
●--number-of-queries
:总的测试查询次数(并发客户数×每客户查询次数)。
●--create-schema
:测试的schema
,MySQL中schema
也就是database
数据库名(并不会真的生成一个库)。
●-uroot -p123456
:设置 MySQL账号和密码。
mysqlslap: [Warning] Using a password on the command line interface can be insecure.
BenchmarkRunning for engine innodbAverage number of seconds to run all queries: 1.863 secondsMinimum number of seconds to run all queries: 1.777 secondsMaximum number of seconds to run all queries: 1.945 secondsNumber of clients running queries: 100Average number of queries per client: 100BenchmarkRunning for engine innodbAverage number of seconds to run all queries: 2.160 secondsMinimum number of seconds to run all queries: 2.077 secondsMaximum number of seconds to run all queries: 2.223 secondsNumber of clients running queries: 1000Average number of queries per client: 10
测试结果说明:
Innodb第一次100客户端同时发起增查用1.863/s,第二次1000客户端同时发起增查用2.160/s
3.2. sysbench
sysbench主要用于评估测试各种不同系统参数下的数据库负载情况。OLTP基准测试需要通过/usr/share/sysbench/
目录中的Lua脚本执行,例如oltp_read_only.lua
脚本执行只读测试。
sysbench还可以通过运行命令时指定自己的Lua脚本来自定义测试
安装工具:
[root@hcss-ecs-3501 ~]# yum install m4 autoconf automake libtool -y[root@hcss-ecs-3501 ~]# find / -name 'libmysqlclient*'
/root/mysql-8.0.33/packaging/deb-in/libmysqlclient-dev.lintian-overrides.in
/root/mysql-8.0.33/packaging/deb-in/libmysqlclient21.install.in
/root/mysql-8.0.33/packaging/deb-in/libmysqlclient21-dbgsym.install.in
/root/mysql-8.0.33/packaging/deb-in/libmysqlclient-dev.install.in
/root/mysql-8.0.33/packaging/deb-in/libmysqlclient21.lintian-overrides.in
/root/mysql-8.0.33/build/library_output_directory/libmysqlclient.so.21
/root/mysql-8.0.33/build/library_output_directory/libmysqlclient.so
/root/mysql-8.0.33/build/library_output_directory/libmysqlclient.so.21.2.33
/root/mysql-8.0.33/build/archive_output_directory/libmysqlclient.a
/usr/local/mysql/lib/libmysqlclient.a
/usr/local/mysql/lib/libmysqlclient.so.21
/usr/local/mysql/lib/libmysqlclient.so
/usr/local/mysql/lib/libmysqlclient.so.21.2.33[root@hcss-ecs-3501 ~]# ln -s /usr/local/mysql/lib/libmysqlclient.so.21 /usr/local/lib/libmysqlclient.so.20
[root@hcss-ecs-3501 ~]# echo /usr/local/lib >> /etc/ld.so.conf
[root@hcss-ecs-3501 ~]# /sbin/ldconfig -v
[root@hcss-ecs-3501 ~]# tar xvf sysbench-1.0.20.tar.gz
[root@hcss-ecs-3501 ~]# cd sysbench-1.0.20
[root@hcss-ecs-3501 sysbench-1.0.20]# ./autogen.sh
[root@hcss-ecs-3501 sysbench-1.0.20]# ./configure
[root@hcss-ecs-3501 sysbench-1.0.20]# make -j
[root@hcss-ecs-3501 sysbench-1.0.20]# make install
[root@hcss-ecs-3501 sysbench-1.0.20]# sysbench --version
sysbench 1.0.20
查看sysbench自带的lua脚本使用方法:
sysbench /usr/local/share/sysbench/oltp_common.lua help
准备数据(prepare):
mysql> select user,host,password from mysql.user;
mysql> alter user root@'%' identified with mysql_native_password by '123456';
mysql> flush privileges;
mysql> create database sbtest;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sbtest |
| sys |
+--------------------+
[root@hcss-ecs-3501 ~]# sysbench \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password='123456' \
/usr/local/share/sysbench/oltp_common.lua \
--db-driver=mysql \
--report-interval=5 \
--time=300 \
--mysql-db=sbtest \
--table-size=100000 \
--tables=10 \
preparesysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Creating table 'sbtest1'...
Inserting 100000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 100000 records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 100000 records into 'sbtest3'
Creating a secondary index on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 100000 records into 'sbtest4'
Creating a secondary index on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 100000 records into 'sbtest5'
Creating a secondary index on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 100000 records into 'sbtest6'
Creating a secondary index on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 100000 records into 'sbtest7'
Creating a secondary index on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest8'
Creating a secondary index on 'sbtest8'...
Creating table 'sbtest9'...
Inserting 100000 records into 'sbtest9'
Creating a secondary index on 'sbtest9'...
Creating table 'sbtest10'...
Inserting 100000 records into 'sbtest10'
Creating a secondary index on 'sbtest10'...
● oltp_common.lua
:执行的测试脚本。因为使用yum进行安装,所以需要到/usr/share/sysbench/
目录下,看到sysbench
自带的lua测试脚本。
● --time
:最大的总执行时间,以秒为单位,默认为 10 秒
● --events
:最大允许的事件个数,默认为0个,应该和--time
互相形成最大的执行时间与次数
MySQL 相关参数:
● --mysql-host
:MySQL server host
● --mysql-port
:MySQL server port
● --mysql-user
:MySQL server 账号
● --mysql-password
:MySQL server 密码
● --mysql-db
:MySQL Server 数据库名
● --table-size
:表记录条数
● --tables
:表名
● --threads
:要使用的线程数,默认 1 个
● --report-interval
:以秒为单位定期报告具有指定间隔的中间统计信息,默认为 0 ,表示禁用中间报告
● prepare
:执行准备数据。
确认测试数据以存在:
[root@hcss-ecs-3501 ~]# mysql -u root -p123456 sbtest;
mysql> show tables;
+------------------+
| Tables_in_sbtest |
+------------------+
| sbtest1 |
| sbtest10 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
| sbtest5 |
| sbtest6 |
| sbtest7 |
| sbtest8 |
| sbtest9 |
+------------------+
10 rows in set (0.00 sec)
随机选择一个表,确认其有100000条数据:
mysql> select count(*) from sbtest1;
+----------+
| count(*) |
+----------+
| 100000 |
+----------+
1 row in set (0.08 sec)
执行测试(run):
● oltp_read_write.lua
:执行的测试脚本,在/usr/share/sysbench/
下。该脚本表示混合读写,在一个事务中,默认比例是:select:update_key:update_non_key:delete:insert = 14:1:1:1:1
。这也是为什么我们测试出来的TPS和QPS的比例大概在1:20左右。相当于一个事务中有18个读写操作
● run
:执行测试。
[root@hcss-ecs-3501 ~]# sysbench \
--time=300 \
--mysql-host=localhost \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=123456 \
/usr/local/share/sysbench/oltp_read_write.lua \
--mysql-db=sbtest \
--tables=10 \
--table_size=100000 \
--report-interval=5 \
runsysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)Running the test with following options:
Number of threads: 1
Report intermediate results every 5 second(s)
Initializing random number generator from current timeInitializing worker threads...Threads started!
# 以下是每5秒返回一次的结果,统计的指标包括:
# 线程数、tps(每秒事务数)、qps(每秒查询数)、每秒的读/写/其它次数、延迟、每秒错误数、每秒重连次数[ 5s ] thds: 1 tps: 110.56 qps: 2214.86 (r/w/o: 1550.68/442.85/221.33) lat (ms,95%): 15.27 err/s: 0.00 reconn/s: 0.00
[ 10s ] thds: 1 tps: 142.00 qps: 2840.27 (r/w/o: 1988.05/568.21/284.01) lat (ms,95%): 9.73 err/s: 0.00 reconn/s: 0.00
[ 15s ] thds: 1 tps: 148.60 qps: 2972.01 (r/w/o: 2080.41/594.40/297.20) lat (ms,95%): 9.39 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 1 tps: 154.20 qps: 3083.99 (r/w/o: 2158.79/616.80/308.40) lat (ms,95%): 8.74 err/s: 0.00 reconn/s: 0.00
......
[ 290s ] thds: 1 tps: 157.80 qps: 3155.23 (r/w/o: 2209.22/630.41/315.60) lat (ms,95%): 8.74 err/s: 0.00 reconn/s: 0.00
[ 295s ] thds: 1 tps: 156.60 qps: 3129.37 (r/w/o: 2189.78/626.39/313.20) lat (ms,95%): 8.74 err/s: 0.00 reconn/s: 0.00
[ 300s ] thds: 1 tps: 157.00 qps: 3143.33 (r/w/o: 2200.55/628.79/313.99) lat (ms,95%): 8.43 err/s: 0.00 reconn/s: 0.00
SQL statistics:queries performed:read: 661290 # 执行的读操作数量 write: 188940 # 执行的写操作数量other: 94470 # 执行的其它操作数量total: 944700transactions: 47235 (157.45 per sec.) # 执行事务的平均速率queries: 944700 (3148.96 per sec.) # 平均每秒能执行多少次查询ignored errors: 0 (0.00 per sec.)reconnects: 0 (0.00 per sec.)General statistics:total time: 300.0028s # 总消耗时间total number of events: 47235 # 总请求数量(读、写、其它)Latency (ms):min: 3.92avg: 6.35max: 163.5595th percentile: 8.58 # 采样计算的平均延迟sum: 299879.21Threads fairness:events (avg/stddev): 47235.0000/0.00execution time (avg/stddev): 299.8792/0.00
测试结果说明:
157 TPS+3148 QPS+8.58ms延迟
清理数据(clean):
sysbench \
--time=300 \
--mysql-host=localhost \
--mysql-port=3306 \
--mysql-user=root \
--mysql-password=123456 \
/usr/local/share/sysbench/oltp_read_write.lua \
--mysql-db=sbtest \
--tables=10 \
--table_size=100000 \
--report-interval=5 \
cleanupsysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)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'...
结论:针对华为云云耀云服务器L实例2核2G的配置,使用mysqlslap工具的情况下,100客户端同时发起增查用1.863/s,1000客户端同时发起增查用2.160/s。使用sysbench工具的情况下,10张表,每张表100000条记录,测试结果是157 TPS+3148 QPS+8.58ms延迟。可基本满足中小企业的数据库性能要求。