Send wsclose on stop test
As far as I can make out, the websocket is not nicely closed when a test is stopped. Would it be possible to send a closesocket before the ws connection's thread is forcefully terminated?
Use case: this introduces issues with high load on my server as it keeps the ws connection open for some time before it decides the client has dropped. This would not be an issue when the ws closed is issued by jmeter on stopping the test.
Comments (9)
-
repo owner -
reporter I have a continuous loop that is only ended by stopping/killing the test. So there is no way of calling the "websocket close", that is my problem. Therefore I was wondering whether the websocket object itself could send a close before it is closed/stopped/deleted? Cheers
-
repo owner Well, i looked again and now i did find a hook, so i implemented a prototype. See https://bitbucket.org/pjtr/jmeter-websocket-samplers/branch/close-on-thread-stop.
To have the tcp connection closed: pass JMeter property like this:
jmeter -J websocket.thread.stop.policy=tcpClose
To have the websocket connection properly closed: pass JMeter property like this:
jmeter -J websocket.thread.stop.policy=wsClose
Give it a try and let me know if it helps. Regards Peter
-
repo owner - changed status to open
-
reporter I have had a look and I receive this:
2017-09-21 23:02:57,590 INFO o.a.j.t.JMeterThread: Thread finished: TestRouter 1-1 2017-09-21 23:02:57,590 DEBUG e.l.j.w.OpenWebSocketSampler: Sampler eu.luminis.jmeter.wssampler.OpenWebSocketSampler@8d99830: closing WebSocket connection 2017-09-21 23:02:57,590 ERROR e.l.j.w.OpenWebSocketSampler: Closing WebSocket connection failed eu.luminis.websocket.UnexpectedFrameException: null at eu.luminis.websocket.WebSocketClient.receiveClose(WebSocketClient.java:362) ~[JMeterWebSocketSamplers-dev.jar:?] at eu.luminis.websocket.WebSocketClient.close(WebSocketClient.java:294) ~[JMeterWebSocketSamplers-dev.jar:?] at eu.luminis.jmeter.wssampler.WebsocketSampler.threadFinished(WebsocketSampler.java:256) [JMeterWebSocketSamplers-dev.jar:?] at org.apache.jmeter.threads.JMeterThread$ThreadListenerTraverser.addNode(JMeterThread.java:679) [ApacheJMeter_core.jar:3.2 r1790748] at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:996) [jorphan.jar:3.2 r1790748] at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:997) [jorphan.jar:3.2 r1790748] at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:997) [jorphan.jar:3.2 r1790748] at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:997) [jorphan.jar:3.2 r1790748] at org.apache.jorphan.collections.HashTree.traverse(HashTree.java:978) [jorphan.jar:3.2 r1790748] at org.apache.jmeter.threads.JMeterThread.threadFinished(JMeterThread.java:651) [ApacheJMeter_core.jar:3.2 r1790748] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:310) [ApacheJMeter_core.jar:3.2 r1790748] at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
Mind you, I tried it from the GUI. I have played a bit with the code and replaced the
webSocketClient.close(1000, "end of test", Integer.parseInt(getReadTimeout()));
with
webSocketClient.sendClose(1000, "testaborted");
I think that it would be sufficient to send a proper close, without waiting for a response. Now I don't see the exception. At this point I also don't really care about whatever response or data might be received.
2017-09-21 23:13:59,080 DEBUG o.a.j.p.h.s.MeasuringConnectionManager: Connection manager shut down 2017-09-21 23:13:59,081 DEBUG o.a.j.p.h.s.MeasuringConnectionManager: Connection manager is shutting down 2017-09-21 23:13:59,081 DEBUG o.a.j.p.h.s.MeasuringConnectionManager: Connection manager shut down 2017-09-21 23:13:59,081 DEBUG e.l.j.w.OpenWebSocketSampler: Sampler eu.luminis.jmeter.wssampler.OpenWebSocketSampler@5ab28adf: closing WebSocket connection 2017-09-21 23:13:59,081 DEBUG o.a.j.t.ThreadGroup: Ending thread TestRouter 1-1 2017-09-21 23:13:59,081 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
And on the serverside, exactly what i needed...
Sep 21 21:14:00 5000 INFO [pid:26716 tid:139962408019712 git:348446b] 2017-09-21 21:14:00,386 - [AA:BB:CC:DD:EF:01] WebSocket 139962036021456 closed (code: 1000, reason: testaborted) <| router:on_close
But I might be missing something here?
:-)
-
repo owner Hi Ray,
No, you didn't miss anything. I agree that waiting for a response is quite useless in this case. I'll correct it.
Thanks for your feedback! Cheers, Peter
-
reporter Geen probleem ;-)
-
repo owner 👍
-
repo owner - changed status to closed
Done. Will be in next release (0.11).
- Log in to comment
Hi Ray,
Your observation that "the websocket is not nicely closed when a test is stopped" is correct. But you can easily do it yourself by adding a "Websocket Close" sampler at the end of your test scenario; wouldn't that solve your problem?
I've been looking into the issue of proper clean up at the end of the test some time ago, and i recall that i concluded that JMeter does not provide a hook to implement such behaviour. Or at least, i couldn't find it ;-).
Regards Peter