[improve][build] Add Async Profiler integration for integration tests - #24688
Merged
lhotari merged 20 commits intoSep 1, 2025
Conversation
- results in about 10% better throughput - latency reduced even more
lhotari
requested review from
BewareMyPower,
codelipenghui,
dao-jun and
nodece
August 30, 2025 11:32
- similar as in java-test-image
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #24688 +/- ##
=============================================
+ Coverage 38.60% 74.11% +35.50%
- Complexity 12971 33005 +20034
=============================================
Files 1836 1893 +57
Lines 143700 147811 +4111
Branches 16616 17098 +482
=============================================
+ Hits 55475 109545 +54070
+ Misses 80664 29512 -51152
- Partials 7561 8754 +1193
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
lhotari
requested review from
Technoboy-,
eolivelli,
heesung-sohn,
nicoloboschi,
poorbarcode and
thetumbled
August 31, 2025 15:54
dao-jun
approved these changes
Sep 1, 2025
This was referenced Sep 1, 2025
KannarFr
pushed a commit
to CleverCloud/pulsar
that referenced
this pull request
Sep 22, 2025
walkinggo
pushed a commit
to walkinggo/pulsar
that referenced
this pull request
Oct 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Async Profiler is a powerful profiler, but it requires using Linux to get more accurate profiling results. When the main development workflow is on Mac for many like me, I started to wonder if it's possible to set up Async Profiler with the more accurate profiling mode using Docker. I use OrbStack (instead of Docker Desktop) on Mac to develop Apache Pulsar. I wanted to be able to create simple scenarios that take a few minutes to run and analyze the results with various tools. For example, converting flamegraphs to .html format with various views (such as per-thread CPU flamegraphs, allocation flamegraphs, and lock flamegraphs) and using Eclipse Mission Control to analyze GC events and other details that Async Profiler is able to collect together with Java Flight Recorder in its "jfrsync" mode.
This work extends the Async Profiler support that was added in #24623 for directly profiling unit tests in the same process. The downside of that approach is that there will be too many aspects included, which skew the results and make it not useful for validating the performance of actual production code. It also had the problem that Async Profiler on Mac doesn't support the more accurate CPU profiling modes that Async Profiler supports on Linux. This is explained in https://github.com/async-profiler/async-profiler/blob/master/docs/CpuSamplingEngines.md.
On Mac, it's not possible to profile native methods either, such as profiling the sources of exceptions. With Async Profiler, it's possible to specify
event=Java_java_lang_Throwable_fillInStackTrace,tree,reverseto profile exception sources. (btw. JFR has alsojdk.JavaExceptionThrowandjdk.JavaErrorThrowevents which could be used, but the exception event isn't enabled by default).Modifications
Additional information
While profiling on Mac, I noticed that memory alloc and free would show up in flamegraphs. It seems that virtualization has an overhead and one way to reduce that is to use Transparent Huge Pages ("madvise" mode is recommended on Linux). That is explained in the sample test PulsarProfilingTest. That links to https://shipilev.net/jvm/anatomy-quarks/2-transparent-huge-pages/ which explains details. Large memory pages significantly reduce memory alloc and free overhead and this matters a lot in virtualized platforms. Therefore, it would also be useful to recommend
-XX:+UseTransparentHugePagesfor Pulsar production deployments.-XX:+AlwaysPreTouchwould also be recommended.The throughput in Mac Orbstack improved over 10% and latency reduced even more for the sample PulsarProfilingTest that runs at full throughtput for 3 minutes.
For actual production environment profiling, besides async-profiler, AWS aperf seems like a great tool for Linux environments (it's not AWS specific). It also integrates with async-profiler.
AWS provides recommendations about using THP in "madvise" or "always" mode. ("always" mode could cause issues so I wouldn't recommend using it, my recommendation is "madvise" mode). There's also a recommendation about
-XX:+UseTransparentHugePagesand it also mentions:
There's a significant high risk for performance degradation when using "always" mode (which is the Linux default). That risk is low for "madvise" mode. Some of the details are explained in this blog post: https://www.evanjones.ca/hugepages-are-a-good-idea.html .
Documentation
docdoc-requireddoc-not-neededdoc-complete