Fundamentals 9 min read

Why Does Kafka Outperform RocketMQ? The Role of Zero‑Copy Techniques

The article explains how Kafka’s use of sendfile zero‑copy gives it higher throughput than RocketMQ, which relies on mmap, and discusses the trade‑offs between performance and feature richness when choosing between the two message‑queue systems.

ITPUB
ITPUB
ITPUB
Why Does Kafka Outperform RocketMQ? The Role of Zero‑Copy Techniques

RocketMQ’s architecture is inspired by Kafka’s design, yet Kafka still outperforms it in throughput because of differences in zero‑copy implementations.

What Is Zero‑Copy?

Message queues store data on disk to avoid loss on crashes. When sending data from disk to a consumer, the operating system moves data between user space and kernel space, typically involving multiple copies and system calls.

Message Sending Process

The steps are:

Program calls read() → data copied from disk device to kernel buffer.

Data copied from kernel buffer to user space.

Program calls write() → data copied from user space to socket send buffer.

Data copied from socket buffer to NIC.

This involves 2 system calls, 4 user‑kernel switches, and 4 data copies.

Zero‑Copy Techniques

Two common methods reduce these copies: mmap: maps kernel buffers into user space, eliminating the user‑kernel copy for the read step. sendfile: transfers data directly from kernel buffer to NIC, bypassing user space entirely.

Using mmap

With mmap(), the program calls the system call, the kernel copies data from disk to its buffer, then maps that buffer into user space without an extra copy. A subsequent write() still copies data to the socket buffer, so the overall process reduces one user‑kernel copy.

Result: 2 system calls, 4 user‑kernel switches, and 3 data copies (one less than the original flow).

Using sendfile

The sendfile() system call reads data from the disk into a kernel buffer and then sends it directly to the NIC, skipping the user‑space copy entirely.

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

Result: 1 system call, 2 user‑kernel switches, and 2 data copies, achieving higher throughput.

Why Kafka Is Faster

Kafka uses sendfile, which reduces both the number of system calls and data copies compared to RocketMQ’s mmap approach. This gives Kafka a performance edge, though RocketMQ gains richer features such as message filtering, transaction support, delayed and dead‑letter queues, which require access to the message content.

Choosing Between Kafka and RocketMQ

If the workload is big‑data‑oriented (e.g., integrates with Spark or Flink), Kafka is recommended for its raw performance. Otherwise, when the ecosystem already supports RocketMQ or when advanced messaging features are needed, RocketMQ may be the better choice.

Summary

RocketMQ simplifies coordination and adds more messaging features compared to Kafka.

Kafka’s use of sendfile yields higher throughput by minimizing copies and kernel‑user switches.

RocketMQ sacrifices some performance to provide richer functionality.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceMessage QueueRocketMQmmapsendfileZero Copy
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

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.