tencent cloud

Tencent Cloud Observability Platform

Release Notes and Announcements
Release Notes
Product Introduction
Overview
Strengths
Basic Features
Basic Concepts
Use Cases
Use Limits
Purchase Guide
Tencent Cloud Product Monitoring
Application Performance Management
Mobile App Performance Monitoring
Real User Monitoring
Cloud Automated Testing
Prometheus Monitoring
Grafana
EventBridge
PTS
Quick Start
Monitoring Overview
Instance Group
Tencent Cloud Product Monitoring
Application Performance Management
Real User Monitoring
Cloud Automated Testing
Performance Testing Service
Prometheus Getting Started
Grafana
Dashboard Creation
EventBridge
Alarm Service
Cloud Product Monitoring
Tencent Cloud Service Metrics
Operation Guide
CVM Agents
Cloud Product Monitoring Integration with Grafana
Troubleshooting
Practical Tutorial
Application Performance Management
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Parameter Information
FAQs
Mobile App Performance Monitoring
Overview
Operation Guide
Access Guide
Practical Tutorial
Tencent Cloud Real User Monitoring
Product Introduction
Operation Guide
Connection Guide
FAQs
Cloud Automated Testing
Product Introduction
Operation Guide
FAQs
Performance Testing Service
Overview
Operation Guide
Practice Tutorial
JavaScript API List
FAQs
Prometheus Monitoring
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Terraform
FAQs
Grafana
Product Introduction
Operation Guide
Guide on Grafana Common Features
FAQs
Dashboard
Overview
Operation Guide
Alarm Management
Console Operation Guide
Troubleshooting
FAQs
EventBridge
Product Introduction
Operation Guide
Practical Tutorial
FAQs
Report Management
FAQs
General
Alarm Service
Concepts
Monitoring Charts
CVM Agents
Dynamic Alarm Threshold
CM Connection to Grafana
Documentation Guide
Related Agreements
Application Performance Management Service Level Agreement
APM Privacy Policy
APM Data Processing And Security Agreement
RUM Service Level Agreement
Mobile Performance Monitoring Service Level Agreement
Cloud Automated Testing Service Level Agreement
Prometheus Service Level Agreement
TCMG Service Level Agreements
PTS Service Level Agreement
PTS Use Limits
Cloud Monitor Service Level Agreement
API Documentation
History
Introduction
API Category
Making API Requests
Monitoring Data Query APIs
Alarm APIs
Legacy Alert APIs
Notification Template APIs
TMP APIs
Grafana Service APIs
Event Center APIs
TencentCloud Managed Service for Prometheus APIs
Monitoring APIs
Data Types
Error Codes
Glossary

WebSocket-based Performance Testing

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2025-03-10 22:14:19
This document introduces how to write a WebSocket-based performance testing script.
Note:
For detailed API documentation, see pts/ws.

Overview

WebSocket is an application-layer communication protocol that provides full-duplex communication over a single TCP connection.
Unlike the HTTP protocol's question-and-answer mode where the client initiates a request and the server responds, once a WebSocket connection is established, data can be continuously and bidirectionally exchanged between the client and server until the connection is closed. Therefore, in performance testing scenarios, scripts based on WebSocket requests differ in structure and action mechanism from scripts based on HTTP requests:
Each VU that executes the HTTP script will continuously iterate the main function (export default function() { ... }) until the performance testing ends.
Each VU that executes the WebSocket script does not continuously iterate the main function, because the main function is blocked by the ws.connect method that establishes the connection, until the connection is closed. However, in the callback function (function (socket) {...}) after the connection is established, the corresponding method will continuously listen on and process asynchronous events until the performance testing ends.

Script Writing

The ws module of the PTS API provides APIs related to the WebSocket protocol. For details, see pts/ws.
Basic usage:
Use the ws.connect method to establish a connection and define your business logic in its callback function:
The required parameters for ws.connect include the URL and callback function.
If the connection is successfully established, PTS will pass the created ws.Socket object to the callback function. You can define your WebSocket request logic in the callback function.
After executing the callback function, the ws.connect method will return a ws.Response object.
Common methods of the ws.Socket object:
send: sends a text message.
close: closes a connection.
on: listens on events and processes them with the callback function. PTS supports the following events.
Event name
Event Purpose
open
Establishes a connection.
close
Closes a connection.
error
Reports an error.
message
Receives a text message.
binaryMessage
Receives a binary message.
pong
Receives a pong message.
ping
Receives a ping message.
The code example is as follows:
import ws from 'pts/ws';
import { check, sleep } from 'pts';
export default function () {
const res = ws.connect("ws://localhost:8080/echo", function (socket) {
socket.on('open', () => console.log('connected'));
socket.on('message', (data) => console.log('Message received: ', data));
socket.on('close', () => console.log('disconnected'));
socket.send("message");
socket.setTimeout(function () {
console.log('3 seconds passed, closing the socket');
socket.close();
}, 3000);
socket.setInterval(function () {
socket.ping();
}, 500);
socket.setLoop(function () {
sleep(0.1)
socket.send("loop message")
});
});
check("status is 101", () => res.status === 101);
}

File Dependency

In the performance testing scenario, you can upload the following types of files to provide status data during the execution of the performance testing task:
Parameter file: It dynamically provides test data in CSV format. That is, when the scenario is executed by each concurrent user (VU), each line of data will be obtained from the parameter file as the test data values for reference by variables in the script. For specific usage, see Using Parameter Files.
Request file: It is required for constructing your request, for example, the file that needs to be uploaded. For specific usage, see Using Request Files.
Protocol file: It is required for request serialization. For specific usage, see Using Protocol Files.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백