1 环境准备
1.1 安装相关依赖
BenchmarkSQL 是基于 Java 开发的,因此需要安装 Java 运行环境(JRE)或 Java 开发工具包(JDK),推荐最新的Java21版本。同时,还需要安装 ant 构建工具。
--选择合适的Java版本
yum install -y java-21-openjdk ant
2 安装BenchmarkSQL
2.1 解压
将安装包上传至服务器,解压即可
unzip benchmarksql-5.0.zip
cd benchmarksql-5.0
编译
cd benchmarksql-5.0
ant

2.2 替换驱动
根据你要压测的数据库,选择合适的JDBC驱动,这里以VastbaseG100为例
--替换为实际的路径
cd benchmarksql-5.0/lib/postgres
mv postgresql-9.3-1102.jdbc41.jar postgresql-9.3-1102.jdbc41.jar.bak
mv /xxx/JDBC-VB_P-2.10-2024091118.jar .
2.3 创建测试用户和测试库
在 PostgreSQL 数据库中创建一个用于测试的用户和数据库
CREATE USER benchmarksql WITH ENCRYPTED PASSWORD 'benchmarksql';
CREATE DATABASE benchmarksql OWNER benchmarksql;
GRANT create,usage on schema public to benchmarksql;
3 使用BenchmarkSQL
3.1 配置BenchmarkSQL
编辑 run/props.pg 文件,根据你的 PostgreSQL 数据库配置进行修改
# 数据库类型
db=postgres
# 数据库驱动
driver=org.postgresql.Driver
# 数据库连接字符串
conn=jdbc:postgresql://localhost:5432/benchmarksql
# 数据库用户名
user=benchmarksql
# 数据库密码
password=benchmarksql
# 仓库数量
warehouses=50
# 加载数据时的线程数
loadWorkers=10
# 并发终端数
terminals=8
# 每个终端运行的事务数量
runTxnsPerTerminal=0
# 运行时间(分钟)
runMins=5
# 每分钟事务数量限制(0 表示不限制)
limitTxnsPerMin=0
# 是否固定每个终端的仓库
terminalWarehouseFixed=true
//The following five values must add up to 100
//The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4
// Directory name to create for collecting detailed result data.
// Comment this out to suppress.
resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
osCollectorScript=./misc/os_collector_linux.py
osCollectorInterval=1
//osCollectorSSHAddr=user@dbhost
//根据实际修改网卡名和设备名
osCollectorDevices=net_ens33 blk_sda
一些重要参数:
- 并发数(terminals)
- 仓库数量(warehouses)
- 压测时间(runMins)
3.2 构建测试数据库
运行以下命令来构建测试数据库
./runDatabaseBuild.sh props.pg

3.3 执行压力测试
运行以下命令来运行压力测试
./runBenchmark.sh props.pg
测试完成后,BenchmarkSQL 会生成详细的测试结果,包括吞吐量(TPM)、响应时间等指标

压测完成之后,会生成my_result_xxxx文件
3.4 分析压测结果
使用generateGraphs.sh和generateReport.sh分析BenchmarkSQL生成的my_result文件
在使用generateReport.sh脚本之前,需要确保操作系统环境中已经安装了R语言
yum install -y R
--生成一系列的图形文件
./generateGraphs.sh my_result_时间戳/
--生成测试报告
./generateReport.sh my_result_时间戳/

报告中包含了:运行的配置信息、测试结果的概要信息、每分钟事务数和事务延迟、系统资源的使用情况
3.5 删除测试库
运行以下命令来删除测试库
./runDatabaseDestroy.sh props.pg

4 常见报错
4.1
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: ExecJDBC has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
问题原因:当前环境的java版本太低
查看当前Java版本
java -version
用yum安装新版本的Java
--查看可用的Java包
yum list available | grep openjdk
安装对应版本的Java环境
yum install -y xxxx
使用alternative命令管理Java版本:
--替换实际路径,2表示的是优先级
alternatives --install /usr/bin/java java /usr/local/java/jdk-17.0.3.1/bin/java 2
设置默认Java版本
alternatives --config java
输入对应的数字选择对应的Java作为默认版本
验证默认版本
java -version
4.2
[main] ERROR OSCollector : OSCollector Cannot run program "python": error=2, No such file or directory
java.io.IOException: Cannot run program "python": error=2, No such file or directory
Python没有安装在您的系统上,或者Python的可执行文件不在系统的PATH环境变量中
yum install python python3
Comments NOTHING