Unable to establish Two websocket connection in a thread

Issue #149 new
Former user created an issue

We have a chat application uses websocket connection. Using our application 2 users will chat with each other. for this Both the users should be online. I was able to establish a websocket connection for user1 But when I established User2 websocket connection, The User1 websocket session is closed automatically. Could you please help me, is there a way to handle 2 websocket connection in a thread?

Comments (5)

  1. Peter Doornbosch repo owner

    No, that is not possible with the official release of this plugin.

    However, you could check out the source of this branch https://bitbucket.org/pjtr/jmeter-websocket-samplers/src/multiple-connections/, and build a plugin from it. As documented in the readme:

    This branch features a new option: the possibility to have multiple concurrent websocket connections on one JMeter thread. This option must be explicitly enabled by adding a "WebSocket Advanced Options" element to your test plan (menu: Add -> Non-test Elements) and checking the checkbox. A connection-id field will appear in the user interface of each WebSocket sampler. The connection id should be used both when creating a connection and when (re-)using a connection. The connection id can have any value and can include JMeter properties. Note that connections are never shared between JMeter threads.

    See the sample test plan "Multiple connections.jmx" in the samples directory.

    So, with this option, you can alternate between sending/receiving messages to/from user1 or user2.

    As this is a experimental feature, i’d love to hear if it works out or other feedback.

    Hth
    Regards
    Peter

  2. Dmitriy Nefedchenko

    Hi, all!

    I faced similar situation using this plugin. Test plan for my case needs two web socket connections. First one accepts control messages. Second - starts to stream binary packages. Very similar to what described here:

    Specifics of the system is that first ws idling most of time(one message is sent after connection is opened and then idling). Whereas second connection receives binary packages quite frequently(2-3 frames/sec).

    So, with multiple-connections branch build my plan looks like this:

    It does allow to have two connections in the same thread group. Although, except Single Read Sampler I had to put ping/pong sampler as well. Without it after ~20 seconds of running binary data stops streaming. Here’s the log after subsequent read:

    2020-03-30 12:58:29,167 DEBUG e.l.j.w.SingleReadWebSocketSampler: Sampler 'WebSocket Single Read Sampler' received binary frame with data: 0x18 0x00 0x00 0x00 0x35 0x65 0x37 0x34 0x62 0x31 0x34 0x64 0x38 0x62 0x65 0x30 0x62 0x32 0x30 0x30 0x33 0x32 0x30 0x37 0x37 0x34 0x34 0x65 0x20 0x00 0x00 0x00 0x7b 0x22 0x64 0x61 0x74 0x61 0x22 0x3a 0x7b 0x22 0x70 0x69 0x64 0x22 0x3a 0x22 0x31 0x35 0x38 0x34 0x37 0x30 0x35 0x38 0x36 0x39 0x38 0x35 0x35 0x22 0x2c 0x22 0x64 0x65 0x76 0x69 0x63 0x65 0x69 0x64 0x22 0x3a 0x22 0x75 0x6e 0x6b 0x6e 0x6f 0x77 0x6e 0x22 0x7d 0x7d

    2020-03-30 12:58:29,167 DEBUG e.l.j.w.SingleReadWebSocketSampler: Added filter Ping Frame Filter 'WebSocket Ping/Pong Frame Filter' to sampler WS Read sampler 'WebSocket Single Read Sampler'; filter list is now [Ping Frame Filter 'WebSocket Ping/Pong Frame Filter']

    2020-03-30 12:58:35,169 DEBUG e.l.j.w.SingleReadWebSocketSampler: I/O Error in sampler 'WebSocket Single Read Sampler'.

    java.net.SocketTimeoutException: Read timed out

    Although, ping/pong sampler resolves this issue I’m really wondering what’s going on JMeter side. The thing confusing me even more is that I managed to write code snippet in pure java replicating the same scenario. It keeps first ws connection opened with no ping/pong frames. On the other hand second connection receives data.

    Having it in place makes me believe JMeter treats ws connections differently. Long story short, do you know why is this happening? is there a way to go without ping/pong sampler in this load test plan?

  3. Peter Doornbosch repo owner

    There is no magic. The plugin does not send anything unless you specifically instruct it to do so.

    The read timeout you were experiencing; did you try to increase the timeout value of the Read Sampler? From the log, it seems that it is only 6 seconds, maybe it helps to wait a little longer.

    If I understand you correctly, you are saying that a Java program that executes the same (test) scenario, works well without pong and that your JMeter testplan doesn’t. I cannot explain. As i said, there is no magic going on in JMeter. Probably, the scenario’s in your Java program and JMeter testplan were not exactly equal. Use Wireshark to find out.

    Regards

    Peter

  4. Dmitriy Nefedchenko

    Hi, Peter and thank you for reply!

    Yes I tried to increase timeout value but the result remains the same.

    Probably, I missed one point during my description. Just to be absolutely clear. I don’t think the problem is with read sampler timeout. This connection is rather busy and data streams through it infinitely(there’s another application running locally so, I see data from second channel keeps streaming). Whereas first connection not so busy and idling most of the time. So, ping/pong sampler refers namely to this connection(ping/pong sampler → wss-control → Open Control Connection Sampler).

    Actually, I tried Wireshark but I’m not so proficient with this tool. If you could point me out what display and capture filter as well as network interface should be I can take another look. I’m using wireless connection. Application is in docker and running on localhost. Two web socket connections are: wss://localhost:8000/?id=VS6QHUT942 and wss://localhost:8001/?id=VS6QHUT942 respectively.

    Thank you in advance

    Dmitriy

  5. Peter Doornbosch repo owner

    Well, to be honest, i still don’t get exactly what your question is…… Maybe you should annotate your screenshot with which sampler is using which connection.

    W.r.t. wireshark: if everything runs on you your local machine, capture network interface “lo” or “lo0” or whatever the “loopback” interface is called. Use capture filter (not to confuse with display filter) “tcp port 8000 or tcp port 8001.

    Hth,
    peter

  6. Log in to comment