使用benchmarksql测试数据库处理能力

我们所处行业的核心应用业务,当前还是传统的OLTP业务,应用系统使用 java 开发,并且不建议使用存储过程,使用 benchmarksql 压测数据库最公平,既可以测试数据库性能,也可以测试JDBC驱动。

一、tpmC性能测试要点

1、流量指标(Throughput,简称tpmC)

按照TPC组织的定义,流量指标描述了系统在执行支付操作、订单状态查询、发货和库存状态查询这4种交易的同时,每分钟可以处理多少个新订单交易。所有交易的响应时间必须满足TPC-C测试规范的要求,且各种交易数量所占的比例也应该满足TPC-C测试规范的要求。在这种情况下,流量指标值越大说明系统的联机事务处理能力越高。

2、测试时长

benchmarksql跑的时间越长,数据库也会越大,一般来说当数据库大小超过数据库共享缓存的3倍后,性能就会开始明显的下降。

3、cpu负荷

可使用htop监控数据库服务端和tpcc客户端CPU利用情况,最佳性能测试情况下,各个业务CPU的占用率应尽可能高。如果有CPU占用率没有达标,可能是绑核方式不对或其他问题,可采用 cpu 绑定技术。

4、warehouses

指定仓库数,仓库数决定性能测试的成绩。如果期望有较高测试结果,仓库数就不能太低。生产环境机器测试,建议 5000 仓库起步(5000仓与我们的业务场景不太相符,建议100仓)。

5、terminals

指定性能压测时的并发数,建议并发数不要高于仓库数 * 10。否则,会有不必要的锁等待。在生产环境中,该并发数设置到 1000 就很高了。一般环境测试建议从 100 开始。

6、runMins

指定性能测试持续的时间,时间越久,越能考验数据库的性能和稳定性。建议不要少于 10 分钟,生产环境中机器建议不少于 1 小时。

二、测试步骤

1、benchmarksql 下载

wget https://gitee.com/MapLover/benchmarksql5.1/repository/archive/master.zip

2、Requirements

■ 配置 ant java

yum install -y ant java

如果无法安装 ant,安装java后下载ant
https://ant.apache.ac.cn/bindownload.cgi 确认 ant 的最新版本
https://mirrors.nju.edu.cn/apache/ant/binaries/apache-ant-1.10.14-bin.tar.gz

仅 bin 和 lib 目录是运行 Ant 所必需的,安装 Ant,请选择一个目录并将发行版文件复制到该目录,此目录将被称为 ANT_HOME

运行 Ant 之前,需进行一些额外的设置,除非安装的是 RPM 版本

1、将 bin 目录添加到路径中

2、将 ANT_HOME 环境变量设置为安装 Ant 的目录

3、可选地,设置 JAVA_HOME 环境变量

ln -s /u01/nfs/soft/apache-ant-1.10.14 /opt/ant

vim /etc/profile

export JAVA_HOME=/u01/app/oracle/product/19.3.0/db_1/jdk

export ANT_HOME=/opt/ant

export PATH=JAVA_HOME/bin:ANT_HOME/bin:$PATH

■ 配置 python

采集cpu、disk、network等相关性能信息时需要调用python程序,支持的python版本是2,如果采用3版本会报错:

复制代码
2024-07-31 15:15:52: osCollectorScript=./misc/os_collector_linux.py
2024-07-31 15:15:52: osCollectorInterval=1
2024-07-31 15:15:52: osCollectorSSHAddr=null
2024-07-31 15:15:52: osCollectorDevices=net_ens39 blk_sda
2024-07-31 15:15:52: Term-00,
  File "<stdin>", line 63
    print ",".join([str(x) for x in sysInfo])
            ^
SyntaxError: invalid syntax
2024-07-31 15:15:52: OSCollector, unexpected EOF while reading from external helper process

因为信息采集是在数据库端执行的,下载
https://mirrors.nju.edu.cn/python/2.7.18/Python-2.7.18.tgz

解压缩、配置:

./configure --enable-optimizations --prefix=/usr/local/python2.7/

修改配置文件:

vim Modules/Setup

_ssl _ssl.c

-DUSE_SSL -I(SSL)/include -I(SSL)/include/openssl

-L$(SSL)/lib -lssl -lcrypto

默认这块是注释的,放开注释即开。这块功能是开启SSL模块,不然会出现安装完毕后,提示找不到ssl模块的错误。

编译、安装:

make -j8 && make install

建新软链:

mv /usr/bin/python /usr/bin/python.bak

ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python

python -V

Compile the BenchmarkSQL source code

总算可以编译 BenchmarkSQL 了:

复制代码
[root@BC86 benchmarksql5.1-master]# ant
Buildfile: /u01/nfs/soft/benchmark/benchmarksql5.1-master/build.xml
init:
    [mkdir] Created dir: /u01/nfs/soft/benchmark/benchmarksql5.1-master/build
compile:
    [javac] Compiling 11 source files to /u01/nfs/soft/benchmark/benchmarksql5.1-master/build
dist:
      [jar] Building jar: /u01/nfs/soft/benchmark/benchmarksql5.1-master/dist/BenchmarkSQL-5.1.jar
BUILD SUCCESSFUL

---如果遇见如下错误,需配置 JAVA_HOME:

复制代码
BUILD FAILED
/u01/nfs/soft/benchmarksql5.1-master/build.xml:24: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-11.oe2203.aarch64/jre"

Create the benchmark configuration file

创建测试的配置文件:

cd run

cp props.pg my_postgres.properties

复制代码
vim my_postgres.properties
---
db=postgres
driver=org.postgresql.Driver
conn=jdbc:postgresql://192.168.10.108:5432/postgres
user=postgres
password=passwdsefsdfsdf

//每个W约100MB,则100个约10G
warehouses=5
loadWorkers=5

//终端数,即并发客户端数量,通常设置为CPU线程总数的2~6倍
terminals=5

//To run specified transactions per terminal- runMins must equal zero
//每个终端运行的固定事务数量,如该值为10, 则每个terminal运行10个事务,如果有32个终端,那整体运行320个事务后,测试结束。该参数配置为非0值时,下面的runMins参数必须设置为0。
runTxnsPerTerminal=0

//To run for specified minutes- runTxnsPerTerminal must equal zero
//runMins表示要压测的时间长度,单位为分钟。该值为非0值时,runTxnsPerTerminal参数必须设置为0。这两个参数不能同时设置为正整数,如果设置其中一个,另一个必须为0,主要区别是runMins定义时间长度来控制测试时间;runTxnsPerTerminal定义事务总数来控制时间。
runMins=5

//Number of total transactions per minute
limitTxnsPerMin=100000000

//Set to true to run in 4.x compatible mode. Set to false to use the
//entire configured database evenly.
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=pg_result_%tY-%tm-%td_%tH%tM%tS
osCollectorScript=./misc/os_collector_linux.py
osCollectorInterval=1
//[email protected]
osCollectorDevices=net_ens39 blk_sda

---如下官方文档供参考:

Note that the provided example configuration is meant to test the functionality of your setupr. That benchmarksql can connect to the database and execute transactions. [■■■That configuration is NOT a benchmark run.■■■] To make it into one you need to have a configuration that matches your database server size and workload. Leave the sizing for now and perform a first functional test.

The BenchmarkSQL database has an initial size of approximately 100-100MB per configured warehouse. A typical setup would be a database of 2-5 times the physical RAM of the server.

Likewise the number of concurrent database connections (config parameter terminals) should be something about 2-6 times the number of CPU threads.

Last but not least benchmark runs are normally done for hours, if not days. This is because on the database sizes above it will take that long to reach a steady state and make sure that all performance relevant functionality of the database, like checkpointing and vacuuming, is included in the measurement.

So you can see that with a modern server, that has 32-256 CPU threads and 64-512GBi, of RAM we are talking about thousands of warehouses and hundreds of concurrent database connections.

Build the schema and initial database load

创建模式和初始化数据库:

复制代码
./runDatabaseBuild.sh my_postgres.properties > load_`date '+%Y-%m-%d-%H%M'`.log 2>&1 &
tail -100f load_*.log

如果 oracle 数据库,执行测试前可先生成一个awr快照

exec dbms_workload_repository.create_snapshot();

Run the configured benchmark

执行测试:

复制代码
./runBenchmark.sh my_postgres.properties > run_`date '+%Y-%m-%d-%H%M'`.log 2>&1 &
tail -100f run_*.log

The benchmark should run for the number of configured concurrent connections (terminals) and the duration or number of transactions.

如果 oracle 执行测试后,再生成一个awr快照,然后获取测试期间的 awr 报告

exec dbms_workload_repository.create_snapshot();

Scale the benchmark configuration.

Change the my_postgres.properties file to the correct scaling (number of warehouses and concurrent connections/terminals). Switch from using a transaction count to time based:

runTxnsPerTerminal=0

runMins=5

Rebuild the database

重新创建测试库:

./runDatabaseDestroy.sh my_postgres.properties

./runDatabaseBuild.sh my_postgres.properties

为了方便多次测试,减少导入数据的时间,可以通过停止数据库,将整个数据目录执行一次拷贝对数据库进行备份。

Result report

生成数据库测试报告:

./generateReport.sh pg_result_2024-07-31_195621

生成报告时,如果提示"无法打开链结到X11显示",则需开启 vncserver 服务

配置 R

复制代码
wget https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/base/R-4/R-4.4.1.tar.gz
./configure
make -j18
make install

---configure 如果错误较多,缺啥装啥:

yum install -y gcc gcc-c++ gcc-gfortran readline-devel

yum install -y gcc-gfortran

如报错:configure: error: --with-x=yes (default) and X11 headers/libs are not available

yum install -y libX11-devel libXt-devel

yum install -y zlib-devel bzip2-devel

如报错:liblzma library and headers are required

yum install -y xz-devel

yum install -y pcre2-devel

如报错:configure: error: libcurl >= 7.28.0 library and headers are required with support for https

yum install -y libcurl-devel

■ 不支持 png 的解决办法

yum install -y libpng-devel libtiff-devel libjpeg-turbo-devel pango-devel

再次 configure 即可!

正确结果应该是 png TRUE, bitmapType 是 cairo,如下:

复制代码
R
capabilities()
> capabilities()
       jpeg         png        tiff       tcltk         X11        aqua 
       TRUE        TRUE        TRUE       FALSE        TRUE       FALSE 
   http/ftp     sockets      libxml        fifo      cledit       iconv 
       TRUE        TRUE       FALSE        TRUE        TRUE        TRUE 
        NLS       Rprof     profmem       cairo         ICU long.double 
       TRUE        TRUE       FALSE       FALSE       FALSE        TRUE 
    libcurl 
       TRUE
getOption("bitmapType")
[1] "cairo"

■ 以下是使用 Cairo 配置支持 png【可选】

wget https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/png_0.1-8.tar.gz

wget https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/Cairo_1.6-2.tar.gz

install.packages("Cairo_1.6-2.tar.gz",repos=NULL)

报错:configure: error: Cannot find cairo.h!

yum install -y cairo* libxt*

复制代码
install.packages("png_0.1-8.tar.gz",repos=NULL)
library(Cairo)
library(png)
Cairo.capabilities()
---
     png     jpeg     tiff      pdf      svg       ps      x11      win
    TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE    FALSE
  raster freetype harfbuzz
    TRUE     TRUE    FALSE