How to use Single Websocket Connection for all the virtual users and also refresh it periodically based on a token

Hi Team,

I was actually trying to establish One WSS Connection and use the same with all the Users.

Post this I also wanted to refresh the WSS connection based on an access token.

But I couldn’t do this as each virtual users are creating new WSS connection on every run.

How can this be achieved.

I am using Java 17 and Gatling version 3.9.5.

Why would you want to do that? What’s your use case exactly?

Thanks for the reply

The Use Case is we wanted to Verify load and traffic for our application with mixed traffic from both Http and Socket protocols and identify the breakdown points.

Case 1 :–

I was trying to create Virtual users to mimic Socket connections and sending multiple messages towards the Application.

The process each user follows is :–

  • Generate a bearer Token using an HTTP API .
  • Create a handshake using the ws connect method with the server, using the Token as an header.
  • Send Message to the Server.
  • Close.

This is happening exactly as of now.

I was able to abstract the Token Generation mechanism and make it generic for all the users … i.e it will generate only Once.

But I couldn’t make One generic Websocket connection for all the users.

Just like One Token Generation for all users … will it be possible to make One Shared Socket connection for all users.

Case 2 :–

It is okay if we can’t make One generic Socket connection.

I can proceed to create only one Virtual user for Socket Connection … and send multiple messages from him.

But in this case how can I implement refresh token for him for long durations, as the connection is dependent on token and it expires every 20 mins.

The process flow is as shown in 4 steps of Case 1 … but here the same user will send multiple messages for more than a hour.

Sorry for the long message … but wanted to convey the different paths we are checking.

Please provide your suggestions for this.

For refresh token you can check:

Hi @GeMi … thanks for the response.

I had gone through this use case earlier … and already have implemented something similar for the HTTP API’s that we use.

This Works fine for HTTP as they are stateless and each user will use it only when during sending a request.

But I have to Implement similar for Websocket … where there will be only One user and he will establish a connection using Token (which expires around 30 mins).

The Use case is –

Create One User who runs for 1 hour.
The user will generate a Token .. establishes a handshake with the socket.
Starts sending a message per second for next hour.

Here I need to refresh the connection or reconnect every 29th min … with a new token
without any of messages failing.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.