Home Database Mysql Tutorial JMeter技巧集锦[组图]

JMeter技巧集锦[组图]

Jun 07, 2016 pm 03:41 PM
jmeter Skill use

JMeter 是一个流行的用于负载测试的开源工具, 具有许多有用的功能元件,如线程组(thread group), 定时器(timer), 和HTTP 取样 (sampler) 元件。 本文是对JMeter 用户手册的补充,而且提供了关于使用Jmeter的一些模拟元件开发质量测试脚本的指导。 本

  JMeter 是一个流行的用于负载测试的开源工具, 具有许多有用的功能元件,如线程组(thread group), 定时器(timer), 和HTTP 取样 (sampler) 元件。 本文是对JMeter 用户手册的补充,而且提供了关于使用Jmeter的一些模拟元件开发质量测试脚本的指导。
  
  本文同时也讨论了一项重要的内容:在指定了精确的响应时间要求后,如何来校验测试结果,非凡是在采用了置信区间分析这种严格的统计方式的情况下应如何操作。请注重,我假定本文的读者们了解关于Jmeter的基础知识,本文的例子基于Jmeter2。0。3版。 
  
    确定一个线程组的ramp-up period (Determine)
  

  Jmeter脚本的第一个要素是线程组(Thread Group),因此首先让我们往返顾一下。 正如图一所示,线程组需要设置以下参数: 
  ·线程数量。 
  ·ramp-up period。 
  ·运行测试的次数。 
  ·启动时间:立即或者预定的时间,假如是后者,线程组所包含的元素也要指定这个起止时间。
  
  

JMeter技巧集锦[组图]

  
  图 1。 JMeter 线程组(JMeter Thread Group)
  
  每个线程均独立运行测试计划。因此, 线程组常用来模拟并发用户访问。假如客户机没有足够的能力来模拟较重的负载,可以使用Jmeter的分布式测试功能来通过一个Jmeter控制台来远程控制多个Jmeter引擎完成测试。 
  
  参数 ramp-up period 用于告知JMeter 要在多长时间内建立全部的线程。默认值是0。假如未指定ramp-up period ,也就是说ramp-up period 为零, JMeter 将立即建立所有线程,假设ramp-up period 设置成T 秒, 全部线程数设置成N个, JMeter 将每隔T/N秒建立一个线程。 
  
  线程组的大部分参数是不言自明的,只有ramp-up period有些难以理解, 因为如何设置适当的值并不轻易。 首先,假如要使用大量线程的话,ramp-up period 一般不要设置成零。 因为假如设置成零,Jmeter将会在测试的开始就建立全部线程并立即发送访问请求, 这样一来就很轻易使服务器饱和,更重要的是会隐性地增加了负载,这就意味着服务器将可能过载,不是因为平均访问率高而是因为所有线程的第一次并发访问而引起的不正常的初始访问峰值,可以通过Jmeter的聚合报告监听器看到这种现象。 
  这种异常不是我们需要的,因此,确定一个合理的ramp-up period 的规则就是让初始点击率接近平均点击率。当然,也许需要运行一些测试来确定合理访问量。 
  
  基于同样的原因,过大的ramp-up period 也是不恰当的,因为将会降低访问峰值的负载,换句话说,在一些线程还未启动时,初期启动的部分线程可能已经结束了。 
  
  那么,如何检验ramp-up period I太小了或者太大了呢?首先,推测一下平均点击率并用总线程除点击率来计算初始的ramp-up period。 例如,假设线程数为100, 估计的点击率为每秒10次, 那么估计的理想ramp-up period 就是 100/10 = 10 秒。 那么,应怎样来提出一个合理的估算点击率呢?没有什么好办法,必须通过运行一次测试脚本来获得。
  
  其次, 在测试计划(test plan)中增加一个聚合报告监听器,如图2所示,其中包含了所有独立的访问请求(一个samplers)的平均点击率。 第一次取样的点击率(如http请求)与ramp-up period 和线程数量密切相关。通过调整ramp-up period 可以使首次取样的奠基率接近平均取样的点击率。 
  
  

JMeter技巧集锦[组图]

点击查看大图


  图2 JMeter 聚合报告 
  
  第三, 查验一下Jmeter日志(文件位置:JMeter_Home_Directory/bin) 的最后一个线程开始时第一个线程是否真正结束了,二者的时间差是否正常。
  
  总之,是否能确定一个适当的ramp-up time 取决于以下两条规则: 
  ·第一个取样器的点击率(hit rate)是否接近其他取样器的平均值,从而能否避免ramp-up period 过小。
  ·在最后一个线程启动时,第一个线程是否在真正结束了,最好二者的时间要尽可能的长,以避免ramp-up period过大。
  
  有时,这两条规则的结论会互相冲突。 这就意味着无法找到同时满足两条规则的合适的ramp-up period。 糟糕的测试计划通常会导致这些问题,这是因为在这样的测试计划里,取样器将不能充分地采集数据,可能因为测试计划执行时间太短并且线程会很快的运行结束。 
  
  
  
    用户思考时间(User think time),定时器,和代理服务器(proxy server)
  

  在负载测试中需要考虑的的一个重要要素是思考时间(think time), 也就是在两次成功的访问请求之间的暂停时间。 有多种情形挥发导致延迟的发生: 用户需要时间阅读文字内容,或者填表, 或者查找正确的链接等。未认真考虑思考时间经常会导致测试结果的失真。例如,估计数值不恰当,也就是被测系统可以支持的最多用户量(并发用户)看起来似乎要少一些等。 
  
  Jmeter提供了一整套的计时器(timer)来模拟思考时间(think time), 但是仍然存在一个问题:: 如何确定适当的思考时间呢?幸运的是, JMeter 提供了一个不错的答案:使用 JMeter HTTP 代理服务器(Proxy Server)元件。 
  
  代理服务器会记录在使用一个普通的浏览器(如Firefox 或 Internet EXPlorer)浏览一个web应用时的操作。 另外, JMeter 在记录操作的同时会建立一个测试计划(test plan)。 这个功能能提供以下便利: 
  
  ·不必手工建立HTTP 访问请求, 尤其是当要设置一些令人乏味的参数时(然而,非英文的参数也许不能正常工作) 。JMeter 将会录制包括隐含字段(hidden fields)在内的所有内容。 
  
  ·在生成的测试计划中,Jmeter会包含浏览器生成的所有的 HTTP 报头,如User-Agent (e。g。, Mozilla/4。0), 或AcceptLanguage (e。g。, zh-tw,en-us;q=0。7,zh-cn;q=0。3)等。 
  
  ·JMeter 会根据设置在录制操作的同时建立一些定时器,其延迟时间是完全根据真实的操作来设置的
  现在让我们来看一下如何配置Jmeter的录制功能。 在JMeter 的控制台上, 在工作台(WorkBench)元件上单击右键,然后选择”add the HTTP Proxy Server “。 注重是在WorkBench 上单击右键而不是在Test Plan上, 因为现在是要为记录操作进行配置而不是要运行测试计划。  HTTP Proxy Server 的实现原理就是通过配置浏览器的代理服务器而使所有的访问请求通过JMeter发送(,因而被Jmeter把访问过程录制下来)。 
  
  如图3所示, HTTP代理服务器(HTTP Proxy Server)元件的一些参数必须被配置: 
  
  ·端口(port): 代理服务器的监听端口 
  
  ·目标控制器(Target Controller): 是代理用于存储生成的数据的控制器,默认情况下,, JMeter 将会在当前的测试计划中找一个记录用的控制器用于存储,此外也可以在下拉菜单中选择任意控制起来存储,通常默认值就可以了。 
  
  ·分组(Grouping): 确定在测试计划中如何来为生成的元件分组。 有多个选项, 一般可以选择“只存储每个组的第一个样本”,否则,将会原样录制URLs,包括包含图像和javascripts脚本的页面。当然 也可以尝试一下默认值“不对样本分组”("Do not group samples"),来看一下JMeter 建立的原版的测试计划。 
  
  ·包含模式(Patterns to Include) 和 排除模式(Patterns to Exclude) :帮助过滤一些不需要的访问请求。
  
  


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Are there any tips for drawing lucky bags on Douyin? How? Are there any tips for drawing lucky bags on Douyin? How? Mar 07, 2024 pm 06:52 PM

Lucky bag activities on Douyin have always been popular among users. By participating, you can not only get various discounts and gifts, but also have the chance to win big prizes. However, newbies may not understand how to draw lucky bags effectively and increase their chances of winning. This article will share with you some tips for drawing lucky bags on Douyin to help you better enjoy the fun of drawing and increase the possibility of winning big prizes. 1. Choose popular lucky bag recommendations and follow the official website: On the Douyin platform, the official often launches some popular lucky bag activities, which can often be seen on the homepage or related channels. These events are usually very popular and the prizes are generous. Therefore, it is a wise move to pay attention to official recommendations. Before opening the lucky bag, it is recommended that you read the comments and reviews of other users. By understanding other people’s lottery winning experiences and opinions on lucky bags

Win11 Tips Sharing: Skip Microsoft Account Login with One Trick Win11 Tips Sharing: Skip Microsoft Account Login with One Trick Mar 27, 2024 pm 02:57 PM

Win11 Tips Sharing: One trick to skip Microsoft account login Windows 11 is the latest operating system launched by Microsoft, with a new design style and many practical functions. However, for some users, having to log in to their Microsoft account every time they boot up the system can be a bit annoying. If you are one of them, you might as well try the following tips, which will allow you to skip logging in with a Microsoft account and enter the desktop interface directly. First, we need to create a local account in the system to log in instead of a Microsoft account. The advantage of doing this is

A must-have for veterans: Tips and precautions for * and & in C language A must-have for veterans: Tips and precautions for * and & in C language Apr 04, 2024 am 08:21 AM

In C language, it represents a pointer, which stores the address of other variables; & represents the address operator, which returns the memory address of a variable. Tips for using pointers include defining pointers, dereferencing pointers, and ensuring that pointers point to valid addresses; tips for using address operators & include obtaining variable addresses, and returning the address of the first element of the array when obtaining the address of an array element. A practical example demonstrating the use of pointer and address operators to reverse a string.

What are the tips for novices to create forms? What are the tips for novices to create forms? Mar 21, 2024 am 09:11 AM

We often create and edit tables in excel, but as a novice who has just come into contact with the software, how to use excel to create tables is not as easy as it is for us. Below, we will conduct some drills on some steps of table creation that novices, that is, beginners, need to master. We hope it will be helpful to those in need. A sample form for beginners is shown below: Let’s see how to complete it! 1. There are two methods to create a new excel document. You can right-click the mouse on a blank location on the [Desktop] - [New] - [xls] file. You can also [Start]-[All Programs]-[Microsoft Office]-[Microsoft Excel 20**] 2. Double-click our new ex

VSCode Getting Started Guide: A must-read for beginners to quickly master usage skills! VSCode Getting Started Guide: A must-read for beginners to quickly master usage skills! Mar 26, 2024 am 08:21 AM

VSCode (Visual Studio Code) is an open source code editor developed by Microsoft. It has powerful functions and rich plug-in support, making it one of the preferred tools for developers. This article will provide an introductory guide for beginners to help them quickly master the skills of using VSCode. In this article, we will introduce how to install VSCode, basic editing operations, shortcut keys, plug-in installation, etc., and provide readers with specific code examples. 1. Install VSCode first, we need

Oracle database query skills: get only one piece of duplicate data Oracle database query skills: get only one piece of duplicate data Mar 08, 2024 pm 01:33 PM

Oracle database query skills: To obtain only one piece of duplicate data, specific code examples are required. In actual database queries, we often encounter situations where we need to obtain the only piece of data from duplicate data. This article will introduce how to use Oracle database techniques to obtain only one record in duplicate data, and provide specific code examples. Scenario Description Suppose we have a table named employee, which contains employee information. There may be duplicate employee information. We need to find all duplicates

PHP programming skills: How to jump to the web page within 3 seconds PHP programming skills: How to jump to the web page within 3 seconds Mar 24, 2024 am 09:18 AM

Title: PHP Programming Tips: How to Jump to a Web Page within 3 Seconds In web development, we often encounter situations where we need to automatically jump to another page within a certain period of time. This article will introduce how to use PHP to implement programming techniques to jump to a page within 3 seconds, and provide specific code examples. First of all, the basic principle of page jump is realized through the Location field in the HTTP response header. By setting this field, the browser can automatically jump to the specified page. Below is a simple example demonstrating how to use P

Win11 Tricks Revealed: How to Bypass Microsoft Account Login Win11 Tricks Revealed: How to Bypass Microsoft Account Login Mar 27, 2024 pm 07:57 PM

Win11 tricks revealed: How to bypass Microsoft account login Recently, Microsoft launched a new operating system Windows11, which has attracted widespread attention. Compared with previous versions, Windows 11 has made many new adjustments in terms of interface design and functional improvements, but it has also caused some controversy. The most eye-catching point is that it forces users to log in to the system with a Microsoft account. For some users, they may be more accustomed to logging in with a local account and are unwilling to bind their personal information to a Microsoft account.

See all articles