How to Load Test RocketMQ with JMeter on Alibaba Cloud PTS
This guide walks you through using Alibaba Cloud PTS and JMeter 5.5 to create a custom JavaSampler for RocketMQ 5.0, package the sampler into a JAR, configure a PTS JMeter environment, run an RPS‑mode load test, and analyze the detailed performance report.
Background
Before a new service goes live, each middleware should be stress‑tested to determine its traffic ceiling under the current configuration. Alibaba Cloud PTS can run custom JMeter scripts in a distributed manner, making it suitable for benchmarking middleware such as RocketMQ.
Prerequisites
JMeter 5.5 installed locally.
RocketMQ deployed on an Alibaba Cloud ECS instance (e.g., 8 CPU × 32 GB).
PTS service enabled on the same Alibaba Cloud account.
Step 1 – Create a Maven project and add dependencies
Add the following dependencies to pom.xml:
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>5.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId>
<version>4.9.5</version>
</dependency>The ApacheJMeter_java dependency provides the JavaSampler; rocketmq-client is the RocketMQ client library. The provided scope avoids bundling JMeter twice.
Configure the Maven Assembly plugin to produce a “jar‑with‑dependencies”:
<build>
<finalName>jmeter-rocketmq4</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>Step 2 – Implement a custom AbstractJavaSamplerClient
Create a class that extends AbstractJavaSamplerClient and implements the four required methods. The example below creates a RocketMQ producer in setupTest, sends a message in runTest, and shuts down the producer in teardownTest.
import java.nio.charset.StandardCharsets;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.rocketmq.client.exception.*;
import org.apache.rocketmq.client.producer.*;
import org.apache.rocketmq.common.message.Message;
public class JavaSamplerForRocketMQ extends AbstractJavaSamplerClient {
private DefaultMQProducer producer;
private static final String NAME_SRV_ADDRESS = "nameSrvAddress";
private static final String TOPIC = "topic";
private static final String PRODUCER_GROUP = "producer group";
private static final String MSG_BODY = "messageBody";
private static final String MSG_TAG = "messageTag";
private static final String ERROR_CODE = "500";
@Override
public void setupTest(JavaSamplerContext ctx) {
try {
producer = new DefaultMQProducer(ctx.getParameter(PRODUCER_GROUP));
producer.setNamesrvAddr(ctx.getParameter(NAME_SRV_ADDRESS));
producer.start();
} catch (MQClientException e) {
throw new RuntimeException(e);
}
}
@Override
public SampleResult runTest(JavaSamplerContext ctx) {
SampleResult sr = new SampleResult();
sr.setSampleLabel("rocketmq-producer");
sr.sampleStart();
Message msg = new Message(
ctx.getParameter(TOPIC),
ctx.getParameter(MSG_TAG),
ctx.getParameter(MSG_BODY).getBytes()
);
try {
SendResult res = producer.send(msg);
sr.setSentBytes(msg.toString().getBytes(StandardCharsets.UTF_8).length);
sr.setDataType(SampleResult.TEXT);
sr.setSamplerData(msg.toString());
sr.setResponseData(String.format("Msg Id:%s", res.getMsgId()).getBytes());
sr.setSuccessful(true);
sr.setResponseCodeOK();
} catch (MQBrokerException | InterruptedException | RemotingException | MQClientException e) {
sr.setSuccessful(false);
sr.setResponseCode(ERROR_CODE);
sr.setResponseData(String.format("Error Msg:%s", e).getBytes());
return sr;
} finally {
sr.sampleEnd();
}
return sr;
}
@Override
public void teardownTest(JavaSamplerContext ctx) {
producer.shutdown();
}
@Override
public Arguments getDefaultParameters() {
Arguments args = new Arguments();
args.addArgument(NAME_SRV_ADDRESS, "");
args.addArgument(PRODUCER_GROUP, "");
args.addArgument(TOPIC, "");
args.addArgument(MSG_TAG, "");
args.addArgument(MSG_BODY, "");
return args;
}
}Step 3 – Package the project into a JAR
Run mvn clean package. The target directory will contain two JARs, the “jar‑with‑dependencies” JAR being the one to upload to PTS.
.
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── JavaSamplerForRocketMQ.java
│ │ └── resources
│ └── test
│ └── java
└── target
├── jmeter-rocketmq4-jar-with-dependencies.jar
├── jmeter-rocketmq4.jarStep 4 – Prepare JMeter GUI
Copy the “jar‑with‑dependencies” JAR (and any additional JARs) to JMETER_HOME/lib/ext and launch JMeter with JMETER_HOME/bin/jmeter.
Create a Thread Group and add a Java Request Sampler .
Select the fully‑qualified class name of the sampler (e.g., com.example.JavaSamplerForRocketMQ) and fill in the parameters defined in getDefaultParameters.
Add “View Results Tree” and “Summary Report” listeners, then start the test.
Save the test plan as a JMX file.
Step 5 – Create a JMeter environment in PTS and upload the JAR
In the PTS console, choose “JMeter Environment”.
Enter a custom environment name.
Upload the JAR produced in Step 3.
Save the environment.
Step 6 – Create a PTS JMeter test scene
Select “JMeter Load Test” as the scene type.
Provide a scene name and upload the JMX file from Step 4.
Enable “Use dependent environment” and select the environment created in Step 5.
Configure the pressure source as Alibaba Cloud VPC internal network, match the ECS region, and ensure the security group allows RocketMQ ports.
Choose RPS mode, set start RPS = 90 000, max RPS = 110 000, duration = 2 minutes.
Leave loop count as “No” (single execution).
Use RPS mode to directly measure the maximum concurrent request capacity of RocketMQ, and run the test inside the VPC to avoid public‑bandwidth bottlenecks.
Step 7 – View and analyze the load‑test report
The report displays overall success rate, average response time, TPS, etc. For example, a success‑rate drop at a certain timestamp coincided with a TPS of approximately 95 561 requests per second.
Prometheus data in the report can be queried with PromQL. Example query for success rate:
sum(rate(pts_api_response_total{task_id="$task_id",code=~"200|302"}[5s]))/sum(rate(pts_api_response_total{task_id="$task_id"}[5s]))Further analysis showed that increasing JVM heap size up to 24 GB did not yield significant gains, while raising sendMessageThreadPoolNums beyond 16 offered diminishing returns.
Conclusion
This tutorial demonstrates how to combine JMeter’s extensible JavaSampler with Alibaba Cloud PTS to perform fine‑grained, distributed load testing of RocketMQ. By packaging the sampler, configuring a PTS scene, and leveraging Prometheus‑based reporting, users can accurately determine the middleware’s throughput limits and make informed capacity‑planning decisions.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Native
We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
