Performance Tuning
# Preface
This document introduces the best practices for performance optimization of Kingdee Apusic Distributed Message Queue for RocketMQ (Apusic Distributed Message Queue for RocketMQ, referred to as: ADMQ for RocketMQ), helping users fully leverage system performance.
# Target Audience
This document is applicable to IT information business leaders, R&D managers, software project managers, software architects, and operations engineers.
# Related Documents
To learn more about ADMQ for RocketMQ related information, please refer to the following ADMQ for RocketMQ product documentation set:
| No. | Document | Description |
|---|---|---|
| 1 | Kingdee Apusic Distributed Message Queue for RocketMQ Quick Start Guide | Briefly introduces how to quickly get started with ADMQ for RocketMQ. |
| 2 | Kingdee Apusic Distributed Message Queue for RocketMQ Installation Manual | Details how to install ADMQ for RocketMQ on various operating systems, as well as starting and stopping ADMQ for RocketMQ services. |
| 3 | Kingdee Apusic Distributed Message Queue for RocketMQ Message Engine User Manual | Details the use, configuration, and management of ADMQ for RocketMQ message engine related functions and supporting tools. |
| 4 | Kingdee Apusic Distributed Message Queue for RocketMQ Console User Manual | Details the use and operation of ADMQ for RocketMQ console related functions. |
| 5 | Kingdee Apusic Distributed Message Queue for RocketMQ Development Manual | Details the development of ADMQ for RocketMQ client applications based on various development languages. |
| 6 | Kingdee Apusic Distributed Message Queue for RocketMQ Migration Manual | Details the migration from RocketMQ to ADMQ for RocketMQ. |
| 7 | Kingdee Apusic Distributed Message Queue for RocketMQ Operations Manual | Details monitoring, operation, security hardening, and other operational instructions for ADMQ for RocketMQ. |
| 8 | Kingdee Apusic Distributed Message Queue for RocketMQ Performance Optimization Manual | Details performance tuning instructions for ADMQ for RocketMQ. |
# Technical Support
ADMQ for RocketMQ products provide comprehensive technical support services. You can obtain technical support through the following methods:
- Website: www.apusic.com
- Phone: 400-855-5800
- Email: support@apusic.com
- Kingdee Cloud Community: https://vip.kingdee.com/?productId=73&productLineId=14&lang=zh-CN
When you obtain technical support, please provide the following information:
Your name
Company information and contact details
Operating system and its version
Product version number
Detailed logs, screenshots, etc. of exceptions and errors
# System-Level Optimization
# Operating System Optimization
# File Descriptors
# View current limit
ulimit -n
# Modify limit (/etc/security/limits.conf)
* soft nofile 65535
* hard nofile 65535
2
3
4
5
6
# Kernel Parameters
# /etc/sysctl.conf
# Increase port range
net.ipv4.ip_local_port_range = 1024 65535
# TCP connection optimization
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.core.somaxconn = 65535
# Memory optimization
vm.swappiness = 10
vm.dirty_ratio = 40
vm.dirty_background_ratio = 10
# Apply configuration
sysctl -p
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Disk Optimization
| Optimization Item | Suggestion |
|---|---|
| File System | Use XFS file system |
| Mount Options | noatime,nodiratime |
| Disk Scheduler | Use noop or deadline |
| RAID Configuration | Use RAID 10 or RAID 0 |
| SSD Optimization | Enable TRIM, reserve over-provisioning |
# View disk scheduling algorithm
cat /sys/block/sda/queue/scheduler
# Set to deadline
echo deadline > /sys/block/sda/queue/scheduler
# Mount options (/etc/fstab)
/dev/sda1 /data/rocketmq xfs noatime,nodiratime 0 0
2
3
4
5
6
7
8
# Network Optimization
# Network buffer
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
net.ipv4.tcp_rmem = 4096 87380 134217728
net.ipv4.tcp_wmem = 4096 65536 134217728
# TCP optimization
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_no_metrics_save = 1
2
3
4
5
6
7
8
9
10
11
# RocketMQ Configuration Optimization
# Broker Configuration
| Parameter | Default | Recommended | Description |
|---|---|---|---|
| sendMessageThreadPoolNums | 1 | CPU cores | Number of send message threads |
| pullMessageThreadPoolNums | 16+ | Adjust based on load | Number of pull message threads |
| queryMessageThreadPoolNums | 8 | Adjust based on load | Number of query message threads |
| adminBrokerThreadPoolNums | 16 | Adjust based on load | Number of admin operation threads |
| brokerRole | ASYNC_MASTER | SYNC_MASTER | Broker role |
| flushDiskType | ASYNC_FLUSH | SYNC_FLUSH | Flush disk mode |
| flushIntervalCommitLog | 500ms | Based on reliability requirements | CommitLog flush interval |
| flushIntervalConsumeQueue | 1000ms | Based on reliability requirements | ConsumeQueue flush interval |
# broker.conf
sendMessageThreadPoolNums=16
pullMessageThreadPoolNums=16
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH
flushIntervalCommitLog=500
flushIntervalConsumeQueue=1000
2
3
4
5
6
7
# Storage Configuration
| Parameter | Default | Recommended | Description |
|---|---|---|---|
| mapedFileSizeCommitLog | 1GB | 1GB | CommitLog file size |
| mapedFileSizeConsumeQueue | 300MB | 300MB | ConsumeQueue file size |
| flushCommitLogTimed | false | false | Whether to flush disk periodically |
| deleteWhen | 04 | 04 | Time to delete expired files |
| fileReservedTime | 72 | Based on disk capacity | File retention time (hours) |
| diskMaxUsedSpaceRatio | 75 | 75 | Maximum disk usage ratio |
# broker.conf
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000000
deleteWhen=04
fileReservedTime=72
diskMaxUsedSpaceRatio=75
2
3
4
5
6
# JVM Configuration
# NameServer JVM
# bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g"
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m"
JAVA_OPT="${JAVA_OPT} -XX:G1ReservePercent=25"
JAVA_OPT="${JAVA_OPT} -XX:InitiatingHeapOccupancyPercent=30"
2
3
4
5
# Broker JVM
# bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m"
JAVA_OPT="${JAVA_OPT} -XX:G1ReservePercent=25"
JAVA_OPT="${JAVA_OPT} -XX:InitiatingHeapOccupancyPercent=30"
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=4g"
2
3
4
5
6
# Client Optimization
# Producer Optimization
# Send Mode Selection
| Send Mode | Throughput | Reliability | Use Case |
|---|---|---|---|
| Synchronous Send | Medium | High | Scenarios requiring confirmation |
| Asynchronous Send | High | Medium | High throughput scenarios |
| One-way Send | Very High | Low | Log collection, etc. |
| Batch Send | Very High | Medium | High throughput scenarios |
# Producer Parameters
DefaultMQProducer producer = new DefaultMQProducer("test-group");
producer.setNamesrvAddr("localhost:9876");
// Send timeout
producer.setSendMsgTimeout(3000);
// Message body compression threshold (compress if exceeded)
producer.setCompressMsgBodyOverHowmuch(1024 * 4);
// Maximum message size
producer.setMaxMessageSize(1024 * 1024 * 4);
// Retry count
producer.setRetryTimesWhenSendFailed(2);
producer.setRetryTimesWhenSendAsyncFailed(2);
// Whether to retry another Broker on internal send failure
producer.setRetryAnotherBrokerWhenNotStoreOK(false);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Batch Send
List<Message> messages = new ArrayList<>();
for (int i = 0; i < 100; i++) {
messages.add(new Message("batch-topic", "tag-a", ("msg-" + i).getBytes()));
}
// Batch send, single batch should not exceed 1MB
producer.send(messages);
2
3
4
5
6
# Consumer Optimization
# Consumer Thread Count
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("test-group");
consumer.setNamesrvAddr("localhost:9876");
// Minimum consumer thread count
consumer.setConsumeThreadMin(20);
// Maximum consumer thread count
consumer.setConsumeThreadMax(64);
// Consumption timeout (minutes)
consumer.setConsumeTimeout(15);
2
3
4
5
6
7
8
9
10
11
# Consumption Batch Size
// Maximum number of messages per consumption
consumer.setConsumeMessageBatchMaxSize(10);
// Maximum number of messages per pull
consumer.setPullBatchSize(32);
// Pull interval (milliseconds)
consumer.setPullInterval(0);
2
3
4
5
6
7
8
# Consumption Offset Strategy
// Start consumption from the last offset
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
// Start consumption from the first offset
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
// Start consumption from a specified time
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_TIMESTAMP);
consumer.setConsumeTimestamp("20260101000000");
2
3
4
5
6
7
8
9
# Cluster Optimization
# Node Deployment Strategy
| Deployment Strategy | Description | Use Case |
|---|---|---|
| Same Data Center Deployment | All nodes in the same data center | Low latency, high throughput |
| Cross Data Center Deployment | Nodes distributed across different data centers | High availability, disaster recovery |
| Heterogeneous Deployment | Mix of different configuration nodes | Cost optimization |
# Master-Slave Replication Optimization
# Synchronous Replication vs Asynchronous Replication
| Replication Mode | Reliability | Performance | Use Case |
|---|---|---|---|
| Synchronous Replication | High | Low | Strong consistency scenarios like financial transactions |
| Asynchronous Replication | Medium | High | General business scenarios |
# broker.conf
# Synchronous replication
brokerRole=SYNC_MASTER
# Asynchronous replication
brokerRole=ASYNC_MASTER
2
3
4
5
6
# Flush Strategy Optimization
# Synchronous Flush vs Asynchronous Flush
| Flush Mode | Reliability | Performance | Use Case |
|---|---|---|---|
| Synchronous Flush | High | Low | Strong consistency scenarios |
| Asynchronous Flush | Medium | High | General business scenarios |
# broker.conf
# Synchronous flush
flushDiskType=SYNC_FLUSH
# Asynchronous flush
flushDiskType=ASYNC_FLUSH
2
3
4
5
6
# Topic Queue Count Optimization
| Scenario | Queue Count Suggestion |
|---|---|
| Low Throughput | 4-8 |
| Medium Throughput | 8-16 |
| High Throughput | 16-32 |
| Very High Throughput | 32-64 |
# Specify queue count when creating Topic
bin/mqadmin updateTopic -n localhost:9876 -c DefaultCluster -t test-topic -r 16 -w 16
2
# Monitoring and Tuning
# Performance Metrics
| Metric | Healthy Range | Optimization Suggestion |
|---|---|---|
| Broker TPS | Based on hardware configuration | Scale up or optimize producers |
| Consumption TPS | Close to production TPS | Add consumers or optimize consumption logic |
| Message Accumulation | < 1 million | Add consumers or optimize consumption logic |
| Disk Usage | < 75% | Scale up or clean expired messages |
| Memory Usage | < 80% | Increase memory or optimize JVM parameters |
| Consumption Lag | < 1 second | Optimize consumption logic or add consumers |
# Performance Testing
# Test using benchmark tool
bin/benchmark.sh producer -n localhost:9876 -t test-topic -s 128 -w 16
# Parameter description
# -n: NameServer address
# -t: Topic name
# -s: Message size (bytes)
# -w: Concurrency count
2
3
4
5
6
7
8
# Bottleneck Analysis
- CPU Bottleneck: Insufficient send/consume threads, compression/decompression, serialization
- Memory Bottleneck: Frequent JVM GC, insufficient DirectBuffer
- Disk Bottleneck: Flush mode, insufficient disk I/O, file system performance
- Network Bottleneck: Cross-data center deployment, insufficient bandwidth, network latency
# Common Issue Optimization
# Message Accumulation Optimization
- Increase consumer count
- Optimize consumer processing logic
- Increase consumption thread count
- Use batch consumption
- Scale up Broker nodes
# Send Performance Optimization
- Use asynchronous sending
- Use batch sending
- Increase producer count
- Optimize message size
- Disable message tracing (if not needed)
# Consumption Lag Optimization
- Increase consumption thread count
- Optimize consumption logic
- Use concurrent consumption
- Scale up consumers
- Check for slow consumers
# Performance Optimization Checklist
# System Level
- [ ] File descriptor limits have been adjusted
- [ ] Kernel parameters have been optimized
- [ ] Disk uses XFS file system
- [ ] Network parameters have been optimized
- [ ] System resources are sufficient (CPU, memory, disk)
# RocketMQ Configuration
- [ ] Broker thread count set appropriately
- [ ] Flush strategy selected based on business
- [ ] Replication strategy selected based on business
- [ ] File retention time set appropriately
- [ ] JVM parameters have been optimized
# Client Optimization
- [ ] Send mode selected appropriately
- [ ] Consumption thread count set appropriately
- [ ] Batch size set appropriately
- [ ] Retry count set appropriately
- [ ] Consumption offset strategy selected appropriately
# Cluster Optimization
- [ ] Topic queue count set appropriately
- [ ] Master-slave replication strategy selected appropriately
- [ ] Flush strategy selected appropriately
- [ ] Cluster scale meets business requirements
- [ ] Node deployment strategy selected appropriately