DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Optimizing Java Applications for Arm64 in the Cloud
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Exploring Exciting New Features in Java 17 With Examples
  • Java and Low Latency

Trending

  • Stop Choosing Sides: An Engineering Leader's Framework for Build, Buy, and Hybrid AI Agents in 2026
  • Reproducible Development Environments, One Command Away: Introducing CodingBooth
  • From 24 Hours to 2 Hours: How We Fixed a Broken BI System With Apache Airflow
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It
  1. DZone
  2. Coding
  3. Java
  4. Apache RocketMQ: How We Lowered Latency

Apache RocketMQ: How We Lowered Latency

See how latency was lowered in Apache RocketMQ.

By 
Andy Shi user avatar
Andy Shi
·
Jun. 07, 19 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
21.7K Views

Join the DZone community and get the full member experience.

Join For Free

Apache RocketMQ

Apache RocketMQ is a distributed messaging and streaming data platform open sourced by Alibaba.

Here is the typical deployment topology:

Image title

At first glance, it looks pretty similar to other products, such as Kafka.

In fact, even the NameServer in the above diagram is Zookeeper, the same as Kafka.

To end the confusion, I would like to share a couple lessons we learned in the process of shaping this project.

In this article, I’ll start with one of the major features: low latency.

Little’s Law

Image title

Little’s law states that the occupancy = latency x throughput.

If occupancy is a set number, the lower the latency, the higher the throughput. In order to maximize the throughput, we have to minimize the latency.

RocketMQ is a pure Java implementation. By “pure” I mean rocketMQ has developed its own memory, storage, and all the other modules, all of which has to be fine-tuned to avoid huge latency.

Image title

JVM Stall:

JVM stall happens a lot, such as during GC, JIT, RevokeBias, and RedefineClasses, to name a few. Many of us already know how to fine-tune GC: via adjusting heap size, changing GC timing, optimizing data structure, etc. But how do we tune the other JVM stalls?

One approach to the issue is to use -XX:+PrintGCApplicationStoppedTime with XX:+PrintSafepointStatistics and -XX: flags to isolate the trouble maker. For example, if we can identify RevokeBias is causing the stall, we can use -XX:-UseBiasedLocking to turn off the biased lock.

Memory Reclaim

When RocketMQ is applying for new memory pages, there is a chance that will cause the Linux system to get into a stage called direct reclaim, which may cause huge latency.

Image title

Another problem we run into is when the kernel reclaims the memory, if that page is loaded from swap space, it may cause file I/O, which leads to huge delay.

Image title

To solve these two issues, we played with different combinations of vm.extra_free_kbytes and vm.swappiness to get the optimal result.

In most Linux versions, the memory page size is 4K. If your application somehow creates a read/write racing condition on the same page, the latency will be a huge problem. To avoid this issue, we tried different ways to coordination memory access.

Conclusion

As they say: the devil is in the details. Many of the fine-tuning processes are trivia yet important. After the optimization, the project is able to handle very tough challenges.

The following is the result of the latency benchmark:

Image title

philosophy Memory (storage engine) Java (programming language) garbage collection Java virtual machine Throughput (business) Law (stochastic processes) Data (computing) kafka Linux (operating system)

Opinions expressed by DZone contributors are their own.

Related

  • Optimizing Java Applications for Arm64 in the Cloud
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Exploring Exciting New Features in Java 17 With Examples
  • Java and Low Latency

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook