Do you remember your early experiences chatting with your friends on social networking applications like Orkut (yeah, remember that one?) and feeling all obsessed with being able to send and receive messages in real-time. Fast forward to now, where we use applications like Gmail, Slack, WhatsApp, Shazam, Instagram, and countless others, without batting any eye. We have really witnessed the rise of real-time web in just a matter of years. One of the biggest reasons this has been possible has mainly been due to the introduction of the WebSocket protocol. Let us try to explain and understand what WebSockets are, their features, benefits, and how to stress test applications and websites that utilize WebSockets to understand overall performance under stress, as well as how that impacts the user experience.

 

What are WebSockets?

By definition, a WebSocket is a two-way computer communication protocol over a single TCP. WebSockets helps immensely to handle high scale data transfers between client and server. WebSockets are different because they work by holding the connection between client and server open at all times. Using this method, the server has the power to send information any time, even when it was not initiated by the client. Clients can still make usual HTTP requests to the server, while WebSockets open a medium between client and server to communicate. Web servers, such as Nginx, Apache, and Windows Server all support the WebSockets protocol, as do all the popular browsers, like Chrome, Edge, Internet Explorer, Firefox, and Safari.

 

Where are WebSockets Used?

WebSockets are good for situations where you need near real-time communications, such as the following scenarios and applications:

  • Online multiplayer games
  • Chat applications
  • Internet of things
  • Real-time applications
  • Sports scores/tickers

 

Advantages & Benefits of WebSockets

  • Continuous Connection between client and server. It makes it feasible to send information to client at any time, even without the client requesting it.
  • Full duplex communication.  Communication can be initiated by either way at any time both client and server are connected.
  • Low Latency.  As there is very limited overhead of HTTP headers, cookies, etc., it makes the speed at which data transfers are seamless and fast.
  • HTTP Polling.  This can help clients to keep polling the server for latest information. Polling is used by a vast number of applications today and most of the time it is used for RESTful practices.

 

Disadvantages of WebSockets

  • WebSockets are more complex to use than HTTP.  We can establish an HTTP connection with a Telnet, but cannot do the same with WebSockets.
  • Load balancing and proxy setup with WebSockets is not possible.
  • If in between connection drops, re-connection handling is not present in WebSockets.

 

Performance Testing Applications That Use WebSockets

As we have seen, WebSockets can be utilized you support a chat application or a news feed that delivers real-time content on a website, for example, but it can possess performance issues which can impact overall user experience if implemented properly. To safeguard this, it would be wise to execute load and stress tests on our website or application to find any performance issues, bottlenecks, or degradation issues. When we put applications up against high numbers of concurrent users, we can get a better idea of what the user will experience.

 

Performance Testing with LoadView using The EveryStep Web Recorder

The EveryStep Web Recorder provides a screen recorder option while you are browsing and helps you simulate the client-side interactions with websites and applications. It supports over 40 desktop and mobile browsers, in addition to frameworks and technologies that are used to create dynamic web applications, such as HTML5, Java, Ruby, React, Vue, Angular, and Knockout, just to name a few. Essentially, if it renders in a browser, the EveryStep Web Recorder can be utilized to create a script. We can record each step of our web transaction by simply navigating through our application as a user would do and then replay those scripts in real browsers. Finally, we can take that script and test the steps and scenarios we just recorded under load to get a better idea of performance under various workloads.

Let us look at the steps and processes used to record scripts using EveryStep Web Recorder and then executing a load test using LoadView.

Open the LoadView testing homepage. You will see multiple types of load test options that are available as shown in the image below. For our use case, we are going to select the Web Application option to start recording the user’s journey.

create new load test web application

 

We would get an option to Record New Script. Please enter website URL, browser type and user device type for the application we want our stress test to run and record our test case. Please click the Record Now button after adding details.

 

Websocket EveryStep

 

Clicking on the Record Now button will allow you the option to interact with the website under test and record steps we want to simulate. We would have the option to stop the recording once user flow is completed.

 

Websocket Record Browser

 

After successfully recording our script, we can review our test scenario using. Select the Play Now button or we can move forward to test by clicking the Continue button.

 

EveryStep Recording Stopped

 

Clicking on Continue would redirect us to the Create Test window with the simulated actions script ready. We can name our test on this video and later we would need to click the Create Device button.

 

Websocket test scenario window

 

Once we have successfully created a device, we would see the Test Scenario screen, where we can set the load curve type, which can differ based on the goals of the load test. The below image shows the load test curves that LoadView makes available for developers and performance testers.

Websocket Test Scenario

 

Once you have selected the load curve, you can begin the test execution with number of concurrent users and test duration. You can also choose from over 20 geo-locations to run tests from, ensuring that you are measuring and testing performance from where your users are located.

Once the test is complete, you can view the results of the test, along with associated metrics. An example of that is shown in the below images.

Websockets average response time

 

Average number of users average response time

Parallel Average number of users with Average Response time graph.

 

Websockets number of virtual users

Summary:  Load Testing WebSocket-based Applications

As we have seen through this article with innovative technologies like WebSockets, and the new challenges it addresses, there are a lot of operational issues developers might face when using WebSockets as their real-time solution. Load tests on these applications are a must and it helps us estimate the behavior of our real-time application under load. We also went through, step-by-step, on how to test a WebSocket-based application using LoadView, along with the EveryStep Web Recorder, which can be extremely helpful to uncover major problems inherent in the WebSocket architecture.

Try the EveryStep Web Recorder now and see how easy it is to start scripting complex user scenarios. Sign up for the LoadView free trial and start running load tests for your WebSocket-based applications. You will get $20 in load testing credits to start. Or schedule your own one-on-demo with one of our performance engineers.