How to keep alive open websocket connection ?

Issue #37 closed
Former user created an issue

Hello Peter. I have a problem, when I'm using WebSocket Open Connection sampler it opens ws connection and than immediately closes it.

The problem is in that: I need to establish 500 ws connection and keep them alive for defined time. How can I do this? I'm not using Websocket close, but they closed anyways.

Comments (18)

  1. Peter Doornbosch repo owner

    Hi,

    The samplers (apart from the Close Sampler of course) never close connections, so it must be the server that closes the connection. Probably, the server detects a protocol error and reacts by closing the connection.

    As far as the plugin is concerned, establishing 500 connections and keeping them alive for some time is no problem at all. Depending on server implementation and how long you need to keep them alive, you might need to add ws ping's (as some servers will close the connection after same idle time).

    Hth. Regards, Peter

  2. Vladimir Melnikov

    @pjtr Thanks for answer, about what protocol error you're talking about? Backend developer says that from his side there is no close connection commands was sent. It's very strange behaviour. I'm just want to open 500 connection for example for 30 minutes, but through jmeter they opens and immediately closes.

  3. Peter Doornbosch repo owner

    Hi Vladimir,

    Maybe you use a loop to open the connections? That won't work, because the samplers will close the connection once a new one is opened on the same JMeter thread. If this is the case, the solution is pretty simple: let your Thread Group use 500 threads.

    Hth! Regards, Peter

  4. Vladimir Melnikov

    @pjtr No I'm in using way just you say - Thread Group use 500 threads. Maybe it's a JMeter limitations when I've established 500 connection they start to close and test ends, but I want to hold them for example 30 minutes long and I don't understand how to do this. Maybe I need to set test duration time somehow?

  5. Peter Doornbosch repo owner
    • How do you conclude the connections are closed? What are the symptoms you see?
    • Are you running JMeter in GUI mode or as command line tool?

    When the JMeter test is finished, the JMeter threads might be garbage collected and this is likely to cause a close on the TCP connection (i.e. not on ws level). Thus it might help to ensure the test is running long enough, for example add a dummy thread group with a wait timer....

  6. Gabriele Centinaro

    I have a similar problem. I need to open a WS connection to my server and check that after 10 minutes of inactivity the server closes the WS automatically.
    I created a script that opens a WS, a timer that waits 10 minutes and then I check that the WS is closed.
    What happens is always that during the timer wait time (always about 3-4 minutes into it) the WS connection shoes as aborted apparently by JMeter. Any clue?

  7. Peter Doornbosch repo owner

    By JMeter? I don’t think so.

    Create a WireShark capture of the session and mail it to me; i’ll analyse it and get back to you.

    Regards
    Peter

  8. Gabriele Centinaro

    Hi Peter,

    I am all new to this. How do I capture the traffic of a JMeter script using WireShark?

    Gabriele

  9. zhoury4

    Hi peter

    I create connection and send a ping/pong sampler, but the server can‘t receive the pong.

    I set a ping/pong sampler after the connect sampler. In ping/pong sampler, I choose ping/pong(send ping,expect pong),- the pong(read) timeout(ms) set 10000.

    should I need to add two ping/pong samplers, one for ping, one for pong to simulate ping/pong as browser?

  10. Peter Doornbosch repo owner

    No, one sampler should do. “send ping, expect pong” is indeed normal client behaviour. The timeout specifies how long to wait for reading the pong response.

    Are you sure the server does not get the ping? Some websocket API’s do not expose the ping/pong’s as they consider it protocol internals.

    You could always check with a wireshark capture whether JMeter sends a ping or not….

    Hth
    Peter

  11. zhoury4

    Hi Peter, thanks for your reply.

    the behavior

    1.“ping/pong(send ping, expect pong)” means the client sent ping and the server return pong to the client

    2.“pong(just send pong)” means the client send pong to the server

    right?

  12. Peter Doornbosch repo owner

    Yes. And (1) expect pong means: the plugin expects that the first message that it receives from the server, is the pong. This can be tricky if the server sends unsolicited messages at the same time.

  13. zhoury4

    Hi,peter

    We found the problem.

    Our project need to send “/n” in ping, the ping/pong sampler seems send nothing.

    Now, using webSocket Single Write Sampler with request data '/n', it can achieve the ping, the server can detect the heartbeat.

    Thanks for your help.

  14. Peter Doornbosch repo owner

    So, you have a feature request to be able to specify data to be send in Ping? If so, can you create a separate issue for that?

    Thanks
    Peter

  15. Log in to comment