[原创]使用benchmarksql和pgbench对PostgreSQL Plus Advanced Server进行性能测试

时间:2023-03-09 13:44:01
[原创]使用benchmarksql和pgbench对PostgreSQL Plus Advanced Server进行性能测试

一、测试环境

benchmarksql version:4.0.8

rhel 6.3

vmware esxi

二、理解benchmarksql性能测试原理TPC-C

1、理解TPC-C

TPC-C模拟一个批发商的货物管理环境。该批发公司有N个仓库,每个仓库供应10个地区,其中每个地区为3000名顾客服务。在每个仓库中有10个终端,每一个终端用于一个地区。在运行时,10×N个终端操作员向公司的数据库发出5类请求。由于一个仓库中不可能存储公司所有的货物,有一些请求必须发往其它仓库,因此,数据库在逻辑上是分布的。N是一个可变参数,测试者可以随意改变N,以获得最佳测试效果。

TPC-C使用三种性能和价格度量,其中性能由TPC-C吞吐率衡量,单位是tpmC。tpm是transactions
per
minute的简称;C指TPC中的C基准程序。它的定义是每分钟内系统处理的新订单个数。要注意的是,在处理新订单的同时,系统还要按表1的要求处理其它4类事务
请求。从表1可以看出,新订单请求不可能超出全部事务请求的45%,因此,当一个系统的性能为1000tpmC时,它每分钟实际处理的请求数是2000多个。价格是指系统的总价格,单位是美元,而价格性能比则定义为总价格÷性能,单位是$/tpmC。

tpmC定义:
TPC-C的吞吐量,按有效TPC-C配置期间每分钟处理的平均交易次数测量,至少要运行12分钟。(吞吐量测试结果以比特/秒或字节/秒表示。)

这里还有一篇文章介绍的很详细:

http://blog.sina.com.cn/s/blog_4485748101019wsh.html

2、benchmarksql参数设置

批发公司的N个仓库,默认为1

warehouses=1

每个仓库中的终端数

terminals=1

//To run specified
transactions per terminal- runMins must equal zero

每终端执行的事务数,如果启用它,就必须将runMins设置为0

runTxnsPerTerminal=10

//To run for specified
minutes- runTxnsPerTerminal must equal zero

终端执行时间,如果启用它,就必须设置runTxnsPerTerminal为0

runMins=0

//Number of total
transactions per minute

limitTxnsPerMin=300

//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

二、PPAS测试

PPAS version:PostgreSQL
Plus Advanced Server 9.2

1、修改驱动及数据库用户名和密码:

[root@dbserver ~]# cp
/opt/benchmarksql-4.0.8/run/props.pg
/opt/benchmarksql-4.0.8/run/props.pg.bak

[root@dbserver ~]# vim
/opt/benchmarksql-4.0.8/run/props.pg

driver=com.edb.Driver

conn=jdbc:edb://localhost:5444/edb

user=benchmarksql

password=000000

2、复制EDB的JDBC驱动到benchmarksql的lib目录

[root@dbserver ~]# cp
/opt/PostgresPlus/9.2AS/connectors/jdbc/edb-jdbc16.jar
/opt/benchmarksql-4.0.8/lib/

3、修改benchmarksql的执行脚本

默认的,benchmarksql的执行脚本都是使用PostgreSQL驱动,因为我们这里要测试的是PPAS,所以首先将执行脚本中的驱动全部修改为EDB的驱动:

[root@dbserver ~]# vim
/opt/benchmarksql_ora/run/runSQL.sh

将脚本中的"postgresql-9.2-1003.jdbc4.jar"修改为:myCP="../lib/
edb-jdbc16.jar",其他几个sh文件也是一样的修改;

[root@dbserver ~]# vim
/opt/benchmarksql_ora/run/runBenchmark.sh

[root@dbserver ~]# vim
/opt/benchmarksql_ora/run/runLoader.sh

3、创建benchmarksql用户并赋予适当的权限

[root@dbserver ~]# psql
-U enterprisedb edb

edb=# CREATE USER
benchmarksql WITH PASSWORD '000000';

CREATE ROLE

edb=# GRANT ALL
PRIVILEGES ON DATABASE edb TO benchmarksql;

GRANT

4、转到benchmarksql的run目录,运行脚本创建测试表

[root@dbserver run]#
./runSQL.sh props.pg sqlTableCreates

如果要删除表,则可以运sqlTableDrops脚本

5、加载测试数据

[root@dbserver run]#
./runLoader.sh props.pg numWarehouses 1

执行完成后可以看到执行的统计结果。

6、创建主键和索引

[root@dbserver
run]#./runSQL.sh props.pg sqlIndexCreates

如果要删除索引,则可以运sqlIndexDrops脚本

7、使用benchmark进行测试:

[root@dbserver run]#
./runBenchmark.sh props.pg

脚本“runBenchmark.sh”会根据props.pg文件中的配置进行自动化的测试,测试完成会给出详细的测试报告。

8、自动测试

自动测试脚本

#! /bin/sh

./runSQL.sh props.pg
sqlIndexDrops

./runSQL.sh props.pg
sqlTableDrops

./runSQL.sh props.pg
sqlTableCreates

./runLoader.sh props.pg
numWarehouses 1

./runSQL.sh props.pg
sqlIndexCreates

./runBenchmark.sh
props.pg

自动删除索引,表及测试结果脚本

#! /bin/sh

./runSQL.sh props.pg
sqlIndexDrops

./runSQL.sh props.pg
sqlTableDrops

./clean.sh

三、PostgreSQL测试

四、MySQL测试

[root@dbserver ~]#
mysql --version

mysql Ver 14.14
Distrib 5.6.14, for Linux (x86_64) using EditLine wrapper

1、准备JDBC驱动

[root@dbserver ~]# cp
/opt/workspace/mysql-connector-java-5.1.26/mysql-connector-java-5.1.26-bin.jar
/opt/benchmarksql_mysql/lib/

2、修改benchmarksql的执行脚本

首先将执行脚本中的驱动全部修改为MySQL的JDBC驱动:

[root@dbserver ~]# vim
/opt/benchmarksql_mysql/run/runSQL.sh

将脚本中的"postgresql-9.2-1003.jdbc4.jar"修改为:myCP="../lib/
mysql-connector-java-5.1.26-bin.jar ",其他几个sh文件也是一样的修改;

[root@dbserver ~]# vim
/opt/benchmarksql_mysql/run/runBenchmark.sh

[root@dbserver ~]# vim
/opt/benchmarksql_mysql/run/runLoader.sh

3、创建benchmarksql用户并赋予适当的权限

benchmarksql建议使用一个用户名为““benchmarksql”的用户进行测试,这里我们先在Oracle中创建benchmarksql用户:

[root@dbserver ~]#
mysql -u root -p

mysql> CREATE USER
'benchmarksql'@'localhost' IDENTIFIED BY '000000';

mysql> flush
privileges;

创建测试数据库

mysql> create
database benchmarkdb;

为用户赋予操作数据库benchmarkdb的所有权限

mysql> grant all
privileges on benchmarkdb.* to 'benchmarksql'@'localhost' identified
by '000000';

mysql> flush
privileges;

4、修改配置文件中的数据库连接信息

[root@dbserver ~]# cp
/opt/benchmarksql_mysql/run/props.ora
/opt/benchmarksql_ora/run/props.mysql

[root@dbserver ~]# vim
/opt/benchmarksql_ora/run/props.mysql

修改props.mysql中的连接字符串及mysql数据库的用户名和密码。

driver=com.mysql.jdbc.Driver

conn=jdbc:mysql://localhost:3306/benchmarkdb

user=benchmarksql

password=000000

5、创建测试表

[root@dbserver ~]# cd
/opt/benchmarksql_ mysql/run/

[root@dbserver run]#
./runSQL.sh props.mysql sqlTableCreates如果要删除表,则可以运sqlTableDrops脚本

6、加载测试数据

[root@dbserver run]#
./runLoader.sh props.mysql numWarehouses 1

执行完成后可以看到执行的统计结果。

7、创建主键和索引

[root@dbserver
run]#./runSQL.sh props.mysql sqlIndexCreates

如果要删除索引,则可以运sqlIndexDrops脚本

8、使用benchmark进行测试:

[root@dbserver run]#
./runBenchmark.sh props.mysql

脚本“runBenchmark.sh”会根据props.mysql文件中的配置进行自动化的测试,测试完成会给出详细的测试报告。

mysql的测试,在最后一步runBenchmark.sh脚本时,会出很多的错误,一部分是mysql的sql脚本的问题,需要自己重新对几个sql脚本进行修改,使之符合mysql语法,这里有一篇文章介绍了benchmarksql对mysql的测试,但是是非常老的版本,记录作为参考:

http://kenshin579.tistory.com/322

五、Oracle测试

1、准备JDBC驱动

从Oracle的JDBC目录中复制Oracle
JDBC驱动到benchmarksql的lib目录中

Oracle version:10.2.0.4

cp /oracle/product/10.2/db_1/jdbc/lib/ojdbc14.jar
/opt/benchmarksql_ora/lib/

Oracle version:11.2.0.1

cp
$ORACLE_HOME/jdbc/lib/ojdbc6.jar ~/benchmarksql_ora/lib/

2、修改benchmarksql的执行脚本

首先将执行脚本中的驱动全部修改为Oracle的JDBC驱动:

[root@dbserver ~]# vim
/opt/benchmarksql_ora/run/runSQL.sh

将脚本中的"postgresql-9.2-1003.jdbc4.jar"修改为:myCP="../lib/ojdbc14.jar",其他几个sh文件也是一样的修改;

[root@dbserver ~]# vim
/opt/benchmarksql_ora/run/runBenchmark.sh

[root@dbserver ~]# vim
/opt/benchmarksql_ora/run/runLoader.sh

3、修改配置文件中的数据库连接信息

[root@dbserver ~]# cp
/opt/benchmarksql_ora/run/props.ora
/opt/benchmarksql_ora/run/props.ora.bak

[root@dbserver ~]# vim
/opt/benchmarksql_ora/run/props.ora

修改props.ora中的连接字符串及oracle数据库的用户名和密码。

4、创建benchmarksql用户并赋予适当的权限

benchmarksql建议使用一个用户名为““benchmarksql”的用户进行测试,这里我们先在Oracle中创建benchmarksql用户:

CREATE USER
benchmarksql IDENTIFIED BY "000000";

GRANT dba TO
benchmarksql;

4、创建测试表

[root@dbserver ~]# cd
/opt/benchmarksql_ora/run/

[root@dbserver run]#
./runSQL.sh props.ora sqlTableCreates如果要删除表,则可以运sqlTableDrops脚本

5、加载测试数据

[root@dbserver run]#
./runLoader.sh props.ora numWarehouses 1

执行完成后可以看到执行的统计结果。

6、创建主键和索引

[root@dbserver
run]#./runSQL.sh props.ora sqlIndexCreates

如果要删除索引,则可以运sqlIndexDrops脚本

7、使用benchmark进行测试:

[root@dbserver run]#
./runBenchmark.sh props.ora

脚本“runBenchmark.sh”会根据props.ora文件中的配置进行自动化的测试,测试完成会给出详细的测试报告。

Oracle version:11.2.0.1

1、准备JDBC驱动

从Oracle的JDBC目录中复制Oracle
JDBC驱动到benchmarksql的lib目录中

[oracle@rhel ~]$ cp
/u01/oracle/product/11.2/dbhome_1/jdbc/lib/ojdbc6.jar
~/benchmarksql-4.0.8/lib/

2、修改benchmarksql的执行脚本

首先将执行脚本中的驱动全部修改为Oracle的JDBC驱动:

[root@ ~]# vim
/opt/benchmarksql_ora/run/runSQL.sh

将脚本中的"postgresql-9.2-1003.jdbc4.jar"修改为:myCP="../lib/ojdbc6.jar",其他几个sh文件也是一样的修改;

[root@ ~]# vim
/opt/benchmarksql_ora/run/runBenchmark.sh

[root@ ~]# vim
/opt/benchmarksql_ora/run/runLoader.sh

3、修改配置文件中的数据库连接信息

[root@dbserver ~]# cp
/opt/benchmarksql-4.0.8/run/props.ora
/opt/benchmarksql-4.0.8/run/props.ora.bak

[root@ ~]# vim
/opt/benchmarksql_ora/run/props.ora

修改props.ora中的连接字符串及oracle数据库的用户名和密码。

创建benchmarksql用户并赋予适当的权限

benchmarksql建议使用一个用户名为““benchmarksql”的用户进行测试,这里我们先在Oracle中创建benchmarksql用户:

CREATE USER
benchmarksql IDENTIFIED BY "000000";

GRANT dba TO
benchmarksql;

4、创建测试表

[root@dbserver ~]# cd
/opt/benchmarksql_ora/run/

[root@dbserver run]#
./runSQL.sh props.ora sqlTableCreates如果要删除表,则可以运sqlTableDrops脚本

5、加载测试数据

[root@dbserver run]#
./runLoader.sh props.ora numWarehouses 1

执行完成后可以看到执行的统计结果。

6、创建主键和索引

[root@dbserver
run]#./runSQL.sh props.ora sqlIndexCreates

如果要删除索引,则可以运sqlIndexDrops脚本

7、使用benchmark进行测试:

[root@dbserver run]#
./runBenchmark.sh props.ora

脚本“runBenchmark.sh”会根据props.ora文件中的配置进行自动化的测试,测试完成会给出详细的测试报告。

六、使用pgbench对EDB进行性能测试

1、安装pgbench

安装完PostgreSQL
Plus Advanced
server,已经默认安装了pgbench;如果使用PostgreSQL,那么需要通过pgbench的源码进行编译和安装,此处略。

2、初始化测试数据

[root@edbs1 ~]# pgbench
-i benchmarkdb -U enterprisedb

3、测试

[root@edbs1
pgbenchscripts]# pgbench -c 10 -j 10 -T 30 -d benchmarkdb -U
enterprisedb -f /opt/workspace/pgbenchscripts/script_1.sql >
/opt/workspace/pgbenchscripts/script_5.out

下面是script_1.sql的内容,如果不指定-f参数,则使用pgbench默认的脚本进行测试。如果指定了-S参数,可以进行只读测试。

\set nbranches :scale

\set ntellers 10 *
:scale

\set naccounts 100000 *
:scale

\setrandom delta -5000
5000

\setrandom aid 1
:naccounts

\setrandom bid 1
:nbranches

\setrandom tid 1
:ntellers

BEGIN;

UPDATE pgbench_accounts
SET abalance = abalance + :delta WHERE aid = :aid;

SELECT abalance FROM
pgbench_accounts WHERE aid = :aid;

UPDATE pgbench_tellers
SET tbalance = tbalance + :delta WHERE tid = :tid;

UPDATE pgbench_branches
SET bbalance = bbalance + :delta WHERE bid = :bid;

INSERT INTO
pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid,
:bid,:aid,:delta, CURRENT_TIMESTAMP);

END;

关于pgbench更多参数介绍,使用pgbench
--help进行查看。

Benchmarking options:

-c NUM number
of concurrent database clients (default: 1)

-C
establish new connection for each transaction

-D VARNAME=VALUE

define
variable for use by custom script

-f FILENAME read
transaction script from FILENAME

-j NUM number
of threads (default: 1)

-l write
transaction times to log file

-M
simple|extended|prepared

protocol
for submitting queries to server (default: simple)

-n do not
run VACUUM before tests

-N do not
update tables "pgbench_tellers" and "pgbench_branches"

-r report
average latency per command

-s NUM report
this scale factor in output

-S perform
SELECT-only transactions

-t NUM number
of transactions each client runs (default: 10)

-T NUM duration
of benchmark test in seconds

-v vacuum
all four standard tables before tests

--aggregate-interval=NUM

aggregate data over NUM seconds

--sampling-rate=NUM

fraction
of transactions to log (e.g. 0.01 for 1% sample)