栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

与JMeter相比,Apache httpclient 4.1慢

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

与JMeter相比,Apache httpclient 4.1慢

如您所见(或未从图像中看到),将jmeter与一起使用时,平均时间为712ms

View Results in aTable
。请注意,此侦听器不会仅输出请求统计信息,而仅显示响应主体。

这是我的Java代码:

public static void main(String[] args) throws Exception{     long totalTimeMS = 0;        for (int i = 0; i < 10; i++) {        long startTime = System.currentTimeMillis();        HttpGet get = new HttpGet("http://stackoverflow.com");        HttpClient client = new DefaultHttpClient();        client.execute(get);        long endTime = System.currentTimeMillis();        long duration = (endTime-startTime);        totalTimeMS +=duration;        System.out.format("Duration %d msn", duration);        }        System.out.format("Average time is %d ms", (totalTimeMS/10));    }

因此,我也不关心响应主体。但是这里是结果(更快):

Duration 615 msDuration 263 msDuration 264 msDuration 262 msDuration 268 msDuration 266 msDuration 265 msDuration 266 msDuration 268 msDuration 263 msAverage time is 300 ms

现在在使用jmeter的另一种情况下,

View Results in a Tree
当您可以实际看到响应主体加上时,
View Results in aTable
因为我们仍然需要时间。

我不会附上屏幕截图,因为答案将变得难以理解,但是这次的平均时间

812 ms
比以前多了100毫秒。

现在,关心响应主体的Java代码(新方法):

public static String convertStreamToString(InputStream is) throws IOException {        if (is != null) { StringBuilder sb = new StringBuilder(); String line; try {     BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));     while ((line = reader.readLine()) != null) {         sb.append(line).append("n");     } } finally {     is.close(); } return sb.toString();        } else { return "";        }    }

而且我已经稍微修改了前面的代码,因此它可以打印出响应,模拟jmeter行为,并发布相关部分:

HttpGet get = new HttpGet("http://stackoverflow.com");        HttpClient client = new DefaultHttpClient();        HttpResponse response = client.execute(get);        long endTime = System.currentTimeMillis();        long duration = (endTime-startTime);        totalTimeMS +=duration;        System.out.println(convertStreamToString(response.getEntity().getContent()));        System.out.format("Duration %d msn", duration);

结果如下:

Duration 678 ms  + (including printing of response body)Duration 264 ms + (including printing of response body)Duration 269 ms + (including printing of response body)Duration 262 ms + (including printing of response body)Duration 263 ms + (including printing of response body)Duration 265 ms + (including printing of response body)Duration 262 ms + (including printing of response body)Duration 267 ms + (including printing of response body)Duration 264 ms + (including printing of response body)Duration 264 ms + (including printing of response body)Average time is 305 ms

响应时间增加了

5 ms
。所以我不知道jmeter如何比普通的Java代码更快。无论如何,jmeter确实是很棒的工具,是最好的工具之一(免费)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368326.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号