jmeter 数据库


JDBC Connection Configuration(配置元件) 跟 JDBC Request(Sample)是配合起来使用的:

1、JDBC Connection Configuration里的Variable Name跟JDBC Request里的Variable Name要同名,不然会报错

2、执行的时候是执行的JDBC Request里抽SQL,所以JDBC Connection Configuration里面的Validataion Query有没有都无所谓

3、JDBC Request里的Variable Names:

If the Variable Names list is provided, then for each row returned by a Select statement, the variables are set up with the value of the corresponding column (if a variable name is provided), and the count of rows is also set up. For example, if the Select statement returns 2 rows of 3 columns, and the variable list is A,,C , then the following variables will be set up:

A_#=2 (number of rows)
A_1=column 1, row 1
A_2=column 1, row 2
C_#=2 (number of rows)
C_1=column 3, row 1
C_2=column 3, row 2

If the Select statement returns zero rows, then the A# and C# variables would be set to 0, and no other variables would be set.

所以如果Variable Names的值设为:A 那后面引用A的话可以用:${A_1}就可以取到select得到的第一值的时间了

jmeter 对Oracle数据库进行并发测试:

1、COPY ORACLE的JDBC驱动JAR包文件(ojdbc14.jar)到JMeter的lib目录下。
(查看Oralce的JDBC驱动包,只用打开数据库,点击Driver最右边会出来数据库的Driver Manager 从这里就可以看出驱动包放在什么地方,也能看出JDBC Driver class)。

2、启动jmeter,从测试计划里新增一个线程组,编辑线程数

3、再从线程组下新增一个JDBC连接池配置,例:

Database URL:数据库地址,格式为 jdbc:oracle:thin:@[IP地址]:[端口号]:[实例名],如:
jdbc:oracle:thin:@192.168.0.126:1521:ydgl
JDBC Driver class:数据库JDBC驱动类名,如:

jdbc:oracle:thin:@192.168.16.163:1521:devdb
Username:数据库连接用户名,如:

pair36

Password:数据库连接密码,如:

pair36

(其它一些基本信息可以看jmeter自带的帮助文件的提示)

4、然后:线程组-->sampler-->JDBC Request,在Query框里输入sql语句,添加监听器后运行就行了

jmeter官网:

http://jakarta.apache.org/jmeter/

http://jakarta.apache.org/jmeter/usermanual/component_reference.html#JDBC_Connection_Configuration :这里有讲解,不同的数据库内容有一些不一样:

Database Driver class Database URL
MySQL com.mysql.jdbc.Driver jdbc:mysql://host[:port]/dbname
PostgreSQL org.postgresql.Driver jdbc:postgresql:{dbname}
Oracle oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@//host:port/service OR
jdbc:oracle:thin:@(description=(address=(host={mc-name})(protocol=tcp)(port={port-no}))(connect_data=(sid={sid})))
Ingres (2006) ingres.jdbc.IngresDriver jdbc:ingres://host:port/db[;attr=value]
SQL Server (MS JDBC driver) com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc:sqlserver://host:port;DatabaseName=dbname
Apache Derby org.apache.derby.jdbc.ClientDriver jdbc:derby://server[:port]/databaseName[;URLAttributes=value[;...]]

数据库配置

JMeter 10步搞定ORACLE数据库并发测试 与LoadRunner相比,JMeter是一个轻量级的测试工具,入门也简单,功能简单但都很实用,本文主要介绍其中一个功能点,数据库JDBC并发访问测试。共分以下10个步骤。

1、下载软件,目前最新版为jmeter 2.3.1
2、COPY ORACLE的JDBC驱动JAR包文件(ojdbc14.jar)到JMeter的lib目录下。
ojdbc14.jar文件一般位于ORACLE的安装目录下的jdbc\lib目录中。本人的就在C:\oracle\ora92\jdbc\lib目录中。
3、进入bin目录运行jmeter.bat启动jmeter.
4、从测试计划里新增一个线程组.
5、再从线程组下新增一个JDBC连接池配置.
6、接着新增一个JDBC访问测试.
7、再配置一个聚合报告,用来显示测试结果的.
8、保存测试计划.
9、从运行菜单启动测试.
10、从聚合报告查看测试结果.

如下图:

注意这里JDBC Connection Configuration中的Variable Name要跟JDBC Request中的Variable Name名字一致,不然的话会报错。

Joyce /
Published under (CC) BY-NC-SA in categories jmeter  tagged with jmeter  database