SQL审计日志性能测试
测试场景
本章节对比不同模式(只写、只读、读写混合)下开启SQL审计日志和关闭审计日志性能差异。
测试环境
TaurusDB测试环境如下:
- 区域:华北-北京四。
- 可用区类型:多可用区。
- 实例类型:一主一只读集群实例。
- 实例规格:16U64G 规格。
- 弹性云服务器(Elastic Cloud Server,简称ECS):ECS与数据库节点在同一个可用区,规格建议选择通用计算增强型c9 | c9.4xlarge.2 | 16vCPUs | 32GB。由于压测工具需要安装额外的编译工具,建议ECS绑定弹性IP。
测试工具
| 工具名称 | 描述及下载方式 | 版本号 |
|---|---|---|
| Sysbench | Sysbench是一款基于LuaJIT开发的模块化多线程基准测试工具,广泛应用于数据库性能测试。通过内置的数据库测试模型,采用多线程并发操作来评估数据库的性能,请单击此处了解Sysbench更多详情。 | Sysbench版本1.0.18 |
具体的安装命令如下:
- 登录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
- 执行以下命令,解压安装包。
unzip 1.0.18
- 执行以下命令,执行安装命令。
cd sysbench-1.0.18 ./autogen.sh ./configure make make install
- 执行命令,查看sysbench版本。
sysbench --version
回显结果:
sysbench 1.0.17
测试指标
- TPS:Transaction Per Second,数据库每秒执行的事务数。
- QPS:Query Per Second,数据库每秒执行的SQL语句数,包含insert、select、update、delete等。
测试步骤
- 以下测试均在ECS上执行,请根据实际信息,替换线程并发数、连接IP、连接端口、用户名称与用户密码。
- 性能测试数据(包含SQL语句)都由Sysbench工具自动生成。
- 为了使sysbench 在大并发场景(512, 1000)正常运行,需要将参数max_prepared_stmt_count 调大,建议改为 1048576(过多的prepare语句会占用大量内存空间进而导致OOM,4U16G规格该值建议设置为400000)。
修改参数的详细步骤请参见修改TaurusDB实例参数。
- 导入数据。
- 执行以下命令,创建测试数据库sbtest。
mysql -u user -P port -h host -p -e "create database sbtest"
- 执行以下命令,将测试背景数据导入至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
- 执行以下命令,确认数据已导入完成。
mysql -u user -P port -h host -p -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'sbtest';select count(*) from sbtest.sbtest1"
回显结果如下:
+----------+ | COUNT(*) | +----------+ | 250 | +----------+ +----------+ | COUNT(*) | +----------+ | 25000 | +----------+
- 执行以下命令,创建测试数据库sbtest。
- 执行以下命令,测试性能。测试过程将持续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
- 执行以下命令,清理数据。
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
- 导入数据。
- 执行以下命令,创建测试数据库sbtest。
mysql -u user -P port -h host -p -e "create database sbtest"
- 执行以下命令,将测试背景数据导入至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
- 执行以下命令,确认数据已导入完成。
mysql -u user -P port -h host -p -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'sbtest';select count(*) from sbtest.sbtest1"
回显结果如下:
+----------+ | COUNT(*) | +----------+ | 250 | +----------+ +----------+ | COUNT(*) | +----------+ | 25000 | +----------+
- 执行以下命令,创建测试数据库sbtest。
- 执行以下命令,测试纯读性能,测试过程将持续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
- 执行以下命令,清理数据。
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
- 导入数据。
- 执行以下命令,创建测试数据库sbtest。
mysql -u user -P port -h host -p -e "create database sbtest"
- 执行以下命令,将测试背景数据导入至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
- 执行以下命令,确认数据已导入完成。
mysql -u user -P port -h host -p -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'sbtest';select count(*) from sbtest.sbtest1"
回显结果如下:
+----------+ | COUNT(*) | +----------+ | 250 | +----------+ +----------+ | COUNT(*) | +----------+ | 25000 | +----------+
- 执行以下命令,创建测试数据库sbtest。
- 执行以下命令,测试读写混合性能,测试过程将持续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_read_write run
- 执行以下命令,清理数据。
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
性能数据
统一使用250张表,每表包含25,000行数据,并针对不同的并发数进行测试。当并发数超过128后,CPU将达到瓶颈。
受系统正常性能波动影响,开启审计功能后的实测性能出现小幅性能提升属于正常波动,不代表审计功能本身带来性能优化。
读写模式测试数据
| 模式 | 表数量 | 单表数据量(行) | 并发数 | 开启SQL审计打开全部选项 | 不开启SQL审计 | 开启全部选项TPS vs 不开启审计TPS | ||
|---|---|---|---|---|---|---|---|---|
| TPS | QPS | TPS | QPS | |||||
| 读写 | 250 | 25000 | 4 | 913.04 | 18260.73 | 910.64 | 18212.79 | 0.26% |
| 8 | 1765.4 | 35307.94 | 1744 | 34879.95 | 1.23% | |||
| 16 | 3305.48 | 66109.59 | 3356.91 | 67138.11 | -1.53% | |||
| 32 | 6000.85 | 120017.01 | 5995.85 | 119916.94 | 0.08% | |||
| 64 | 10225.39 | 204507.89 | 10628.06 | 212561.11 | -3.79% | |||
| 128 | 11777.69 | 235553.71 | 12977.15 | 259542.96 | -9.24% | |||
只读模式测试数据
| 模式 | 表数量 | 单表数据量(行) | 并发数 | 开启SQL审计打开全部选项 | 不开启SQL审计 | 开启全部选项TPS vs 不开启审计TPS | ||
|---|---|---|---|---|---|---|---|---|
| TPS | QPS | TPS | QPS | |||||
| 只读 | 250 | 25000 | 4 | 1579.87 | 25277.86 | 1547.11 | 24753.78 | 2.12% |
| 8 | 3105.53 | 49688.47 | 3050.89 | 48814.18 | 1.79% | |||
| 16 | 5910.93 | 94574.84 | 5993.17 | 95890.71 | -1.37% | |||
| 32 | 10690.48 | 171047.72 | 10470.22 | 167523.58 | 2.10% | |||
| 64 | 14473.59 | 231577.48 | 14761.66 | 236186.64 | -1.95% | |||
| 128 | 16463.74 | 263419.86 | 18041.48 | 288663.68 | -8.75% | |||
只写模式测试数据
| 模式 | 表数量 | 单表数据量(行) | 并发数 | 开启SQL审计打开全部选项 | 不开启SQL审计 | 开启全部选项TPS vs 不开启审计TPS | ||
|---|---|---|---|---|---|---|---|---|
| TPS | QPS | TPS | QPS | |||||
| 只写 | 250 | 25000 | 4 | 1976.92 | 11861.5 | 1974.09 | 11844.55 | 0.14% |
| 8 | 3896.66 | 23379.98 | 3843.34 | 23060.07 | 1.39% | |||
| 16 | 7347.01 | 44082.04 | 7135.42 | 42812.54 | 2.97% | |||
| 32 | 12909.03 | 77454.18 | 12617.28 | 75703.7 | 2.31% | |||
| 64 | 22512.82 | 135076.9 | 22915.74 | 137494.43 | -1.76% | |||
| 128 | 39818.79 | 238912.72 | 41480.33 | 248881.96 | -4.01% | |||