Backend Development 8 min read

Why RocketMQ Lags Behind Kafka in Performance: The Impact of Zero‑Copy Techniques

The article explains how RocketMQ’s reliance on mmap‑based zero‑copy leads to more data copies and system‑call overhead compared to Kafka’s sendfile approach, resulting in lower throughput, and discusses when to choose each message‑queue system based on functional needs and performance requirements.

IT Services Circle
IT Services Circle
IT Services Circle
Why RocketMQ Lags Behind Kafka in Performance: The Impact of Zero‑Copy Techniques

RocketMQ’s architecture borrows heavily from Kafka, but despite similar design ideas it often shows lower throughput because its zero‑copy implementation uses mmap , which still requires multiple data copies between disk, kernel, and user space.

The typical message‑sending flow involves reading data from disk into kernel buffers ( read() ), copying it to user space, then writing it out to the network ( write() ), resulting in several user‑kernel transitions and copies.

Zero‑copy aims to reduce these copies. In the traditional path, the data is copied twice (disk → kernel, kernel → user) and then again for network transmission, leading to two system calls and four copy operations.

Using mmap maps the kernel buffer directly into user space, eliminating the user‑space copy for the read step. The process still involves a read() system call, a kernel‑to‑socket copy, and a socket‑to‑NIC copy, totaling two system calls and three copies.

void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);

In contrast, sendfile transfers data from a file descriptor to a socket entirely within the kernel, requiring only one system call and reducing copies to two (disk → kernel, kernel → NIC), effectively achieving “zero‑CPU copy”.

ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);

Kafka adopts sendfile , gaining higher performance due to fewer copies and context switches, while RocketMQ retains mmap to preserve access to the message payload for features like dead‑letter queues and message replay, sacrificing some speed for richer functionality.

The article concludes that the choice between Kafka and RocketMQ depends on the scenario: for big‑data pipelines (e.g., Spark, Flink) Kafka is preferred for raw throughput, whereas RocketMQ is suitable when advanced messaging features are needed and the component ecosystem supports it.

Summary:

RocketMQ simplifies some coordination aspects but adds functional features, resulting in extra copy overhead.

Kafka’s leaner architecture and use of sendfile provide higher throughput.

Zero‑copy techniques differ: mmap reduces user‑space copies, while sendfile eliminates them entirely from the CPU’s perspective.

Choosing the right system requires balancing performance against feature requirements.

performanceKafkaMessage QueuerocketmqMMAPsendfileZero Copy
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.