benchmarksql-5.0 下载地址: https://udomain.dl.sourceforge.net/project/benchmarksql/benchmarksql-5.0.zip
htop 下载地址: https://github.com/htop-dev/htop/releases
R 语言下载地址: https://mirror.bjtu.edu.cn/cran/src/base/R-3/R-3.6.3.tar.gz
PostgreSQL客户端JDBC连接驱动 下载地址:https://jdbc.postgresql.org/download.html
# 安装所需系统包
[root@pgtest3 ~]# yum install -y gcc glibc-headers gcc-c++ gcc-gfortran readline-devel libXt-devel pcre-devel libcurl libcurl-devel ncurses ncurses-devel autoconf automake zlib zlib-devel bzip2 bzip2-devel xz-devel java-1.8.0-openjdk ant
# 安装R语言(generateReport.sh脚本需要) 使R语言支持png图片,否则报告生成有问题
[root@pgtest3 ~]# yum install -y pango-devel pango libpng-devel cairo cairo-devel
[root@pgtest3 ~]# cd /enmo/soft/
[root@pgtest3 soft]# tar -zxf R-3.6.3.tar.gz
[root@pgtest3 soft]# cd R-3.6.3
[root@pgtest3 R-3.6.3]# ./configure && make && make install
# 安装htop监控工具
[root@pgtest3 ~]# cd /enmo/soft/
[root@pgtest3 soft]# tar -zxvf htop-3.0.5.tar.gz
[root@pgtest3 soft]# cd htop-3.0.5
[root@pgtest3 htop-3.0.5]# ./autogen.sh && ./configure && make && make install
# 检查安装情况(java/ant/htop)
[root@pgtest3 ~]# ant -version
Apache Ant(TM) version 1.9.2 compiled on June 10 2014
[root@pgtest3 ~]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
[root@pgtest3 ~]# R --version
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
# 解压软件及JDBC驱动
[root@pgtest3 ~]# unzip /enmo/soft/benchmarksql-5.0.zip -d /enmo/app/
# 替换默认的postgresql驱动
[root@pgtest3 ~]# mv /enmo/app/benchmarksql-5.0/lib/postgres/postgresql-9.3-1102.jdbc41.jar /enmo/app/benchmarksql-5.0/lib/postgres/postgresql-9.3-1102.jdbc41.jar.bak
[root@pgtest3 ~]# cp /enmo/soft/postgresql-42.2.20.jar /enmo/app/benchmarksql-5.0/lib/postgres/postgresql.jar
# 使用ant编译
[root@pgtest3 ~]# cd /enmo/app/benchmarksql-5.0
[root@pgtest3 benchmarksql-5.0]# ant
Buildfile: /enmo/app/benchmarksql-5.0/build.xml
init:
[mkdir] Created dir: /enmo/app/benchmarksql-5.0/build
compile:
[javac] Compiling 11 source files to /enmo/app/benchmarksql-5.0/build
dist:
[mkdir] Created dir: /enmo/app/benchmarksql-5.0/dist
[jar] Building jar: /enmo/app/benchmarksql-5.0/dist/BenchmarkSQL-5.0.jar
BUILD SUCCESSFUL
Total time: 1 second
配置说明
# 数据库类型,postgres代表我们对PG数据库进行测试,它支持的数据库包括PostgreSQL/EnterpriseDB、DB2、Oracle、SQL Server和MySQL。
db=postgres
# 驱动
driver=org.postgresql.Driver
# 修改连接字符串, 包含IP、端口号、数据库 https://jdbc.postgresql.org/documentation/head/connect.html
cOnn=jdbc:postgresql://192.168.0.11:26000/benchmarksql?prepareThreshold=1&batchMode=on&fetchsize=10
# 设置数据库登录用户和密码。
user=bench
password=gauss@123
# 仓库数,每个Warehouse的数据量大小约为76823.04KB
warehouses=20
# 用于在数据库中初始化数据的加载进程数量,默认为4 (建议填写CPU核数)
loadWorkers=4
# 终端数,即:并发客户端数量, 跟服务端最大work数对应,通常设置为CPU线程总数的2~6倍
terminals=6
# 每个终端(terminal)运行的固定事务数量,当该参数为非0时,runMins参数必须等于零
runTxnsPerTerminal=0
# 要运行指定的分钟,当该参数为非0时,runTxnsPerTerminal必须等于零
runMins=5
# 每分钟总事务数
limitTxnsPerMin=0
# 在4.x兼容模式下运行时,设置为True。设置为false以均匀使用整个配置的数据库。
terminalWarehouseFixed=false
# 以下五个值相加之和为100 (45、43、4、4和4的默认百分比与TPC-C规范匹配)
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4
# 测试数据生成目录,默认无需修改,默认生成在run目录下面,名字形如my_result_xxxx的文件夹
resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
# 操作系统性能收集脚本,默认无需修改,需要操作系统具备有python2环境
osCollectorScript=./misc/os_collector_linux.py
# 操作系统收集操作间隔,默认为1秒
osCollectorInterval=1
# 操作系统收集所对应的主机,如果对本机数据库进行测试,该参数保持注销即可,如果要对远程服务器进行测试,请填写用户名和主机名
//osCollectorSSHAddr=omm@192.168.0.11
# 操作系统中被收集服务器的网卡名称和磁盘名称
osCollectorDevices=net_eth0 blk_vda
配置示例
[root@pgtest3 ~]# vi /enmo/app/benchmarksql-5.0/run/props.PostgreSQL.5432
db=postgres
driver=org.postgresql.Driver
cOnn=jdbc:postgresql://192.168.58.10:5432/benchmarksql?ApplicatiOnName=benchmark
user=benchmarksql
password=changeme
warehouses=20
loadWorkers=4
terminals=6
runTxnsPerTerminal=0
runMins=2
limitTxnsPerMin=0
terminalWarehouseFixed=false
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4
[root@pgtest3 ~]# vi /enmo/app/benchmarksql-5.0/run/props.PostgreSQL.5000
db=postgres
driver=org.postgresql.Driver
cOnn=jdbc:postgresql://192.168.58.20:5000/benchmarksql?ApplicatiOnName=benchmark
user=benchmarksql
password=changeme
warehouses=20
loadWorkers=4
terminals=6
runTxnsPerTerminal=0
runMins=2
limitTxnsPerMin=0
terminalWarehouseFixed=false
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4
例如,配置tableCreates.sql脚本,调整表的表空间分布(充分利用多块磁盘的IO)
# vi /opt/benchmarksql-5.0/run/sql.common/tableCreates.sql
------------------------------------------------------------
CREATE TABLESPACE tbs1 location '/gauss/data/tbs1';
CREATE TABLESPACE tbs2 location '/gauss/data/tbs2';
create table bmsql_config (
cfg_name varchar(30) primary key,
cfg_value varchar(50)
);
如果不是针对本机测试且配置了参数osCollectorSSHAddr,则需要配置与数据库服务器的ssh互信。
# ssh-keygen -t rsa
# ssh-copy-id postgres@192.168.58.10
# ssh-copy-id postgres@192.168.58.11
# ssh-copy-id postgres@192.168.58.12
# 创建测试用户和数据库
postgres=# CREATE USER benchmarksql WITH ENCRYPTED PASSWORD 'changeme';
postgres=# CREATE DATABASE benchmarksql OWNER benchmarksql;
# 确保放开连接权限
# vi pg_hba.conf
host all all 192.168.58.0/24 md5
# cat postgresql.auto.conf
listen_addresses = '*'
port = 5432
[root@pgtest3 ~]# cd /enmo/app/benchmarksql-5.0/run
# 执行前,请务必将props.PostgreSQL.1000w文件的所有注释和多余空格删除,否则可能报错
[root@pgtest3 run]# ./runDatabaseBuild.sh props.PostgreSQL.5432
[root@pgtest3 ~]# cd /opt/benchmarksql-5.0/run
[root@pgtest3 run]# ./runBenchmark.sh props.PostgreSQL.5432
[root@pgtest3 run]# ./runBenchmark.sh props.PostgreSQL.5000
# BenchmarkSQL修改参数后重新运行TPCC测试
# ./runDatabaseDestroy.sh props.PostgreSQL.5432
# ./runDatabaseBuild.sh props.PostgreSQL.5432
# ./runBenchmark.sh props.PostgreSQL.5432
[root@pgtest3 run]# ./runBenchmark.sh props.PostgreSQL.5432
Term-00, Running Average tpmTOTAL: 24834.29 Current tpmTOTAL: 1641864 Memory Usage: 22MB / 55MB
13:46:06,206 [Thread-4] INFO jTPCC : Term-00,
13:46:06,207 [Thread-4] INFO jTPCC : Term-00,
13:46:06,207 [Thread-4] INFO jTPCC : Term-00, Measured tpmC (NewOrders) = 11169.22
13:46:06,207 [Thread-4] INFO jTPCC : Term-00, Measured tpmTOTAL = 24833.05
13:46:06,207 [Thread-4] INFO jTPCC : Term-00, Session Start = 2021-11-04 13:36:06
13:46:06,208 [Thread-4] INFO jTPCC : Term-00, Session End = 2021-11-04 13:46:06
13:46:06,208 [Thread-4] INFO jTPCC : Term-00, Transaction Count = 248349
[root@pgtest3 run]# ./runBenchmark.sh props.PostgreSQL.5000
Term-00, Running Average tpmTOTAL: 21077.55 Current tpmTOTAL: 1385688 Memory Usage: 15MB / 55MB
14:02:16,373 [Thread-2] INFO jTPCC : Term-00,
14:02:16,374 [Thread-2] INFO jTPCC : Term-00,
14:02:16,374 [Thread-2] INFO jTPCC : Term-00, Measured tpmC (NewOrders) = 9543.71
14:02:16,374 [Thread-2] INFO jTPCC : Term-00, Measured tpmTOTAL = 21076.02
14:02:16,374 [Thread-2] INFO jTPCC : Term-00, Session Start = 2021-11-04 13:52:16
14:02:16,374 [Thread-2] INFO jTPCC : Term-00, Session End = 2021-11-04 14:02:16
14:02:16,374 [Thread-2] INFO jTPCC : Term-00, Transaction Count = 210781
# 检查R语言是否支持png
# R
> capabilities()
jpeg png tiff tcltk X11 aqua
FALSE TRUE FALSE FALSE FALSE FALSE
http/ftp sockets libxml fifo cledit iconv
TRUE TRUE TRUE TRUE TRUE TRUE
NLS profmem cairo ICU long.double libcurl
TRUE FALSE TRUE TRUE TRUE TRUE
# 生成html报告
[root@pgtest3 run]# ./generateReport.sh my_result_2021-01-19_145218/
[root@pgtest3 ~]# ls /enmo/app/benchmarksql-5.0/run/my_result_2021-01-19_145218
pgbench 不需要安装,PostgreSQL自带了。
postgres=# CREATE USER pgbench WITH ENCRYPTED PASSWORD 'pgbench';
postgres=# CREATE DATABASE pgbench OWNER pgbench;
$ pgbench -h 192.168.58.10 -p 5432 -U pgbench -d pgbench -i -s 2 -F 80 --partitiOns=20
$ pgbench -h 192.168.58.20 -p 5001 -U pgbench -d pgbench -P 2 -T 600 -S -c 200 -j 10
$ pgbench -h 192.168.58.10 -p 5432 -U pgbench -d pgbench -P 2 -T 600 -b tpcb-like -c 200 -j 2
$ pgbench -h 192.168.58.20 -p 5000 -U pgbench -d pgbench -P 2 -T 60 -b simple-update@2 -b tpcb-like@8 -c 200 -j 2