BenchmarkSQL 是一个易于使用的 JDBC 基准测试程序, 它与 OLTP 的TPC-C标准非常相似。它支持的数据库包括 PostgreSQL/EnterpriseDB、DB2,、Oracle、 SQL Server和 MySQL。
BenchmarkSQL 是开源的, 采用的协议是 GNU 通用公共许可协议版本 2.0 (GPL v2),这意味着它不允许修改后的和衍生的代码做为闭源的商业软件发布和销售 。
本文将介绍如何安装BenchmarkSQL并使用它测量PostgreSQL的性能参数。
硬件环境:
CPU,Intel(R) Xeon(R) 4核以上
内存,8G 以上
操作系统:
Linux,推荐使用CentOS 7.x。
软件环境:
Java,JDK 7以上版本
PostgreSQL,本文采用 PostgreSQL 10.0。可安装在另一台计算机上。
Ant,本文采用ant 1.7.1
EPEL 仓库,本文采用epel-release-6-8
R语言,本文采用R 3.5.1
以及上述软件的依赖。
本文默认Java和PostgreSQL已经安装成功。若读者未安装Java和PostgreSQL,请首先自行安装,然后阅读后续内容。
执行命令:
yum -y install ant
如果你使用的是CentOS 6.x的版本,执行命令:
su -c 'rpm -Uvh https://download.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm'
如果你使用的是CentOS 7.x的版本,执行命令:
su -c 'rpm -Uvh https://download.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm'
然后更新yum仓库:
sudo yum -y update
执行命令:
sudo yum -y install R
安装过程中,若出现如下问题:
下载软件包时出错
texinfo-tex-4.13a-8.el6.x86_64: failure: Packages/texinfo-tex-4.13a-8.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.
请参考5.1节“下载软件包失败”。
在下载地址中下载BenchmarkSQL 安装包。本文下载的文件是benchmarksql-5.0.zip(见附录)。下载完成后解压文件:
unzip ./benchmarksql-5.0.zip
在安装了PostgreSQL的服务器上启动PostgreSQL并登录,然后创建名为benchmarksql的用户数据库:
postgres=# CREATE USER benchmarksql WITH ENCRYPTED PASSWORD 'changeme';
postgres=# CREATE DATABASE benchmarksql OWNER benchmarksql;
postgres=# \q
这里,你可以将“changeme” 替换为自己的数据库密码。
进入BenchmarkSQL 解压后的目录,并使用ant编译源码:
[wieck@localhost ~] $ cd benchmarksql
[wieck@localhost benchmarksql] $ ant
进入run目录, 复制props.pg文件并编辑产生的副本,设置与基准测试有关的参数:
[wieck@localhost benchmarksql] $ cd run
[wieck@localhost run] $ cp props.pg my_postgres.properties
[wieck@localhost run] $ vi my_postgres.properties
首次实验时,首先修改下面的参数:
conn=jdbc:postgresql://localhost:5432/postgres
将其中的 “localhost” 修改为postgresql所在服务器的ip地址,将“5432”修改为 postgresql所在的端口,将末尾的 “postgres” 修改为所测量的数据库。本次实验,将其修改为 conn=jdbc:postgresql://localhost:5432/ benchmarksql
user=benchmarksql
将“benchmarksql”修改为用来测试的用户。本次实验不做修改。
password=PWbmsql
将“PWbmsql”修改为测试的用户的密码。本次实验将其修改为“changeme”。
执行当前路径下的shell脚本:
[wieck@localhost run] ./runDatabaseBuild.sh my_postgres.properties
执行下面的命令,验证程序BenchmarkSQL是否能正确运行:
[wieck@localhost run]$ ./runBenchmark.sh my_postgres.properties
基准测试的报告的结尾如下所示:
01:58:09,081 [Thread-1] INFO jTPCC : Term-00,
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Measured tpmC (NewOrders) = 179.55
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Measured tpmTOTAL = 329.17
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Session Start = 2016-05-25 01:58:07
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Session End = 2016-05-25 01:58:09
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Transaction Count = 10
这表示你成功运行了一次测试。
进行正式的测试之前,需要修改my_postgres.properties中的参数。
本次实验中,我们将下面两个参数修改为:
runTxnsPerTerminal=0
runMins=120
其中,runTxnsPerTerminal代表测试时,每个终端运行的事务数量。运行的事务数量达到这个值后测试结束;runMins 代表测试的时长,以分钟为单位。
当这两个参数之一的值大于零时,另一个的值必须设置为0。
依次执行下面的命令,重新初始化数据库,并运行基准测试:
[wieck@localhost run]$ ./runDatabaseDestroy.sh my_postgres.properties
[wieck@localhost run]$ ./runDatabaseBuild.sh my_postgres.properties
[wieck@localhost run]$ ./runBenchmark.sh my_postgres.properties
接下来,BenchmarkSQL会对相应的Postgresql 数据库进行时长为120分钟的性能测试。
测试结束后,run目录下会生成一个新目录,它的命名格式为 my_result_%tY-%tm-%td_%tH%tM%tS。
使用 generateReport.sh my_result_* 脚本创建具有图形的 HTML 文件:
例如:
./generateReport.sh my_result_2018-09-30_133047
随后会在my_result_* 目录下生成一个html文件。
用浏览器打开,即可查看报告。如图所示:
问题描述:
使用命令 “sudo yum -y install R” 下载软件包时报错:
下载软件包时出错
texinfo-tex-4.13a-8.el6.x86_64: failure: Packages/texinfo-tex-4.13a-8.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.
libicu-devel-4.2.1-14.el6.x86_64: failure: Packages/libicu-devel-4.2.1-14.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.
解决方法:
1. 首先,手动在官网上下载缺失的组件:
texinfo-tex-4.13a-8.el6.x86_64
libicu-devel-4.2.1-14.el6.x86_64
2. 下载完成后,使用如下命令安装:
rpm -ivh texinfo-tex-4.13a-8.el6.x86_64.rpm
rpm -ivh texinfo-tex-4.13a-8.el6.x86_64
3. 重新安装相关组件:sudo yum -y install R
[1] BenchmarkSQL开发团队. Instructions for running BenchmarkSQL on PostgreSQL.
[2] Martyn Plummer. R RPMS for Fedora, Red Hat Enterprise Linux and Derivatives. 2014-07-22.
[3] Jason A. French. Installing R in Linux. 2013-05-11