Jmeter (eight) - from entry to proficient - JMeter configuration components (detailed tutorial)

content

1 Introduction

2. Detailed explanation of common configuration components

3. Summary


1 Introduction

JMeter configuration elements can be used to initialize default values ​​and variables, read file data, set public request parameters, assign variable values, etc. for subsequent samplers to use. Will be processed during the initialization phase of its scope. The Config Element provides support for static data configuration and can set default values ​​and variables for the sampler.

First, let's take a look at the configuration elements of JMeter, the path: add-configuration elements; we can clearly see that there are 19 configuration elements in JMeter5, as shown in the following figure:

 

If you can't see the above picture clearly, Brother Hong summarized a mind map, about the configuration component types of JMeter5, as shown in the following figure:

 

Through the above understanding, we have a general understanding and understanding of the configuration components. Below, Brother Hong will share and explain some configuration components that are usually used in work to small partners or children's shoes.

2. Detailed explanation of common configuration components

  In this section, Brother Hong will explain the commonly used configuration components in detail from top to bottom .

2.1CSV Data Set Config

1. Let's take a look at what this CSV Data Set Config looks like, as shown in the following figure:

 

2. Detailed explanation and description of parameters, as shown in the following table:

parameter

describe

Is it required

Name

The descriptive name of this element displayed in the script

Yes

Filename

The name of the file to read. You can write an absolute path or a relative path (relative to the bin directory). If you write the file name directly, the file should be placed in the bin directory. For distributed testing, there should be the same CSV file in the corresponding directory on the host and remote

Yes

File Encoding

The encoding format when the file is read, if not filled, the encoding format of the operating system will be used

no

Ignore first line

Whether to ignore the first line, if there is no header in the csv file, select false

Yes

Variable Names

A list of variable names. Multiple variable names must be separated by a delimiter. If this is empty, the first line of the file is read and parsed as a list of column names

no

Delimiter

Parameter separator, which separates a line of data into multiple variables, the default is a comma, or "\t" can be used. If a row of data delimited has fewer values ​​than the variables defined in Vairable Names, those variables will retain their previous values ​​(if any)

Yes

Allow quoted data?

Whether to allow double quotes for variables, if allowed, variables can be enclosed in double quotes, and these variable names can contain delimiters

no

Recycle on EOF?

Whether to cyclically read the contents of the csv file, whether to re-read from the beginning of the file after reaching the end of the file; the default is true

Yes

Stop thread on EOF?

Whether to read the contents of the csv file in a loop, and whether the thread should terminate when the end of the file is reached; the default is true

Yes

Recycle on EOF?

When Recycle on EOF is False, stop the thread, when Recycle on EOF is True, this item is meaningless, the default is false

Yes

Sharing mode

1. All threads (default): In a thread group, each thread (user) takes values ​​in a unique order; 2. Current thread: In a thread group, each thread (user) takes values ​​in their own order; 3. Thread groups are independent, But each thread (user) in each thread group takes values ​​in a unique order;

Yes

3. The relationship between Recycle on EOF and Stop thread on EOF:

When Recycle on EOF selects true, Stop thread on EOF selects true and false without any meaning, because since the file has been set to be read continuously, the subsequent control stop is equivalent to failure; when Recycle on EOF selects false When the Stop thread on EOF is set to true, when the number of threads exceeds the number of parameters in the file, the actual number of requests is the number of parameters; when Recycle on EOF is set to false, Stop thread on EOF selects flase, and when the number of threads When the number of parameters in the file is exceeded, the actual number of requests is the number of threads, but when the number of threads exceeds the number of parameters, the result is still a failure because there are no parameters. 4. Sharing mode: If you want each thread to have its own independent set of values, then you need to create a series of data files and prepare a data file for each thread, such as test1.csv, test2.csv, etc., use the file name test$ {__threadNum}.csv with "sharing mode" set to "Current thread"

All threads: The file is shared among all threads.

Identifier: All threads share the same identity, share the same file. With 4 thread groups, testers can use a common ID to share files between two or more thread groups.

Current thread: Each file is opened individually for each thread.

Current thread group: Each file is opened once per thread group.

2.2HTTP Header Manager

Allows users to add or rewrite HTTP request headers. JMeter supports multiple header managers. Multiple header entries are combined into a header list and submitted to the server along with the http request.

Note: Knock on the blackboard, knock on the skull! ! !

(1) When there are multiple header managers, and there are header entries with the same name in different managers, the header entries of the managers at the front of the order will cover the latter ones;

(2) When there is only one header manager, but there are header entries with the same name in the manager, it will take effect at the same time;

1. Let's take a look at what this HTTP Header Manager looks like, as shown in the following figure:

 

2. Detailed explanation and description of parameters, as shown in the following table:

parameter

describe

Is it required

Name

The name of the request header, such as Content-Type

no

Value

The value of the request header, such as application/json

no

3. Common request headers, which can generally be captured and found in the browser, as shown in the following table:

2.3HTTP Cookie Manager

There are two main functions:

One function: store and send cookies like a web browser. If there is an HTTP request and the response contains a cookie, the cookie manager will automatically store the cookie, and then use the cookie in all subsequent requests for a specific web site. Can be viewed in the results tree.

Received cookies can be saved as variables, the property "CookieManager.save.cookie=true" must be defined. In addition, the cookie name will be prefixed with "COOKIE_" before being stored. To restore the previous processing method, define the attribute "CookieManager.name.prefix=" (one or more spaces).

If this function is enabled, the cookie named TEST can be referenced by ${COOKIE_TEST}. Manually add a cookie to the cookie manager (shared by all JMeter threads).

1. Let's take a look at what this HTTP Cookie Manager looks like, as shown in the following figure:

 

2. Detailed description of parameters, as shown in the following table:

parameter

describe

Is it required

Name

Display the name of this component description in the tree

Yes

Comments

Notes

no

Clear cookie each Iteration

Before each thread group runs, the cookie will be cleared, but if it is a manually added cookie, it will not be cleared

no

Cookie Policy

Choose the cookie management strategy, it is recommended to choose compatibility, strong compatibility

Yes

User Define cookie

User-defined cookies

no

2.4HTTP Cache Manager

  被用来为其作用域内的HTTP请求提供缓存功能,如果“Use Cache-Control/Expires header When ..."选中,那么会根据当前时间来选择,如果请求是”GET",而时间指向未来,那么采样器就会立即返回,而无须从远程服务器请求URL,这样是为了模拟浏览器的操作,请注意Cache-Control头必须是“pulic”的,并且只有"max-age"终结选项会被处理,如果请求文档自从其被缓存以来没有发生任何改变,那么响应包体就会为空。 

1、我们先来看看这个HTTP Cache Manager长得是啥样子,如下图所示:

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

树中显示此元件的描述性名称

Comments

注释

Clear Cache each iteration

如果选择此选项,则在线程开始时清除缓存。

Use Cache

如果选择此选项,则在线程开始时使用缓存。

Max Number

如果选择此选项,则在线程开始时最大缓存。

2.5HTTP Request Defaults

在实际测试计划中,我们经常会碰到Http Sampler请求有较多的参数与配置会重复,每一个Http Sampler都单独设置的话比较浪费时间和精力,为了节省工作量,JMeter提供了HTTP Request Defaults元件,用来把这些重复的部分封装起来,一次设置多次使用。可以设定一些缺省值,假设有10个请求,访问域名和端口都是一样的,那HTTP请求中就不再需要单独配置了,比较方便(增加脚本的移植性)。

这个元件可以设置HTTP请求控制器使用的默认值。例如,图中【服务器名称或IP】项目内填入了【example.com】,后面的HTTP请求如果IP也是example.com的话,那么只要将【服务器名称或IP】留空,那么这个字段将自动继承HTTP请求默认值中的值。其他诸如【协议】、【端口号】、【路径】等同此。

1、我们先来看看这个HTTP Request Defaults长得是啥样子,如下图所示:

 

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

用作标识一个取样器,建议使用一个见名知义的名称

Comments

注释

Protocol

协议,向目标服务器发送HTTP请求时的协议,可以是http或者是Https

IP

HTTP请求发送的目标服务器名称或者IP地址

Port Number

目标服务器端口

Path

目标URL路径(不包括服务器地址和端口)

Content encdoing

内容的编码方式

Parameter

参数

body data

参数

2.6Counter

计数器,顾名思义就是在测试执行过程中会记录迭代次数。可以在线程组任何位置创建,允许用户配置起点、最大值和增量。配置后,计数器将从起点循环到最大值,然后重新开始,直到线程结束。允许用户创建一个计数器,可在线程组中任何地方被引用。

1、我们先来看看这个Counter长得是啥样子,如下图所示:

 

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

控制器名称,可以随意设置

Comments

注释,可以随意设置

Starting value

启动,记录数量起始值

Increment

递增,记录迭代次数步长,1后是2,步长就是1

Maximum value

记录的最大值

Number format

计算器格式,可以是数字,例如000000(6位长度,000,000(6位长度,3位间隔开);字符加数字,例如CUST_000000(字符加6位数字 )

Exported Variable Name

引用变量名称,记数器记录的值可以存入的此引用名(变量),可供其他元件调用

Track counter independently for each user

与每位用户独立的跟踪计数器,每个线程都有自己的计数器,相互不干扰

Reset counter on each Thread Group Iteration

每次迭代复原计数器

2.7DNS Cache Manager

1、我们先来看看这个DNS Cache Manager长得是啥样子,如下图所示:

 

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

树中显示此元件的描述性名称

Comments

注释

Clear cache each iter

清除每个迭代的缓存,如果选择此选项,则每次启动新迭代时,都会清除每个线程的DNS缓存。

Use System DNS resolver

使用系统DNS解析器;将使用系统DNS解析器。为了正确工作,请编辑 $ JAVA_HOME / jre / lib / security / java.security并添加networkaddress.cache.ttl = 0

Use custom DNS resolver

使用自定义DNS解析器;将使用自定义DNS解析器(来自dnsjava库)。

2.8FTP Request Defaults

被用于设置FTP请求的默认值

1、我们先来看看这个FTP Request Defaults长得是啥样子,如下图所示:

2.9HTTP Authorization Manager

HTTP认证是一种安全机制,在客户端、浏览器或者程序向服务器发起请求时,需要提供用户名和密码且验证通过(拿到凭证)才能继续发起交互。

1、我们先来看看这个HTTP Authorization Manager长得是啥样子,如下图所示:

 

2.10JDBC Connection Configuration

1、我们先来看看这个JDBC Connection COnfiguration长得是啥样子,如下图所示:

2、关于JDBC Connection COnfiguration参数详细说明,可以参考宏哥的另一篇文章是非常详细的:传送门。 

2.11Java Request Defaults

1、我们先来看看这个Java Request Defaults长得是啥样子,如下图所示:

 

2.12Keystore Configuration

1、我们先来看看这个Keystore Configuration长得是啥样子,如下图所示:

 

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

树中显示此元件的描述性名称。可以默认

Comments

注释

Preload

预载,是否预加载秘钥库,设置为true通常是最佳选择

Variable name holding certificate alias

变量名称,将包含用于客户端证书身份验证的别名。例如,将从CSV数据集中填充变量值。在屏幕截图中,“ certificat_ssl”也将是CSV数据集中的变量。

Alias Start index

从0开始在Keystore中使用的第一个键的索引。

Alias End index

基于0的密钥库中要使用的最后一个密钥的索引。使用“变量名称持有证书别名”时,请确保其足够大,以便在启动时加载所有密钥。

2.13LDAP Extended Request Defaults

1、我们先来看看这个LDAP Extended Request Defaults长得是啥样子,如下图所示:

 

2.14LDAP Request Defaults

1、我们先来看看这个LDAP Request Defaults长得是啥样子,如下图所示:

 

2.15Login Config Element

1、我们先来看看这个Login Config Element长得是啥样子,如下图所示:

 

2.16Random Variable

1、我们先来看看这个Random Variable长得是啥样子,如下图所示:

 

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

树中显示的此元件的描述性名称。

Comments

注释

Variable Name

变量名,存储随机字符串的变量的名称。

Output Format

格式化字符串,要使用的java.text.DecimalFormat格式字符串。例如,“ 000”将生成至少3位数字,或者“ USER_000”将生成USER_nnn形式的输出。如果未指定,则默认为使用Long.toString()生成数字。

Minimum Value

最小值;生成的随机数的最小值(长整数)。

Maximum Value

最大值;生成的随机数的最大值(长整数)。

Seed for Random function

随机种子,随机数生成器的种子。默认值为当前时间,以毫秒为单位。如果在“将每个线程”设置为true的情况下使用相同的种子值,则与“ 随机” 类一样,您将为earch线程获得相同的值

Per Thread(User)?

每个线程,如果为False,则在线程组中的所有线程之间共享生成器。如果为True,则每个线程都有自己的随机生成器。

2.17Simple Config Element

1、我们先来看看这个Simple Config Element长得是啥样子,如下图所示:

 

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

树中显示此元件的描述名称

Comments

注释

Name

参数名称

Value

参数值

2.18TCP Sampler Config

TCP采样器配置为TCP采样器提供默认数据

1、我们先来看看这个TCP Sampler Config长得是啥样子,如下图所示:

 

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

树中显示此元件的描述性名称

Comments

注释

TCPClient classname

TCPClient类的名称,默认属性tcp.handler,使TCPClientImpl失败

Sever Name or IP

TCP服务器的名称或者IP

Port Number

使用的端口

Re-use connection

重用连接,如果选择,则连接保持打开状态,否则,在读取数据后将其关闭

Close connection

关闭连接,如果选择此项,则在运行采样器后将连接关闭

Set NoDelay

设置节点布局,应该设置nodelay

SO_LINGER

创建套接字时,以指定的延迟时间(以秒为单位)启用/禁用SO_LINGER。如果将“SO_LINGER"值设置为0,则则可以防止大量套接字处于TIME_WAT 的状态

End of line byte value

判断行结束的byte值,如果你指定的值大于127或者小于-128,则会跳过EOL检测。比如服务器端返回的字符串都是以回车符结尾,那么我们可以将该选项设置成10。

Text to send

文字发送,要发送的文字

Connect

连接超时(毫秒。0禁用)

Response

响应超时(毫秒。0禁用)

2.19User Defined Variables

如果您有多个线程组,请确保对不同的值使用不同的名称,因为UDV在线程组之间共享。同样,这些变量在处理完元素之后才可用,因此您不能引用在同一元素中定义的变量。您可以引用在早期UDV或测试计划中定义的变量。

1、我们先来看看这个User Defined Variable长得是啥样子,如下图所示:

 

2、参数详细说明,如下表所示:

参数

描述

是否必填

Name

树中显示此元件描述的名称

Comments

注释

User Define Variables

用户定义的变量。变量名称/值对。您需要在$ {...}结构的方括号内放置“名称”(Name)列下的字符串,以便以后使用变量。然后,整个$ {...}将由“值”列中的字符串替换

3.小结

好了,今天关于JMeter的配置元件就分享到这里,其中有些常用的要熟练掌握。

您的肯定就是我进步的动力。如果你感觉还不错,就请鼓励一下吧!

Guess you like

Origin blog.csdn.net/ZangKang1/article/details/124122509