有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

jmeter响应时间和我在日志文件中看到的时间之间的java差异

我在stack overflow上搜索过,但没有找到任何接近我需要的内容,所以如果重复,请告诉我,我将删除此帖子

我有一个web应用程序,它是一个单一的REST服务,只执行线程。睡眠(10000)。如果该方法只休眠10秒,那么我的所有请求的平均响应时间应该是10-11秒,对吗

为了在JMeter上测试它,通常我使用200个线程和5秒的爬升。当测试开始时,我的平均响应时间保持在10秒,但在100个请求之后,它开始增加,直到35-42秒

我非常担心我的实现,所以我在方法的第一行添加了一个日期,并打印一个日志来显示它的开始和结束时间。所有日志信息显示请求的持续时间为10秒

public Response go(@MultipartForm FileUploadForm form){
    Date start = new Date();
    try  {
        Thread.sleep(10000);
        logger.info("Time " + sdf.format(start) + " - " + sdf.format(new Date()));
    } catch (Exception e){
        logger.error("Error:", e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
    return Response.ok("OK").build();
}

我想知道为什么Jmeter会增加响应时间,而我的日志会显示我期望的时间。Jmeter可能有问题,或者我真的需要担心我的服务

先谢谢你


测试计划

Thread Group

HTTP Request

BeanShell PreProcessor

BeanShell PostProcessor


共 (2) 个答案

  1. # 1 楼答案

    检查你的延迟指标。根据JMeter Glossary

    Latency. JMeter measures the latency from just before sending the request to just after the first response has been received. Thus the time includes all the processing needed to assemble the request as well as assembling the first part of the response, which in general will be longer than one byte. Protocol analysers (such as Wireshark) measure the time when bytes are actually sent/received over the interface. The JMeter time should be closer to that which is experienced by a browser or other application client.

    所以Elapsed Time(JMeter向您展示的)是Response Time+Latency

    我认为你正在经历How to Analyze the Results of a Load Test指南中描述的情况