You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JMeter 5.2压测出现NoHttpResponseException问题求解决

解决JMeter 5.2高并发下的org.apache.http.NoHttpResponseException问题

问题背景

你在使用JMeter 5.2对Web应用做负载测试时,线程数超过500后遇到了org.apache.http.NoHttpResponseException: server-address:80 failed to respond异常,已经做了以下配置:

  • 在user.properties中设置httpclient4.retrycount=1、hc.parameters.file=hc.parameters
  • 在hc.parameters中设置http.connection.stalecheck$Boolean=true
  • HTTP请求客户端实现选择httpClient4

完整异常栈信息:

org.apache.http.NoHttpResponseException: server-address:80 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:850)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:561)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:67)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1282)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1271)
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:627)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:551)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:490)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257)
at java.lang.Thread.run(Unknown Source)

针对性解决方法

这个异常本质是客户端与服务器的连接在服务器返回响应前就被断开,高并发场景下通常和连接池资源不足、服务器过载、TCP连接配置不合理有关。以下是具体的解决方案:

1. 扩容JMeter HttpClient4的连接池

默认的HttpClient连接池大小不足以支撑500并发线程,需要调整hc.parameters中的参数:

  • 添加http.connection-manager.max-total=1000(全局最大连接数,建议设为线程数的1.5-2倍)
  • 添加http.connection-manager.max-per-route=600(单个目标服务器的最大连接数,至少大于你的线程数500)
  • 添加http.connection-manager.timeout=30000(从连接池获取连接的超时时间,单位毫秒)

修改后重启JMeter生效。

2. 增强重试与超时配置

你已经开启了重试机制,可以进一步优化user.properties中的参数:

  • 调大重试次数:httpclient4.retrycount=3(仅对幂等请求适用,比如GET、PUT,根据业务场景调整)
  • 开启全错误重试:httpclient4.retryonallerrors=true(让JMeter对更多类型的错误进行重试)
  • 延长连接与socket超时:
    httpclient4.connection_timeout=60000
    httpclient4.socket_timeout=60000
    
    避免因服务器响应慢导致连接被主动断开。

3. 优化JMeter线程组启动策略

如果线程数瞬间拉满到500,服务器可能因突发过载断开连接:

  • 延长Ramp-Up时间:比如设置为60秒,让JMeter在60秒内逐步启动500个线程,给服务器缓冲时间
  • 添加Constant Timer:在HTTP请求前添加固定定时器,比如每个请求间隔50毫秒,平滑并发压力

4. 检查并优化服务器端配置

高并发下服务器资源耗尽是核心诱因,需要检查目标Web服务器的配置:

  • 应用服务器(如Tomcat):调整server.xml中的maxThreads(建议设为200-500,根据服务器CPU核心数)、acceptCount(等待队列大小,建议设为100-200)
  • Web服务器(如Nginx):调整nginx.conf中的worker_connections(每个worker进程的最大连接数,建议设为10240以上)、keepalive_timeout(适当缩短至60秒,避免连接长时间占用)
  • Linux TCP内核参数:在服务器上调整以下参数,加速TIME_WAIT连接回收:
    echo "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
    echo "net.ipv4.tcp_tw_recycle = 1" >> /etc/sysctl.conf
    echo "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
    sysctl -p
    

5. 其他优化建议

  • 关闭JMeter的GUI模式,改用命令行运行:jmeter -n -t testplan.jmx -l result.jtl,GUI模式会消耗更多本地资源,影响并发性能
  • 确保JMeter运行机器的资源充足:CPU、内存、网络带宽都要满足500并发的需求,避免客户端机器先成为瓶颈
  • 检查服务器端防火墙或负载均衡的并发连接数限制,比如防火墙的连接阈值、负载均衡的最大连接数设置

内容的提问来源于stack exchange,提问作者Mojackoo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:45:11