java.net.SocketException:使用 Jmeter 并发线程组时,套接字在脚本持续时间结束时关闭
java.net.SocketException: Socket closed at the end of the script duration when using Jmeter Concurrency Thread Group
我正在使用 Jmeter 5.2.1 和 Concurrency Thread Group with ${__tstFeedback(ThroughputShapingTimer,1,10,10)}
in combination with the Throughput Shaping Timer 在整个测试期间动态更改目标吞吐量。
测试计划由一个线程组组成,该线程组具有一个模块控制器和其下的 ThroughputShapingTimer。模块控制器控制一个包含测试逻辑的测试片段。
我在测试结束时遇到一个问题,在大多数情况下,最后几个采样器会导致“java.net.SocketException: Socket closed
”异常。无论我是否在测试结束时降到 0,都会发生这种情况。
相比之下,如果我使用具有相同设置的相同脚本但只是从普通线程组控制它,那么所有采样器都会在脚本末尾成功完成而不会出现问题。
以下是我的设置的一些屏幕截图:
采样器的完整错误文本:
java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)
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)
我想了解可能的原因,因为这会影响报告。
如能帮助解决或解决此问题,我们将不胜感激。
JMeter 无法在 5 次尝试后正常终止线程,因此它 forcefully terminates the connection,在您的情况下,此终止发生在服务器响应破坏 SSL 隧道并导致错误的过程中。
“正常”线程组使用 different approach 停止不能在并发线程组中重复使用的线程,因为在您的情况下,它会产生一个不属于线程的额外线程池除非明确使用它们,否则它们会在某种程度上超出 JMeter 的控制范围。
如果您仍想使用并发线程组并且只想忽略或过滤掉错误,可以使用以下方法完成:
- JMeter Plugins Command Line Tool Plugin
- Filter Results Plugin
- Response Assertion 和“忽略状态”框
- JSR223 Assertion and your custom code to conditionally mark the sampler(s) in scope 通过或失败
当 JMeter 尝试发送请求但连接已关闭时,在测试结束时抛出错误。
这些错误是由于测试配置造成的,应在测试中忽略 results/reports。
您可以在 JSR223 Post 处理器中使用 pre.setIgnore()
忽略特定时间的测试结果。
示例代码可用。
我正在使用 Jmeter 5.2.1 和 Concurrency Thread Group with ${__tstFeedback(ThroughputShapingTimer,1,10,10)}
in combination with the Throughput Shaping Timer 在整个测试期间动态更改目标吞吐量。
测试计划由一个线程组组成,该线程组具有一个模块控制器和其下的 ThroughputShapingTimer。模块控制器控制一个包含测试逻辑的测试片段。
我在测试结束时遇到一个问题,在大多数情况下,最后几个采样器会导致“java.net.SocketException: Socket closed
”异常。无论我是否在测试结束时降到 0,都会发生这种情况。
相比之下,如果我使用具有相同设置的相同脚本但只是从普通线程组控制它,那么所有采样器都会在脚本末尾成功完成而不会出现问题。
以下是我的设置的一些屏幕截图:
采样器的完整错误文本:
java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)
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)
我想了解可能的原因,因为这会影响报告。
如能帮助解决或解决此问题,我们将不胜感激。
JMeter 无法在 5 次尝试后正常终止线程,因此它 forcefully terminates the connection,在您的情况下,此终止发生在服务器响应破坏 SSL 隧道并导致错误的过程中。
“正常”线程组使用 different approach 停止不能在并发线程组中重复使用的线程,因为在您的情况下,它会产生一个不属于线程的额外线程池除非明确使用它们,否则它们会在某种程度上超出 JMeter 的控制范围。
如果您仍想使用并发线程组并且只想忽略或过滤掉错误,可以使用以下方法完成:
- JMeter Plugins Command Line Tool Plugin
- Filter Results Plugin
- Response Assertion 和“忽略状态”框
- JSR223 Assertion and your custom code to conditionally mark the sampler(s) in scope 通过或失败
当 JMeter 尝试发送请求但连接已关闭时,在测试结束时抛出错误。
这些错误是由于测试配置造成的,应在测试中忽略 results/reports。
您可以在 JSR223 Post 处理器中使用 pre.setIgnore()
忽略特定时间的测试结果。
示例代码可用