JDBC Connection Configuration & JDBC Request 详解

Jmeter同样可以测试数据库的性能,通过执行增删改查的语句

step1:Jdbc配置

线程组-》添加-》配置元件-》JDBC Connection Configuration,只要配置Database Connection Configuration即可,其他保持默认。


简单来说:

Variable Name: 变量名称,需要变量名绑定到池。需要唯一标识。与JDBC取样器中的相对应,决定JDBC取样的配置。简单理解就是在JDBC request的时候确定去哪个绑定的配置。
Max Number of Connection: 数据库最大链接数
PoolTimeout: 数据库链接超时,单位ms
Idle Cleanup Interval (ms): 数据库空闲清理的间隔时间,单位ms
Auto Commit:自动提交。有三个选项,true、false、编辑(自己通过jmeter提供的函数设置)
Transaction Isolation:  
事务间隔级别设置,主要有如下几个选项:(对JMX加解密) 
【TRANSACTION_NODE   事务节点 、
TRANSACTION_READ_UNCOMMITTED  事务未提交读、
TRANSACTION_READ_COMMITTED   事务已提交读 、
TRANSACTION_SERIALIZABLE   事务序列化 、
DEFAULT  默认、
TRANSACTION_REPEATABLE_READ 事务重复读、
编辑】

Keep-Alive: 是否保持连接Max  Connection age (ms):最大连接时长,超过时长的会被拒绝Validation Query:验证查询,检验连接是否有效(数据库重启后之前的连接都失效,需要验证查询)。。。。。。
Database URL:如jdbc:mysql://localhost:3306/test   表示本地数据库,3306端口,数据库名称为test
JDBCDriver Class: JDBC的类,如org.gjt.mm.mysql.Driver  


这些配置是跟数据库连接池有关,具体可参考下面博文:

http://blog.csdn.net/sunwangdian/article/details/50737270

http://elf8848.iteye.com/blog/1931778

http://www.mamicode.com/info-detail-1242126.html

http://blog.csdn.net/yzllz001/article/details/54845877

http://blog.csdn.net/u012868077/article/details/48134179


下面是原文和翻译:

(1) Variable Name Bound to Pool

Variable Name,数据库连接池的变量名,之后JDBC request可以通过选择不同的连接池名来选择不同的数据库连接

Variable name变量名称:与JDBC Request的Variable name保持一致

原因:因为链接数据库是需要在JDBC Connection Configuration中配置好的,然后赋予一个变量名称,那么JDBC Request想要去访问数据库,就必须通过这个配置好的元件去链接,所以JDBC Reques就需要通过读取JDBC Connection Configuration的变量中的信息,

那怎么读取呢,JDBC Reques就需要用到这个变量了,就需要到名称为mysql的元件中去应用。

(2) Connection Pool Configuration

Max Number of Connections    该数据库连接池的最大连接数,一般可设置为0,意思是每个线程都使用单独的数据库连接,线程之间数据库连接不共享
中文:池中允许的最大连接数。在大多数情况下,将其设置为0,这意味着每个线程将得到它自己的池,其中只有一个连接,即线程之间不共享连接。 如果您真的想要使用共享池(为什么?),那么将max count与线程数相同,以确保线程不会相互等待。
原文:aximum number of connections allowed in the pool. In most cases, set this to zero (0) . This means that each thread will get its own pool with a single connection in it, i.e. the connections are not shared between threads. If you really want to use shared pooling (why?), then set the max count to the same as the number of threads to ensure threads don't wait on each other.

Max Wait (ms)   在连接池中取回连接最大等待时间
中文:如果在试图检索连接过程中(取回连接)超过所设置期限,连接池抛出一个错误
原文:ool throws an error if the timeout period is exceeded in the process of trying to retrieve a connection

Time Between Eviction Runs (ms)     疏散时间
中文:在空闲对象驱逐线程运行期间,可以休眠的毫秒数。当非正值时,将运行无空闲对象驱逐器线程。(默认为“60000”,1分钟)(如果当前连接池中某个连接在空闲了time Between Eviction Runs Millis时间后任然没有使用,则被物理性的关闭掉。)
原文:The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run. (Defaults to " 60000 ", 1 minute)

Auto Commit    自动提交sql语句
中文:打开或关闭连接的自动提交。
原文:Turn auto commit on or off for the connections.

(3) Connection Validation by Pool 

这是Jmeter用来检验数据库连接是否有效的一种机制,超过5秒没有使用的话,就会用validation query去测试下这个连接是否有效

Test While Idle   当空闲的时候测试连接是否断开
中文:测试连接池的空闲连接,验证查询将会被使用去测试。
原文:Test idle connections of the pool, see BasicDataSource.html#getTestWhileIdle . Validation Query will be used to test it.

Soft Min Evictable Idle Time(ms)   
中文:最少的时间连接可能在池中闲置,然后才有资格被闲置的对象驱逐出去,额外的条件是至少在池中保持连接。默认值为5000(5秒)
原文:Minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle object evictor, with the extra condition that at least minIdle connections remain in the pool. See BasicDataSource.html#getSoftMinEvictableIdleTimeMillis . Defaults to 5000 (5 seconds)

(4) Database Connection Configuration

Database URL: jdbc:mysql://服务器地址:3306/数据库名  

  (比如:jdbc:mysql://ip:3306/数据库名?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true)

    备注:“&allowMultiQueries=true” 这句话的意思呢  是为了在JDBC中执行多条select语句的时候用的!

JDBC Driver class:数据库JDBC驱动类名:com.mysql.jdbc.Driver

Username:数据库连接用户名

password:数据库连接密码

例如(上面url或class如有问题,可试一试下面的):

Database URL:  jdbc:mysql://localhost:3306/information_schema?serverTimezone=GMT%2B8

JDBC Driver class:  com.mysql.cj.jdbc.Driver

Username:root

password:xxx


Step 2:建立一个JDBC Request组件 

目前JDBC Request可以发送的请求类型有

  • Select Statement
  • Update Statement - use this for Inserts and Deletes as well
  • Callable Statement
  • Prepared Select Statement
  • Prepared Update Statement - use this for Inserts and Deletes as well
  • Commit
  • Rollback
  • Autocommit(false)
  • Autocommit(true)
  • Edit - this should be a variable reference that evaluates to one of the above

我这里举了一个存储过程的例子

首先Variable Name要写之前创建好的数据库连接池的名字

SQL Query部分,选择Query Type为callable statement,语句中用问号作为占位符,代替传入的参数

然后在Parameter value里面设置传入的值,这里也可以用变量,即可以读csv文件里的值,比较灵活,但是千万要记得在下面一行Parameter Types里面配置好相应的类型,否则会报错

Variable Name,可以用来存储查询的值,例如你查询select * from tableA,返回三行三列,你在Variable Name里面写A,,C,那么会返回如下值,第二列由于没有变量名,所以不会被存储,不过需要一个空占位符

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

Result Variable name,用法 columnValue = vars.getObject("resultObject").get(0).get("Column Name"); 将结果集存储在一个对象中,然后按照行号加列名去取值


  • 3
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值