
# 测试方法
#### 测试环境
TaurusDB测试环境如下：
- 区域：华北-北京四。
- 可用区类型：多可用区。
- 测试用云数据库 TaurusDB实例为一主一只读集群。
- 弹性云服务器（Elastic Cloud Server，简称ECS）：ECS与数据库节点在同一个可用区，规格建议选择通用计算增强型 \| c7.8xlarge.4 \| 32vCPUs \| 128GB，操作系统镜像使用CentOS 7.6 64bit位版本。由于压测工具需要安装额外的编译工具，建议ECS绑定弹性IP。
 
#### 测试工具
表1测试工具 
| 工具名称     | 描述及下载方式                                                                                                                                      | 版本号                                                                                    |
|:---|:---|:---|
| Sysbench | Sysbench是一款基于LuaJIT开发的模块化多线程基准测试工具，广泛应用于数据库性能测试。通过内置的数据库测试模型，采用多线程并发操作来评估数据库的性能，请[单击此处](https://github.com/akopytov/sysbench)了解Sysbench更多详情。 | [Sysbench版本](https://codeload.github.com/akopytov/sysbench/zip/refs/tags/1.0.18)1.0.18 |
   
具体的安装命令如下：
1. 登录ECS，执行以下命令，下载sysbench安装包。 
   ```
   wget https://codeload.github.com/akopytov/sysbench/zip/refs/tags/1.0.18
   yum install -y autoconf libtool mysql mysql-devel vim unzip
   ```
   
   
2. 请执行以下命令，解压安装包。 
   ```
   unzip 1.0.18
   ```
   
   
3. 请执行以下命令，执行安装命令。 
   ```
   cd sysbench-1.0.18
   ./autogen.sh
   ./configure
   make
   make install
   ```
   如果您未安装make，运行**make** 命令会报错，需要执行**yum install make**。
   
   
#### 测试步骤
![](https://support.huaweicloud.com/pwp-taurusdb/public_sys-resources/notice_3.0-zh-cn.png)
以下测试均在ECS上执行，请根据实际信息，替换线程并发数、连接IP、连接端口、用户名称与用户密码。
性能测试数据（包含SQL语句）都由sysbench工具自动生成。
压测机ECS与实例在同一可用区。
为了使sysbench 在大并发场景(512, 1000)正常运行，需要将参数 max_prepared_stmt_count 调大，建议改为 1048576（过多的prepare语句会占用大量内存空间进而导致OOM，4U16G规格该值建议设置为400000）。
#### 测试指标
- **TPS**：Transaction Per Second，数据库每秒执行的事务数。
- **QPS**：Query Per Second，数据库每秒执行的SQL语句数，包含insert、select、update、delete等。
 
#### 只写性能测试
1. 导入数据。 
   1. 执行以下命令，创建测试数据库sbtest。
      ```
      mysql -u user -P port -h host -p -e "create database sbtest"
      ```
      
   
   2. 执行以下命令，将测试背景数据导入至sbtest数据库。
      ```
      sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=25000 --tables=250 --threads=thread_num oltp_common prepare
      ```
      
   
   
   
   
2. 执行以下命令，测试性能。测试过程将持续10分钟。 
   ```
   sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=25000 --tables=250 --time=600   --threads=thread_num --percentile=95 --report-interval=1 oltp_write_only run
   ```
   
   
3. 执行以下命令，清理数据。 
   ```
   sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=25000 --tables=250 --threads=thread_num oltp_common cleanup
   ```
   
   
 
#### 只读性能测试
1. 导入数据。 
   1. 执行以下命令，创建测试数据库sbtest。
      ```
      mysql -u user -P port -h host -p -e "create database sbtest"
      ```
      
   
   2. 执行以下命令，将测试背景数据导入至sbtest数据库。
      ```
      sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=25000 --tables=250 --threads=thread_num oltp_common prepare
      ```
      
   
   
   
   
2. 执行以下命令，测试纯读性能，测试过程将持续10分钟。 
   ```
   sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=25000 --tables=250 --time=600  --range_selects=0 --skip-trx=1  --threads=thread_num --percentile=95 --report-interval=1 oltp_read_only run
   ```
   
   
3. 执行以下命令，清理数据。 
   ```
   sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=25000 --tables=250 --threads=thread_num oltp_common cleanup
   ```
   
   
 
#### 读写混合性能测试
1. 导入数据。 
   1. 执行以下命令，创建测试数据库sbtest。
      ```
      mysql -u user -P port -h host -p -e "create database sbtest"
      ```
      
   
   2. 执行以下命令，将测试背景数据导入至sbtest数据库。
      ```
      sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=250000 --tables=25 --threads=thread_num oltp_common prepare
      ```
      
   
   
   
   
2. 执行以下命令，测试读写混合性能，测试过程将持续10分钟。 
   ```
   sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=250000 --tables=25 --time=600   --threads=thread_num --percentile=95 --report-interval=1 oltp_read_write run
   ```
   
   
3. 执行以下命令，清理数据。 
   ```
   sysbench --db-driver=mysql --mysql-host=host --mysql-port=port --mysql-user=user --mysql-password=password --mysql-db=sbtest --table_size=250000 --tables=25 --threads=thread_num oltp_common cleanup
   ```
   
   
 
