Create a load testing scenario
You can use the MQTT load testing feature of Performance Testing Service (PTS) to run load tests on self-managed MQTT services and ApsaraMQ for MQTT. This topic describes how to use this feature.
Background
MQTT is an ultra-lightweight messaging protocol designed for the Mobile Internet and the Internet of Things (IoT). It enables two-way communication between mobile clients and cloud services. MQTT is widely used in various application scenarios, such as device-to-cloud status reporting, cloud-to-device message pushes, and device-to-device messaging for applications like instant messaging.
Procedure
Log on to the PTS console. In the left navigation pane, choose , and then click MQTT Test.
On the Create MQTT Scene page, enter a Scene Name.
On the Scene configuration tab, click the expand icon next to + Add Test Node to add the required test nodes to the target serial link.
Scene configuration
Click the expand icon next to a serial link to expand it and configure its basic information, output parameters, and checkpoints.
Basic configuration
On the Basic Configuration tab of the serial link, configure the following basic parameters for the load test.
Establish Connection: Establishes an MQTT connection.
Parameter
Description
Server address
The public network address of the MQTT server. Client devices typically use the public network to access the MQTT service. For example, if you want to run a load test on an ApsaraMQ for MQTT instance, set this parameter to the public endpoint of the instance. You can find the endpoint in the ApsaraMQ for MQTT console.
Server port
The port of the MQTT server, such as
1883for the standard TCP port.MQTT version
The MQTT version, for example,
3.1.1. Most MQTT servers support version 3.1.1.Connection timeout
The timeout, in seconds, for client operations such as establishing a connection or sending a message.
Protocol
The connection protocol. You can select TCP or SSL.
Signature authentication
This feature is disabled by default. To enable signature authentication, you must enter an AccessKey ID, AccessKey Secret, and instance ID.
AccessKey ID: The ID used to identify a user. For more information, see Obtain an AccessKey pair.
AccessKey Secret: The secret key used to authenticate a user. You must keep your AccessKey Secret confidential. For more information, see Obtain an AccessKey pair.
Instance ID: The ID of the ApsaraMQ for MQTT instance.
Username
The username for the MQTT client. You do not need to configure this parameter if Signature authentication is enabled.
Password
The password for the MQTT client. You do not need to configure this parameter if Signature authentication is enabled.
Client ID prefix
The prefix of the MQTT client ID.
Keep alive interval
The heartbeat interval in seconds. For example, a value of
300means a heartbeat is sent every 5 minutes when the connection is idle.Add random suffix to client ID
Specifies whether to add a random suffix to the client ID.
Clean session
If you enable this option, the session is cleared when the client disconnects. If you disable this option, the session is retained when the client disconnects.
Publish Message: Configures the message to be published.
Parameter
Description
Topic name
The topic of the message. MQTT topics support a hierarchical structure that uses forward slashes (/) as delimiters, similar to file paths. Example: pts_test/mqtt.
QoS level
The Quality of Service (QoS) level for messages published from a client to the server. You can select At most once (0), At least once (1), or Exactly once (2).
Message type
The type of message to send, which can be a plain string, hexadecimal string, or fixed-length random string.
Add timestamp
If enabled, you can measure the message latency during the test.
Retained message
Specifies whether to make this a retained message. If enabled, the message is sent to any new subscribers of the topic.
Message content
Enter the content of the message based on the selected message type.
Subscribe to Message: Subscribes to the published messages.
Parameter
Description
Topic name
The message topic to subscribe to. This must match the topic of the published message.
QoS level
The QoS level for messages pushed from the server to the client. You can select At most once (0), At least once (1), or Exactly once (2).
Add timestamp
If enabled, PTS calculates the total message latency. Total latency is the time from when a message leaves the publisher, passes through the server, and arrives at the subscriber.
Debug Response
This option logs the content of received messages for debugging and troubleshooting. We recommend disabling this option during formal performance tests to optimize performance and reduce memory usage.
Close Connection: Closes the MQTT connection.
Output parameter settings
On the Output parameter settings tab of the serial link, configure output parameters. For more information, see API output parameters.
Checkpoint settings
On the Checkpoint settings tab of the serial link, configure checkpoints. For more information, see Checkpoints (assertions).
Controllers and timers (optional)
You can add controllers and timers for various load testing scenarios.
On the Scene configuration tab, click + Add Controller and select a controller.
Loop Controller: Controls the number of times the test nodes within it are executed.
After you add a loop controller, click the
icon next to it, add the test nodes to the loop, and set the number of loops. During the test, the nodes under this controller are executed sequentially for the specified number of times.A serial link loops automatically for the whole load test duration, so you do not need to add a Loop Controller to make it repeat. A Loop Controller is used to precisely control how many times the test nodes within it are executed; it is not a prerequisite for a serial link to loop. In debug mode, a serial link is executed only once. In load testing mode, a serial link keeps looping for the configured load test duration.
Transaction controller: All test nodes under a transaction controller are treated as a single transaction. This controller includes the Generate parent sample and Include timer and pre/post processor time settings.
Generate parent sample:
Enabled: The individual test results of each node under the controller are not displayed separately in the test report. Instead, they are aggregated and presented as the result of the transaction controller.
Disabled: The test results for both the transaction controller and its individual nodes are displayed in the report.
Include duration of timers and pre/post-processors in samples: If you enable this switch, the average response time of the transaction controller in the performance test report is the sum of the average response times of all test nodes, timers, and pre- and post-processors. If you do not enable this switch, the average response time of the transaction controller is only the sum of the average response times of all test nodes.
Once Only Controller: Nodes added under a Once Only Controller are executed only once.
On the Scene configuration tab, click + Add Timer and select a timer.
Constant Timer: Pauses the test for a fixed duration, specified in milliseconds.
Synchronizing Timer: Waits for a specified number of virtual users to accumulate before triggering the test. You can set the Number of simulated users to wait for and a Delay Duration (timeout). If the number of users is not reached within the timeout period, the test is triggered immediately.
Uniform Random Timer: Adds a random delay with a uniform distribution. You can configure a Constant Delay Offset (fixed delay) and a Random Delay Maximum (upper bound for the random delay). The total delay is the sum of the constant delay and a random value between 0 and the random delay maximum. Each random value has an equal probability of being chosen.
Gaussian Random Timer: Similar to the Uniform Random Timer, this timer adds a random delay. You can configure a Constant Delay Offset and a Random Delay Maximum. Use this timer if you require the random delay to follow a normal (Gaussian) distribution.
Constant Throughput Timer: Controls the throughput by executing test nodes at a specified rate. You can set the target throughput and the condition to which it applies. Conditions include This thread only, All active threads, All active threads in current link, All active threads (shared), and All active threads in the current link (shared).
Load test configuration
Click the Stress test configuration tab to set the load testing mode.
Parameter
Description
Stress source
The network type used for the test. You can select Public Network or Alibaba Cloud VPC. For more information, see Stress source (public network and VPC).
Concurrency
The number of virtual users that initiate requests. For example, a concurrency of 100 means 100 virtual users send requests at the same time.
Connections per user
The number of connection requests a single user can initiate.
Total connections
The total number of concurrent connections initiated by all virtual users. For example, if Concurrency is 100 and Connections per user is 2, the Total connections is 200.
Test duration
The recommended test duration is at least 2 minutes. The total duration cannot exceed 24 hours by default.
Traffic model
The model for increasing concurrency. When you select a different traffic model, the estimated load graph on the right side of the page refreshes accordingly.
Linear Ramp-up: This is the default model. The concurrency increases at a constant rate. The corresponding Estimated Stress Graph is a straight diagonal line.
Stepped Ramp-up: The concurrency increases in steps. The load increases by a set amount at each interval until it reaches the target concurrency, which is then maintained for a period. The corresponding Estimated Stress Graph is a step-like curve.
Constant Load: The concurrency is fixed. The Estimated Stress Graph is a flat horizontal line, indicating that the test runs at the specified concurrency from start to finish.
Ramp-up duration
The time it takes to ramp up from 0 to the maximum concurrency. You must configure this parameter if you select Linear Ramp-up or Stepped Ramp-up as the Traffic model.
Number of ramp-up steps
The number of steps to take during the ramp-up period. You must configure this parameter if you select Stepped Ramp-up as the Traffic model.
Number of specified IPs
The number of source IP addresses to use for the test. For more information, see Specify the number of stress source IPs.
Customize traffic region
Simulate user traffic from specific geographic locations by specifying the regions of the stress testing machines. After you enable this feature, you can configure the regional distribution of the stress machines to customize the geographic distribution of your test traffic. For more information, see Customize traffic regions.
Configure the maximum concurrency weight for all links in the scenario.
Parameter
Description
Max concurrency weight
The weight of the serial link relative to the total concurrency of the scenario. For example, if serial link 1 has a weight of 1 and serial link 2 has a weight of 3, they are allocated 25% and 75% of the total maximum concurrency, respectively.
Batch settings
Set the maximum concurrency weight for multiple links at once.
Select the serial links you want to configure.
Click Batch Settings and enter a value in the dialog box.
Click Confirm to apply the settings.
Run the test
Click Debug Scene in the lower-left corner of the page to validate your configuration. For more information, see Debug a scenario. Then, click Save and Run Test and click OK in the confirmation dialog box to start the test.
Next steps
View the load test report. For more information, see View multi-protocol load test reports.