jmeter- knowledge points to explain

Association (regular expressions)

Automatically associated to the new addressing bug bug number
1) [added in the corresponding request postprocessor]> [] extractor regular expression
(2) to be extracted to find the content in response to the request result tree
(3) provided regular expression extractor
Here Insert Picture Description
Reference name: Next request parameter name to be referenced, such as filling ABC, the reference can be used it $ {abc}.
Regular Expressions:
    (): Enclosed part is to be extracted.
    .: Matches any string.
    +: One or more times.
    ?: Do not be too greedy, stop after finding the first match.
    *: Matches zero or more times

template: With KaTeX parse error: Can not use function '$' in math mode at position 28: ... wherein a plurality of regular expressions, it may be of $ 2 $ 3 3 , etc., showing an analysis of the several values to abc. Such as: 1 1 represents the analytical value of a
Matching numbers: 0 represents a random value, 1 for all values, usually fill 0
The default value: If the parameter is not to get value, a value that defaults to take it.
(4) using a regular expression value obtained
format: Reference name $ {}
Here Insert Picture Description
$ {ABC} 1,2,3 value representative of the contents take
$ {abc_g1} take the first representative of a value,
$ {} abc_g2 value representative of the second take,
$ {} abc_g3 take the first representatives 3 values

to parameterize

(1)用户自定义变量Here Insert Picture Description
用户自定义变量中的定义的所有参数的值在测试计划的执行过程中不能发生取值的改变,因此一般仅将测试计划中不需要随迭代发生改变的参数(只取一次值的参数)设置在此处。

(2)用户参数(在“前置处理器”中添加)Here Insert Picture Description
与用户自定义变量不同的是,用户参数列表中的参数取值可以在测试计划执行过程中发生变化。
Here Insert Picture Description
修改线程数即可按顺序循环执行
(3)CSV data set Config(“配置元件“中添加)Here Insert Picture Description
对“输入用户名和密码”http请求进行CSV参数化进行演示
Here Insert Picture Description

Filename: 获取参数值的文本文件。
File Encoding: 文件编码方式,一般采用utf-8。
Variable Namesg: 从文本文件中获取内容的参数列表。参数列表中可以包含多个参数,用逗号分隔。
Ignore first line: 忽略第一行内容
Delimiter: 文本文件中分隔记录域的分隔符,“\t”表示tab键。
Allow quoted data?: 当该项值是False时,CSV Data Set Config原封不动地将文本文件中相应域的值取为参数值;当为Trues时,将处理文本中用双引号引用的部分,把双引号中的内容取为参数值。
Recycle on EOF: 当该项取值为True时,允许循环取值。当文件中的全部记录被取完后,重新从文件的第一行取值。为False时,根据stop thread on EOF的取值决定测试计划的执行行为。
Stop thread on EOF?: 当Recycle on EOF为true时,无论该项取何值,测试计划的执行行为相同;当Recycle on EOF为False时,该项值为True时,文件记录取完后,线程停止运行,如果该项取值为False,则线程后续执行时给定参数的取值为。
Here Insert Picture Description

Sharing mode:
All threads,该测试计划的所有线程共享csv文件中的记录(所有线程按照顺序取文件中的记录)。
Current thread group,该测试计划中的每个thread group中的所有线程共享csv文件中的记录。
Current thread,每个线程各自独立使用csv的记录
(4)函数助手 (选项>函数助手对话框)
Here Insert Picture Description
(5)计数器(配置元件>计数器)
Here Insert Picture Description
修改线程数,查看运行结果

Jmeter分布式测试

在使用Jmeter进行性能测试时,如果并发数比较大(比如最近项目需要支持1000并发),单台电脑的配置(CPU和内存)可能无法支持,这时可以使用Jmeter提供的分布式测试的功能。
一、Jmeter分布式执行原理:
  1、Jmeter分布式测试时,选择其中一台作为调度机(master),其它机器做为执行机(slave)。
  2、执行时,调度机会把脚本发送到每台执行机上,执行机拿到脚本后就开始执行,执行时不需要启动GUI,是通过命令行模式执行的。
  3、执行完成后,执行机会把结果回传给调度机,调度机收集所有执行机的信息并汇总。
二、执行机(slave)配置:
  1、slave机上需要安装Jmeter,具体如何安装这里不详细介绍了。
  2、添加环境变量:path=D:\B_TOOLS\apache-jmeter-2.13\bin (此处为你Jmeter的路径)
  3、检查Jmeter.properties文件中的remote_hosts=192.168.2.236:1099,端口也可以自定义
启动bin目录下的:jmeter-server.bat.
  4、执行机的IP和端口会在调度机里配置时用到。
  5、多台执行的话,重复1~4步骤就好。
三、调度机配置:
1.修改Bin目录下jmeter.properties文件remote_hosts=192.168.2.236:1099,多个IP时用“,”隔开
2.脚本:录制Bugfree登录界面脚本,添加“察看结果树”与“聚合报告”
3.打开Jmeter,选择“运行》远程启动”,查看聚合报告。
四、聚合报告结果分析:
Here Insert Picture Description

JDBC数据库性能测试

利用Jmeter对数据库的性能测试,对SQL语句的响应时间
(1)添加JDBC Connetction Configuration (测试计划>配置元件)
添加线程组
JDBC Request (线程组>Sampler)
(2)添加JDBC数据库驱动,拷贝mysql-connector-java-5.1.47-bin.jar到jmeter安装目录的lib文件夹下
Here Insert Picture Description
(3)JDBC Connetction Configuration配置
如何使用jmeter批量构造mysql测试
Here Insert Picture Description
Database URL:jdbc:mysql://127.0.0.1:3306/bugfree3?useZUnicode=true&characterEncoding=utf-8
JDBC Driver class:com.mysql.jdbc.Driver
Username:数据库登录用户名,我这里是root
Password:密码(如果没有密码,则不用填)
(4)采用SQLyog连接到Bugfree3数据库上,对bf_bug_info表进行查询操作
Here Insert Picture Description
(5)JDBC Request配置
Here Insert Picture Description
(6)添加“察看结果树”,查看数据库返回结果
(7)在“测试计划”中把jar添加Lib库中
Here Insert Picture Description
(8)添加“响应断言”
修改查询语句,添加“响应断言”(线程组>添加>断言>)
Here Insert Picture Description
添加“断言结果”(线程组>监听器)
Here Insert Picture Description
添加“断言持续时间”(线程组>断言持续时间),查看语句执行性能指标
Here Insert Picture Description
Here Insert Picture Description

Jmeter批量创建数据

在Bugfree数据库中创建一个score表(id,score)
首先在线程组中添加“用户参数”,添加变量,值采用“函数助手”产生Here Insert Picture Description
在JDBC Request中SQL语句引用变量
Here Insert Picture Description
修改线程数为10,运行后通过SQLyog查看数据库数据是否增加
Here Insert Picture Description

集合点\思考时间\事务\初始化\Http请求默认值 设置

添加“线程组”、“Http请求”、“察看结果树”
(1)添加“集合点” (线程组>定时器>Synchronizing Timer)
Here Insert Picture Description
(2)添加“思考时间” (请求与请求之间的等待时间)
固定定时器(Http请求>定时器>固定定时器)
Here Insert Picture Description
高斯定时器
Here Insert Picture Description
(3)添加“事务”(线程组>逻辑控制器>事务控制器)
Here Insert Picture Description
Generate parent sample 勾上只显示所有请求事务时间,不勾则单独显示每个请求事务时间
Here Insert Picture Description
(4)“初始化”设置(线程组>逻辑控制器>仅一次控制器)
Here Insert Picture Description
Here Insert Picture Description
(5)Http请求默认值
线程组>配置元件>HTTP请求默认值
Here Insert Picture Description
Here Insert Picture Description

元件作用域

详细介绍链接
组件执行顺序:
1.配置元件 (CSV、HTTP Cookie管理器、Http请求默认值)
2.前置处理器 (用户参数)
3.定时器 (固定定时器、高斯随机定时器、集合点)
4.取样器 (http请求)
5.后置处理器 (正则表达式)
6.断言 (响应断言)
7.监听器 (察看结果树、聚合报告、断言结果)
8.逻辑控制器(事务控制器、仅一次控制器)

作用域的原则是:
1.采样器(sampler):元件不和其它元件相互作用,因此不存在作用域的问题。
2.逻辑控制器(Logic Controller):元件只对其子节点中的取样器 和 逻辑控制器作用。
3.除采样器 和 逻辑控制器 元件外,其他6类元件,如果是某个sampler的子节点,则该元件只对其父子节点起作用。
4.除采样器和逻辑控制器元件外的其他6类元件,如果其父节点不是sampler ,则其作用域是该元件父节点下的其他所有后代节点(包括子节点,子节点的子节点等)。

测试计划和线程设置

Here Insert Picture Description
Here Insert Picture Description

Jmeter命令生成HTML报告

注意:提前要配置环境变量Path
Here Insert Picture Description
Jmeter命令生成HTML报告格式:
jmeter -n -t [jmx file] -l [results file] -e -o [path to output folder]

Examples (Windows):
jmeter.bat -n -t F: \ GitHub \ jmeter \ baidu_ search parameters of .jmx -l F: \ GitHub \ jmeter \ result.jtl -e -r -oc: \ tmp
command parameter parsing :
-n: Jmeter running non-GUI form
-t: source.jmx script path
-l: result.jtl operating results save path (.jtl), the file must not exist
-e: generate html reports at the end of the script
- r: set the distributed execution
-o: html directory to hold the report, noted that the directory must be empty.

Here Insert Picture Description
Here Insert Picture Description
Open the c: \ index.html analysis report content tmp \.

Published 44 original articles · won praise 1 · views 1414

Guess you like

Origin blog.csdn.net/cc_park/article/details/104188674