首页 性能测试 性能测试 PTS 3.0 服务支持 常见问题 JMeter 为什么采样日志中报java.net.SocketException: Socket closed错误?

为什么采样日志中报java.net.SocketException: Socket closed错误?

更新时间: 2024-09-27 16:08:59

问题现象

如果压测的是HTTPS接口,同时在压测进行过程中出现RT(响应时间)逐渐变高,TPS和成功率都有跌零或者相应的趋势。

这时,打开采样日志看到的如下报错信息:

java.net.SocketException: Socket closed
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:542)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
at org.apache.jmeter.protocol.http.sampler.LazySchemeSocketFactory.connectSocket(LazySchemeSocketFactory.java:97)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
at org.apache.jmeter.protocol.http.sampler.hc.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:318)
at org.apache.jmeter.protocol.http.sampler.MeasuringConnectionManager$MeasuredConnection.open(MeasuringConnectionManager.java:114)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:695)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:454)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1189)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1178)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:498)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:424)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:255)
at java.lang.Thread.run(Thread.java:766)
            

查看采样日志的Timing瀑布流,发现时间都耗费在连接建立阶段。

可能原因

引起java.net.SocketException: Socket closed错误的原因通常是未设置连接的超时时间。

解决方案

如果在HTTP Request Sampler的Basic里选中了Use KeepAlive,则建议您在Advanced页签下设置如下参数:

  • 选择ImplementationHttpClient4

  • Connect设置一个10秒~60秒的值,作为连接空闲超时时间,避免由于没收到被压测端返回的Keep-Alive的Header而导致连接断开。

image

更多信息,请参见JMeter Socket相关资料

上一篇: JMeter压测中的数据是如何统计的? 下一篇: 为什么JMeter的压测发起之后很快停止了?
阿里云首页 性能测试 相关技术圈