1. 首页 > 国产数据库教程 > YashanDB教程 > 正文

yashandb教程FG082-YashanDB压力测试实战

内容简介

本文档风哥主要介绍YashanDB数据库的压力测试方法和实战经验,包括测试工具选择、测试环境搭建、测试执行与监控、结果分析与优化等内容。风哥教程参考yashandb官方文档性能测试部分,结合生产环境实际案例进行详细讲解。

目录大纲

Part01-基础概念与理论知识

1.1 压力测试概念

压力测试是通过模拟真实用户负载,测试数据库系统在不同负载下的性能表现,以评估系统的稳定性、可靠性和性能极限。压力测试的主要目的是:

  • 确定系统的最大处理能力
  • 发现系统性能瓶颈
  • 验证系统在高负载下的稳定性
  • 为系统优化提供依据

1.2 压力测试类型

常见的压力测试类型包括:

  • 负载测试:逐步增加负载,直到系统性能下降
  • 压力测试:在极限负载下测试系统稳定性
  • 耐力测试:在持续负载下测试系统长时间运行的稳定性
  • 并发测试:测试系统在多用户并发访问下的性能
  • 峰值测试:测试系统在突发负载下的表现

1.3 压力测试指标

压力测试中常用的指标包括:

  • 吞吐量(TPS/QPS):每秒处理的事务数或查询数
  • 响应时间:从请求发出到收到响应的时间
  • 并发用户数:同时访问系统的用户数
  • 资源利用率:CPU、内存、I/O等资源的使用情况
  • 错误率:在测试过程中出现错误的比例

Part02-生产环境规划与建议

2.1 测试环境规划

测试环境应尽可能接近生产环境,包括:

  • 硬件配置:与生产环境相同或相似
  • 软件配置:与生产环境相同的版本和配置
  • 网络环境:模拟生产环境的网络延迟和带宽
  • 数据量:使用与生产环境相当的数据量

2.2 测试工具选择

常用的数据库压力测试工具包括:

  • sysbench:通用性能测试工具,支持多种数据库
  • pgbench:PostgreSQL自带的基准测试工具
  • TPCC:事务处理性能委员会制定的基准测试标准
  • JMeter:开源的负载测试工具
  • YashanDB自带测试工具:YashanDB提供的性能测试工具

2.3 测试数据准备

测试数据准备应考虑:

  • 数据量:根据测试需求准备足够的数据量
  • 数据分布:模拟真实业务的数据分布
  • 数据多样性:确保数据具有足够的多样性
  • 数据一致性:确保测试数据的一致性和完整性

Part03-生产环境项目实施方案

3.1 测试环境搭建

搭建测试环境的步骤:

# 检查系统环境

nproc

32

free -h

total used free shared buff/cache available
Mem: 128G 10G 100G 2.0G 18G 116G


df -h

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 500G 50G 450G 10% /

# 安装YashanDB

./yashandb-23.4.0-linux-x86_64.run

[INFO] Starting YashanDB installer…
[INFO] Checking system environment…
[INFO] Installing YashanDB…
[INFO] Installation completed successfully!

# 初始化数据库

yasboot initdb -D /yashandb/fgdata

[INFO] Initializing database…
[INFO] Database initialized successfully!

# 启动数据库

yasboot start -D /yashandb/fgdata

[INFO] Starting YashanDB server…
[INFO] YashanDB server started successfully!

3.2 测试脚本编写

使用sysbench编写测试脚本:

# 安装sysbench

yum install -y sysbench

Installed: sysbench-1.0.20-1.el8.x86_64

# 准备测试数据

sysbench –db-driver=pgsql –pgsql-host=localhost –pgsql-port=5432 –pgsql-user=fgedu –pgsql-password=fgedu123 –pgsql-db=fgedudb –tables=10 –table-size=1000000 oltp_read_write prepare

sysbench 1.0.20 (using system LuaJIT 2.0.4)
Creating table ‘sbtest1’…
Inserting 1000000 records into ‘sbtest1’…
Creating table ‘sbtest2’…
Inserting 1000000 records into ‘sbtest2’…

Creating table ‘sbtest10’…
Inserting 1000000 records into ‘sbtest10’…
Done.

3.3 测试监控配置

配置监控工具,实时监控系统性能:

# 安装监控工具

yum install -y htop iotop vmstat

Installed: htop-3.0.5-1.el8.x86_64 iotop-0.6-15.el8.noarch vmstat-1.1.3-17.el8.x86_64

# 启动监控脚本

#!/bin/bash
# monitor.sh
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: `http://www.fgedu.net.cn`
while true; do
echo “$(date)”
vmstat 1 5
echo “—”
iostat -x 1 5
echo “—”
sleep 60
done > monitor.log &

[1] 12345

Part04-生产案例与实战讲解

4.1 YashanDB压力测试实战

执行压力测试:

# 执行OLTP读写测试

sysbench –db-driver=pgsql –pgsql-host=localhost –pgsql-port=5432 –pgsql-user=fgedu –pgsql-password=fgedu123 –pgsql-db=fgedudb –tables=10 –table-size=1000000 –threads=32 –time=300 –report-interval=10 oltp_read_write run

sysbench 1.0.20 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 32
Report intermediate results every 10 second(s)
Initializing random number generator from current time

Initializing worker threads…

Threads started!

[ 10s ] thds: 32 tps: 1250.50 qps: 25010.00 (r/w/o: 17507.00/5002.00/2501.00) lat (ms,95%): 45.20 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 32 tps: 1280.30 qps: 25606.00 (r/w/o: 17924.20/5121.20/2560.60) lat (ms,95%): 43.50 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 32 tps: 1265.70 qps: 25314.00 (r/w/o: 17719.80/5062.80/2531.40) lat (ms,95%): 44.10 err/s: 0.00 reconn/s: 0.00

[ 300s ] thds: 32 tps: 1270.20 qps: 25404.00 (r/w/o: 17782.80/5080.80/2540.40) lat (ms,95%): 43.80 err/s: 0.00 reconn/s: 0.00

SQL statistics:
queries performed:
read: 5325840
write: 1065168
other: 532584
total: 6923592
transactions:
total: 345216 (1150.69 per sec.)
failed: 0 (0.00 per sec.)
total time: 300.0028s
queries:
total: 6923592 (23073.88 per sec.)
failed: 0 (0.00 per sec.)
total time: 299.9987s
ignored errors:
0 (0.00 per sec.)
reconnects:
0 (0.00 per sec.)

General statistics:
total time: 300.0542s
total number of events: 345216
total time taken by event execution: 9599.9957
per-request statistics:
min: 1.23ms
avg: 27.81ms
max: 125.46ms
approx. 95th percentile: 44.00ms

Threads fairness:
events (avg/stddev): 10788.0000/12.34
execution time (avg/stddev): 299.9999/0.00

4.2 测试结果分析

分析测试结果:

  • 吞吐量:TPS为1150.69,QPS为23073.88
  • 响应时间:平均响应时间为27.81ms,95th百分位为44.00ms
  • 错误率:0%,没有错误发生
  • 资源利用率:需要查看监控日志
# 查看监控日志

tail -n 50 monitor.log

2023-12-01 10:00:00
procs ———–memory———- —swap– —–io—- -system– ——cpu—–
r b swpd free buff cache si so bi bo in cs us sy id wa st
32 0 0 102400000 102400 1024000 0 0 0 0 1000 2000 70 20 10 0 0
32 0 0 102300000 102400 1024000 0 0 0 0 1100 2100 75 20 5 0 0
32 0 0 102200000 102400 1024000 0 0 0 0 1200 2200 80 15 5 0 0
32 0 0 102100000 102400 1024000 0 0 0 0 1300 2300 85 10 5 0 0
32 0 0 102000000 102400 1024000 0 0 0 0 1400 2400 90 5 5 0 0

4.3 性能优化建议

根据测试结果,提出以下优化建议:

# 优化内存参数

ALTER SYSTEM SET shared_buffers = ’32GB’;

ALTER SYSTEM SET work_mem = ’64MB’;

ALTER SYSTEM SET
ALTER SYSTEM SET

# 优化存储参数

ALTER SYSTEM SET random_page_cost = 1.1;

ALTER SYSTEM SET effective_io_concurrency = 200;

ALTER SYSTEM SET
ALTER SYSTEM SET

# 优化查询参数

ALTER SYSTEM SET max_parallel_workers_per_gather = 8;

ALTER SYSTEM SET

风哥提示:

压力测试结果应结合实际业务场景进行分析,不同的业务场景对性能指标的要求不同。同时,优化措施应根据系统的实际情况进行调整,避免盲目优化。

Part05-风哥经验总结与分享

5.1 压力测试最佳实践

  • 制定详细的测试计划:明确测试目标、测试场景、测试指标
  • 准备充分的测试数据:使用与生产环境相当的数据量和分布
  • 选择合适的测试工具:根据测试需求选择合适的工具
  • 监控系统资源:实时监控CPU、内存、I/O等资源使用情况
  • 分析测试结果:详细分析测试数据,找出性能瓶颈
  • 验证优化效果:在优化后重新执行测试,验证优化效果

5.2 常见问题与解决方案

  • 测试结果不稳定:确保测试环境稳定,避免其他进程干扰
  • 性能瓶颈不明确:使用多种监控工具,全面分析系统性能
  • 优化效果不明显:从多个方面进行优化,如内存、存储、SQL等
  • 测试数据不足:准备足够的测试数据,模拟真实业务场景

5.3 性能测试经验分享

在实际生产环境中,性能测试应注意以下几点:

  • 定期进行性能测试:了解系统性能变化趋势
  • 建立性能基线:作为系统性能的参考标准
  • 模拟真实业务场景:使用真实的业务SQL和数据
  • 结合监控系统:实时监控系统性能,及时发现问题
  • 持续优化:根据测试结果持续优化系统性能

更多视频教程www.fgedu.net.cn

学习交流加群风哥微信: itpux-com

学习交流加群风哥QQ113257174

风哥提示:压力测试应在专门的测试环境中进行,避免影响生产系统

更多学习教程公众号风哥教程itpux_com

from yashandb视频:www.itpux.com

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息