学英语学压测:03jmeter组件-采样器、逻辑控制器

📢📢📢:先看关键单词,再看英文,最后看中文总结,再回头看一遍英文原文,效果更佳!!

关键词

|-----------------------|-----------|--------------------------------|
| assertion | 断言 | /əˈsɜrʃən/ |
| configuration element | 配置元素 | /ˌkɒn.fɪˈɡjʊr.eɪ.ʃən ˈɛlɪmənt/ |
| controller | 控制器 | /kənˈtroʊlər/ |
| cookie manager | cookie管理器 | /ˈkʊki ˈmænɪdʒər/ |
| default | 默认值 | /dɪˈfɔlt/ |
| interleave controller | 交错控制器 | /ˈɪntərˌliv kənˈtroʊlər/ |
| listener | 监听器 | /ˈlɪsənər/ |
| logical controller | 逻辑控制器 | /ˈlɒdʒɪkəl kənˈtroʊlər/ |
| once only controller | 仅一次控制器 | /wʌns ˈoʊnli kənˈtroʊlər/ |
| sampler | 采样器 | /ˈsæmplər/ |
| thread group | 线程组 | /θrɛd ɡruːp/ |

控制器:包括采样器和逻辑控制器

JMeter has two types of Controllers: Samplers and Logical Controllers. These drive the processing of a test.

Samplers tell JMeter to send requests to a server. For example, add an HTTP Request Sampler if you want JMeter to send an HTTP request. You can also customize a request by adding one or more Configuration Elements to a Sampler. For more information, see Samplers.

Logical Controllers let you customize the logic that JMeter uses to decide when to send requests. For example, you can add an Interleave Logic Controller to alternate between two HTTP Request Samplers. For more information, see Logical Controllers.

采样器:

Samplers tell JMeter to send requests to a server and wait for a response. They are processed in the order they appear in the tree. Controllers can be used to modify the number of repetitions of a sampler.

JMeter samplers include:

  • FTP Request
  • HTTP Request (can be used for SOAP or REST Webservice also)
  • JDBC Request
  • Java object request
  • JMS request
  • JUnit Test request
  • LDAP Request
  • Mail request
  • OS Process request
  • TCP request

Each sampler has several properties you can set. You can further customize a sampler by adding one or more Configuration Elements to the Test Plan.

If you are going to send multiple requests of the same type (for example, HTTP Request) to the same server, consider using a Defaults Configuration Element. Each controller has one or more Defaults elements (see below).

Remember to add a Listener to your test plan to view and/or store the results of your requests to disk.

If you are interested in having JMeter perform basic validation on the response of your request, add an Assertion to the sampler. For example, in stress testing a web application, the server may return a successful "HTTP Response" code, but the page may have errors on it or may be missing sections. You could add assertions to check for certain HTML tags, common error strings, and so on. JMeter lets you create these assertions using regular expressions.

逻辑控制器

Logic Controllers let you customize the logic that JMeter uses to decide when to send requests. Logic Controllers can change the order of requests coming from their child elements. They can modify the requests themselves, cause JMeter to repeat requests, etc.

To understand the effect of Logic Controllers on a test plan, consider the following test tree:

  • Test Plan
    • Thread Group
      • Once Only Controller
      • Load Search Page (HTTP Sampler)
      • Interleave Controller
        • Search "A" (HTTP Sampler)
        • Search "B" (HTTP Sampler)
        • HTTP default request (Configuration Element)
      • HTTP default request (Configuration Element)
      • Cookie Manager (Configuration Element)

The first thing about this test is that the login request will be executed only the first time through. Subsequent iterations will skip it. This is due to the effects of the Once Only Controller.

After the login, the next Sampler loads the search page (imagine a web application where the user logs in, and then goes to a search page to do a search). This is just a simple request, not filtered through any Logic Controller.

After loading the search page, we want to do a search. Actually, we want to do two different searches. However, we want to re-load the search page itself between each search. We could do this by having 4 simple HTTP request elements (load search, search "A", load search, search "B"). Instead, we use the Interleave Controller which passes on one child request each time through the test. It keeps the ordering (i.e. it doesn't pass one on at random, but "remembers" its place) of its child elements. Interleaving 2 child requests may be overkill, but there could easily have been 8, or 20 child requests.

Note the HTTP Request Defaults that belongs to the Interleave Controller. Imagine that "Search A" and "Search B" share the same PATH info (an HTTP request specification includes domain, port, method, protocol, path, and arguments, plus other optional items). This makes sense - both are search requests, hitting the same back-end search engine (a servlet or cgi-script, let's say). Rather than configure both HTTP Samplers with the same information in their PATH field, we can abstract that information out to a single Configuration Element. When the Interleave Controller "passes on" requests from "Search A" or "Search B", it will fill in the blanks with values from the HTTP default request Configuration Element. So, we leave the PATH field blank for those requests, and put that information into the Configuration Element. In this case, this is a minor benefit at best, but it demonstrates the feature.

The next element in the tree is another HTTP default request, this time added to the Thread Group itself. The Thread Group has a built-in Logic Controller, and thus, it uses this Configuration Element exactly as described above. It fills in the blanks of any Request that passes through. It is extremely useful in web testing to leave the DOMAIN field blank in all your HTTP Sampler elements, and instead, put that information into an HTTP default request element, added to the Thread Group. By doing so, you can test your application on a different server simply by changing one field in your Test Plan. Otherwise, you'd have to edit each and every Sampler.

The last element is a HTTP Cookie Manager. A Cookie Manager should be added to all web tests - otherwise JMeter will ignore cookies. By adding it at the Thread Group level, we ensure that all HTTP requests will share the same cookies.

Logic Controllers can be combined to achieve various results. See the list of built-in Logic Controllers.

总结

  1. JMeter有两种类型的控制器:采样器和逻辑控制器。
  2. 采样器:告诉JMeter向服务器发送请求并等待响应,按它们在测试树中的顺序处理。
  3. 常见的采样器:包括FTP请求、HTTP请求、JDBC请求、Java对象请求、JMS请求、JUnit测试请求、LDAP请求、邮件请求、操作系统进程请求和TCP请求。
  4. 配置元素:可以通过添加一个或多个配置元素来自定义采样器。
  5. 默认配置元素:如果要向同一服务器发送多个相同类型的请求,考虑使用默认配置元素。
  6. 监听器:添加到测试计划中以查看和/或将请求结果存储到磁盘。
  7. 断言:可以在响应中执行基本验证,例如检查特定HTML标签或常见错误字符串。
  8. 逻辑控制器:让你可以自定义JMeter用来决定何时发送请求的逻辑,改变请求的顺序、修改请求、重复请求等。
  9. Once Only Controller:只在第一次迭代时执行其子请求。
  10. Interleave Controller:在其子请求之间交替,每次通过测试时传递一个子请求。
  11. HTTP Request Defaults:可以将共享的HTTP请求信息抽象到一个配置元素中,以减少重复配置。
  12. Cookie Manager:应添加到所有Web测试中,否则JMeter将忽略cookies。
  13. 组合逻辑控制器:可以结合使用来实现各种结果。
相关推荐
记录测试点滴1 小时前
【JMeter】配置元件Config Element
数据库·jmeter
cmgdxrz4 小时前
性能测试04|JMeter:连接数据库、逻辑控制器、定时器
jmeter
zfj3215 小时前
JMeter线程组Duration和循环次数设置冲突后,Duration优先级高
jmeter·duration·循环次数·线程组·持续时间
小大力10 小时前
简单的jmeter数据请求学习
java·学习·jmeter
测试者家园1 天前
JMeter + Grafana +InfluxDB性能监控 (二)
自动化测试·软件测试·jmeter·性能测试·grafana·性能监控·质量效能
讓丄帝愛伱1 天前
使用JMeter对Linux生产服务器进行压力测试
linux·jmeter·压力测试
云采1 天前
JMeter 的 If Controller:开启性能测试的智能大门
测试工具·jmeter·压力测试
zfj3212 天前
学英语学压测:02jmeter组件-测试计划和线程组&ramp-up参数的作用
jmeter·压测·线程组·测试计划·ramp-up
m0_7Ella2 天前
Jmeter-性能测试工具的安装教程
测试工具·jmeter·性能测试