All Products
Search
Document Center

Performance Testing:Load test WebSocket with JMeter in PTS

Last Updated:Mar 11, 2026

Performance Testing (PTS) runs Apache JMeter scripts to execute load tests. This guide walks you through building a JMeter script that tests WebSocket connections and running that script in PTS. The JMeter WebSocket Samplers plug-in is used throughout.

How WebSocket testing differs from HTTP: Unlike HTTP request-response cycles, a WebSocket connection is persistent and full-duplex. A single request can produce multiple responses, which JMeter queues in arrival order. Each read sampler pulls the next response from the front of this queue, and each newly received response is placed at the end of the queue. If the number of read and write samplers does not match, responses may become misaligned. Keep this behavior in mind when designing test scripts.

Prerequisites

  • Apache JMeter installed on a local machine

  • A WebSocket service endpoint to test

Workflow overview

The end-to-end workflow has five steps:

  1. Install the JMeter WebSocket Samplers plug-in.

  2. Create a test script with WebSocket samplers.

  3. Debug the script locally.

  4. Export the script as a .jmx file.

  5. Upload the script to PTS and run the load test.

Step 1: Install the JMeter WebSocket Samplers plug-in

  1. Download the latest version of the JMeter WebSocket Samplers plug-in. The following steps use JMeterWebSocketSamplers-1.2.10.jar as an example.

  2. Copy the downloaded JAR file to the <Apache JMeter installation directory>/lib/ext directory.

    Important

    Save a copy of this JAR file. You must upload it to PTS later.

  3. Restart Apache JMeter.

  4. Verify the installation by checking for the following elements:

    LocationExpected elements
    Test Plan > Add > Config ElementWebSocket Binary Frame Filter, WebSocket Ping/Pong Frame Filter, WebSocket Text Frame Filter
    Test Plan > Add > AssertionsBinary Response Assertion
    Test Plan > Add > Listener > View Results Tree > Text dropdownBinary option
    Thread Group > Add > SamplerWebSocket samplers listed in the table below

Step 2: Create a test script

The following example demonstrates a basic WebSocket test script. Adjust the samplers to match your use case.

Sampler reference

SamplerPurposeBlocking behavior
WebSocket Open ConnectionOpens a WebSocket connection to the serverBlocks until connection is established or times out
WebSocket Ping/PongSends a ping frame and waits for a pong frameBlocks until pong is received or times out
WebSocket request-response SamplerSends a frame and reads one responseBlocks until a response is read or times out
WebSocket Single Write SamplerSends a frame without waiting for a responseNon-blocking
WebSocket Single Read SamplerReads one response from the queueBlocks until a response is read or times out
WebSocket CloseCloses the connection through negotiationBlocks until close handshake completes

For proxy services, data filtering, and data sharding samplers, see the JMeter WebSocket Samplers documentation.

Build the script

  1. Right-click Test Plan and choose Add > Threads (Users) > Thread Group.

  2. Add the following samplers to the thread group in order. Right-click Thread Group and choose Add > Sampler > *sampler name* for each one.

a. WebSocket Open Connection

Configure the Server URL section to point to the service under test.

WebSocket Open Connection configuration
Note

This example targets a Python Echo service that echoes every received message. The sample server code:

Example server.py code

import asyncio
import websockets

async def echo(websocket, path):
    async for message in websocket:
        message = "Your message: {}".format(message)
        await websocket.send(message)

asyncio.get_event_loop().run_until_complete(websockets.serve(echo, '0.0.0.0', 8080))
asyncio.get_event_loop().run_forever()

b. WebSocket Ping/Pong

Set Pong (read) timeout (ms) to 6000. If JMeter does not receive a pong frame within 6,000 ms, the sampler fails and reuses the existing connection.

WebSocket Ping/Pong configuration

c. WebSocket request-response Sampler

This sampler sends a frame and reads the response in a single step.

ParameterExample valueDescription
Connectionuse existing connectionReuses the connection opened earlier.
Data typeTextFrame data type.
Request dataPTSThe payload to send.
Response (read) timeout (ms)6000Maximum wait time for a response.
WebSocket request-response Sampler configuration

d. WebSocket Single Write Sampler

This sampler sends a frame and returns immediately without waiting for a response.

ParameterExample valueDescription
Connectionuse existing connectionReuses the connection opened earlier.
Data typeTextFrame data type.
Request dataPTS bang bang bangThe payload to send.
WebSocket Single Write Sampler configuration

e. WebSocket Single Read Sampler

This sampler reads the next response from the queue without sending anything.

ParameterExample valueDescription
Connectionuse existing connectionReuses the connection opened earlier.
Data typeTextFrame data type.
Response (read) timeout (ms)6000Maximum wait time for a response.
WebSocket Single Read Sampler configuration

f. WebSocket Close

Closes the WebSocket connection through the standard close handshake. A successful close returns 1000:sampler requested close.

ParameterExample valueDescription
Close status1000Status code sent in the close frame (first two bytes of the data frame).
Response (read) timeout (ms)6000Maximum wait time for the close acknowledgment.
WebSocket Close configuration

(Optional) Add HTTP headers

To include headers such as authentication tokens, right-click Thread Group and choose Add > Config Element > HTTP Header Manager. For details, see the Apache JMeter Header Manager documentation.

Add a listener

Right-click Thread Group and choose Add > Listener > View Results Tree to inspect request and response data during debugging.

Step 3: Debug the script

  1. Click the Start button in the JMeter toolbar to run the script.

  2. Open the View Results Tree listener. A green check mark next to a sampler indicates success. A red icon indicates failure.

  3. For any failed sampler, review the request and response data to identify the issue. The following screenshots show successful results: WebSocket request-response Sampler -- Request data: WebSocket request-response Sampler -- Response data (Text): WebSocket Single Read Sampler -- Response data (Text):

    Request data

    Response data

    Single Read response

Step 4: Export the script

After debugging, choose File > Save Test Plan as to save the script. The following example uses the filename wsTest.jmx.

Step 5: Run the load test in PTS

Upload the script

  1. Log on to the PTS console. Choose Performance Test > Create Scenario, then click JMeter.

  2. Enter a scenario name and upload the wsTest.jmx file.

  3. PTS automatically resolves plug-in dependencies. If automatic resolution fails, click Upload File to manually upload the JMeterWebSocketSamplers-1.2.10.jar file and any data files such as CSV parameter files.

    Scenario configuration

Configure load settings

Set the following parameters for an initial test run. Adjust values based on your testing requirements.

ParameterExample valueDescription
Max VUs10Maximum number of concurrent virtual users.
Test Duration2 minutesTotal duration of the load test.
Increment Duration2 minutesTime to ramp up to the maximum VU count.

Keep the default values for other parameters.

Load settings
Important

Load testing incurs charges. Set the load level based on your actual requirements. For pricing, see Billing overview. For load model details, see Configure the stress testing model and level.

Start the load test

  1. (Recommended) Debug the scenario to verify the configuration before running the full test. For details, see Debug a stress testing scenario.

  2. Click Save and Test. On the Tips page, select Trigger Now and Make sure that the test is approved and complies with local laws, then click Start Stress Testing.

Analyze the test results

After the load test finishes, PTS automatically generates a performance report that includes:

  • Scenario-level metrics

  • Per-API business details

  • Monitoring details

  • API sampling logs

For details, see View a JMeter performance testing report.

What's next