Jmeter返回org.apache.http.NoHttpResponseException: The target server failed to respond解决办法
1、问题:这段时间使用jmeter压测时(300个请求,持续压300s,加速期10s),压力平稳时偶然错误,部分请求失败事务报错信息如下
org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:95)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:61)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
at org.apache.jmeter.protocol.http.sampler.MeasuringConnectionManager$MeasuredConnection.receiveResponseHeader(MeasuringConnectionManager.java:201)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:715)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:520)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:517)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:331)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
at java.lang.Thread.run(Unknown Source)
2、原因:在JMeter下,发送http 请求时,默认选择了use keepAlive(Keep-Alive通俗地讲,就是所谓的持久连接,对于http这种大量的短连接的服务来说,开启持久连接的好处可节省大量的TCP连接过程的开销,据apache的官方文档称对包含大量图片的HTML文档造成的延时起到50%的加速作用),这个是连接协议,JMeter坑就在这里,默认勾选了这个(如果不勾选的话,也不会保存),但其配置JMeter.properties中的时间设置默认却是注销的,不会等待,一旦连接空闲,则立即断开了,导致压测中出现了事务失败的情形。
可访问https://wiki.apache.org/jmeter/JMeterSocketClosed查看官网解释
3、解决方法:
找到jmeter安装路径D:\apache-jmeter-3.2\bin下的jmeter.properties,编辑,设置httpclient4.idletimeout=<time in ms>,注意单位是ms,设置成觉得合理的时间,一般可设置成10-60s(表示连接空闲10s后才会断开)。修改完成后再次压测,错误就没出现。
例:httpclient4.idletimeout=3000,意思是连接空闲3s才会断开
4、KeepAlive
日常在浏览器查看请求头也可看到KeepAlive,本章重点不在这里,有兴趣可参考
http://blog.csdn.net/gaoshanliushui2009/article/details/8020240
http://liuzhigong.blog.163.com/blog/static/1782723752011412551547/