如何知道Jmeter中每个用户的每个请求的结束时间

时间:2014-04-18 02:56:02

标签: jmeter

我正在使用Jmeter,并希望为每个用户确定每个请求的结束时间。

请看一下我的测试计划:

线程组:2个用户 循环:1

2 HTTP请求(request_1,request_2)


开始测试Web性能,查看结果树显示:4个结果(request_1为2,request_2为2)

request_2:1次通过,1次失败。查看结果树的请求表,我看到:

Thread Name: jp@gc - Stepping Thread Group 1-1
Sample Start: 2014-04-18 09:28:06 ICT
Load time: 1100554
Latency: 550450
Size in bytes: 408190
Headers size in bytes: 4774
Body size in bytes: 403416
Sample Count: 1
Error Count: 0
Response code: 200
Response message: OK

Response headers:
HTTP/1.1 200 OK
Date: Fri, 18 Apr 2014 02:28:15 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
Set-Cookie: ls23166422738597439695-runtime-publicportal=h4knpfldt76e3kvmunrn5i4u16; path=/limesurvey/
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Last-Modified: Fri, 18 Apr 2014 02:36:09 GMT
Cache-Control: post-check=0, pre-check=0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8


HTTPSampleResult fields:
ContentType: text/html; charset=utf-8
DataEncoding: utf-8

问题是:

  1. 如何识别导致request_2失败的时间?以及如何为每个用户显示每个请求的结束时间?

  2. 如何在Jmeter的日志面板中显示信息(在GUI上启用DEbug日志模式),例如"这是错误....由于..."

  3. 此外,如在日志面板(GUI中的活动日志调试)中,日志条目停留在线程1-n(n = 1,2 ...)的某个时间,在30秒之后,日志是继续显示。所以,我想知道这次,Web服务器有错误,而在这个时候,Jmeter仍然发送请求或等待Web服务器响应?

  4. 感谢。

1 个答案:

答案 0 :(得分:2)

  1. 可以通过Beanshell Pre Processor完成,您可以将其添加为任何“有趣”请求的子代。示例代码如下所示:

       import java.util.Date;
    
       long end_time_ms = prev.getEndTime(); // obtain sampler end time (in milliseconds from 1st Jan 1970)
       Date end_time_date = new Date(end_time_ms); //convert it to human-readable date if you prefer 
    
       String response_message = prev.getResponseMessage(); // get initial response message
    
       StringBuilder response = new StringBuilder(); // initialize StringBuilder to construct new response
       response.append(response_message); // add initial response message
       response.append(System.getProperty("line.separator")); // add new line
       response.append("Thread finished at: ").append(end_time_date); // add thread finish date
       prev.setResponseMessage(response.toString()); // set new response message
               log.info("Thread finished at:" + end_time_date"); // to print it to the log
    
  2. 请参阅上面的Beanshell代码和图片,了解UI影响

  3. Beanshell Post Processor Response Message Change Demo

    除了开发或调试测试之外,

    从不使用GUI。如果您想在日志中添加内容,请使用上面的log.info("something");或JMeter __log()函数