使用BenchmarkSQL与pgbench来测试PostgreSQL集群的最大性能。
TPC-C是一种针对在线事务处理(OTLP)系统的性能测试基准。它具有多种事务处理场景以及复杂的执行结构,通过多种类型和复杂性的并发事务混合测试,来评估数据库的性能指标。TPC-C以每分钟事务数(tpmC)来作为衡量数据库性能的指标 TPC-B通过系统每秒处理的并发事务数TPS,Transactions per Second),来作为衡量数据库性能的指标
测试环境准备:
对应云环境测试:保证数据库和虚拟机实例在同一个可用区内 虚拟机规格:(64核256GB) 虚拟机存储规格:SSD 500GB 网络类型:转悠网络,在同一个VPC内 操作系统:centos,ubuntu均可以
测试指标
tpmC: 数据库每分钟处理事务数 TPS: 数据库每秒钟处理的并发事务数
部署测试工具
安装测试工具:https://sourceforge.net/projects/benchmarksql/files/latest/download/ 下载安装包后
编译BenchmarkSQL
# 安装ant
yum install ant
# 解压
unzip benchmarksql-5.0.zip;
cd benchmarksql-5.0;
ant;复制
如果编译报错则安装依赖
yum install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-
复制
测试步骤
编写测试文件
vim benchmarksql-5.0/run/PolarDB-warehouse2000.conf
db=postgres
driver=org.postgresql.Driver
conn=jdbc:postgresql://localhost:5432/tpcc
user=polar
password=polar
warehouses=2000
loadWorkers=128
terminals=256
// To run specified transactions per terminal- runMins must equal zero
runTxnsPerTerminal=0
// To run for specified minutes- runTxnsPerTerminal must equal zero
runMins=15
// Number of total transactions per minute
limitTxnsPerMin=100000000
terminalWarehouseFixed=true
// Set to true to use the stored procedure/function implementations.
useStoredProcedures=true
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4复制
替换对应数据
conn=jdbc:postgresql:// : / , 、 、 换成压测数据库实际值 user、password 用户名、密码,换成压测数据库实际值 warehouses 压测数据量 warehouses=2000,大概有200GB数据 terminals 压测并发数量,一般设置为 规格cpu * 8; runMins 压测运行时间 loadWorkers 导数据阶段,并发数量,不用改变 limitTxnsPerMin 压测端限制tpmC 上限,不用改变 terminalWarehouseFixed=true 不用改变 useStoredProcedures=true 使用Procedures,性能更好,不用改变
数据导入
每一轮压测前,都需要重新导一遍数据。随着压测进行,数据量会急剧增大,性能会降低 数据导入步骤
cd benchmarksql-5.0/run
./runDatabaseBuild.sh PolarDB-warehouse2000.conf复制
导数据时间比较长,导完数据后,可以备份数据,后续压测可以直接从备份数据恢复出数据,节省导数据时间 导完数据后,tpcc库包含待压测数据,创建tpcc_backup库,作为备份;登陆数据库操作:
psql> \c postgres;
psql> CREATE DATABASE tpcc_backup WITH TEMPLATE tpcc;复制
使用备份恢复待压测数据
psql> \c postgres;
psql> drop database tpcc;
psql> CREATE DATABASE tpcc WITH TEMPLATE tpcc_backup;复制
数据压测预热
创建文件:benchmarksql-5.0/run/PolarDB-warehouse2000.warmup.conf。配置与 PolarDB-warehouse2000.warmup.conf 一致,差别是 runMins 改为 5分钟。执行压测预热
#_JAVA_OPTIONS 是减少压测客户端运行是java GC对结果的影响;
env _JAVA_OPTIONS="-Xms128g -Xmx128g -Xmn64g -XX:MaxMetaspaceSize=8g"
./runBenchmark.sh PolarDB-warehouse2000.warmup.conf复制
配置文件如下
db=postgres
driver=org.postgresql.Driver
conn=jdbc:postgresql://localhost:5432/tpcc
user=polar
password=polar
warehouses=1000
loadWorkers=128
terminals=256
// To run specified transactions per terminal- runMins must equal zero
runTxnsPerTerminal=0
// To run for specified minutes- runTxnsPerTerminal must equal zero
runMins=5
// Number of total transactions per minute
limitTxnsPerMin=100000000
terminalWarehouseFixed=true
// Set to true to use the stored procedure/function implementations.
useStoredProcedures=true复制
执行压测
cd benchmarksql-5.0/run
#_JAVA_OPTIONS 是减少压测客户端运行是java GC对结果的影响;
e
./runBenchmark.sh PolarDB-warehouse2000.conf复制
删除压测数据
cd benchmarksql-5.0/run
./runDatabaseDestroy.sh PolarDB-warehouse2000.conf复制
Postgresql TPC-B 性能测试
使用PostgreSQL数据库自带的一款轻量级压力测试工具pgbench,来进行TPC-B性能基准测试
安装测试攻击
安装postgresql 11
# azmonlinux
yum install postgresql-contrib
# ubuntu
apt-get install postgresql-contrib
# centos
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7.8-x86_64/postgresql11-11.11-1PGDG.rhel7.x86_64.rpm复制
配置环境变量
export PGHOST=<PolarDB集群地址的私网地址>
export PGPORT=<PolarDB集群地址的私网端口>
export PGDATABASE=postgres
export PGUSER=<PolarDB数据库用户名>
export PGPASSWORD=<PolarDB对应用户的密码>复制
数据导入
pgbench -i -s 20000
复制
执行压测
pgbench -M prepared -r -c128 -j24 -P1 -T 600
复制
文章转载自耶喝运维,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。