MINOR: Update jmh to 1.27 for async profiler support#9129
Conversation
|
Actually, it looks like I need to improve the jmh script to make this easier to use. Will also update the README. So, please don't review it yet. |
|
@omkreddy this is ready for review. |
There was a problem hiding this comment.
Rather than "in order to verify that they are valid", how about "in order to verify that they are measuring what you think they are. For example, if you use mocks they may use reflection that can easily dominate the benchmark's run time.".
There was a problem hiding this comment.
While we're at it we can also mention -prof gc and how you should look for the norm allocation rate (since we care about garbage generated per operation rather than per second).
There was a problem hiding this comment.
I'll provide some text for this soon.
There was a problem hiding this comment.
Sure. Do you think I should have only the link to jmh-benchmarks/README.md and have all the information on to use it in that page?
There was a problem hiding this comment.
Including only the link sounds good.
There was a problem hiding this comment.
Let's drop this and include that link before merge.
There was a problem hiding this comment.
Yeah, I fixed this in my local copy, but I wanted to test it before pushing the changes.
|
@ijuma the text mode output here looks good however it would be good to include instructions for producing an svg flamegraph if possible. Do you know if we can do that? |
There was a problem hiding this comment.
Suggested addition:
Using JMH GC profiler
It's good practice to run your benchmark with -prof gc to measure the allocation rate for your code:
./jmh-benchmarks/jmh.sh -prof gc
Of particular importance is the "norm" alloc rates, which measure the allocations per operation rather than allocations per second which can increase when you have made your code faster.
There was a problem hiding this comment.
We should document this variant instead so linux and mac os users are covered.
-prof async:libPath=/Users/lucas/Downloads/async-profiler-1.8-macos-x64/build/libasyncProfiler.so
There was a problem hiding this comment.
Agreed, I tested this variant on Mac, but not Linux yet. Will do before changing.
|
@ijuma we should bump this to 1.26 as it has some relevant bug fixes, e.g. openjdk/jmh@2398e8e |
chia7712
left a comment
There was a problem hiding this comment.
I love those new document about JMH usage.
|
@lbradstreet @chia7712 @omkreddy Please take a look when you have a chance. |
There was a problem hiding this comment.
The file name of async-profiler is libasyncProfiler.so. Should we follow the naming in this example?
There was a problem hiding this comment.
Yeah, that makes sense. Will do when I'm near a computer.
Highlights: * async-profiler integration. Can be used with -prof async, pass -prof async:help to look for the accepted options. * perf c2c [2] integration. Can be used with -prof perfc2c, if available. Full details: https://mail.openjdk.java.net/pipermail/jmh-dev/2020-August/002982.html
| <Package name="org.apache.kafka.jmh.consumer.generated"/> | ||
| </Or> | ||
| <!-- Suppress some minor warnings about machine-generated code for benchmarking. --> | ||
| <Package name="~org\.apache\.kafka\.jmh\..*\.jmh_generated"/> |
There was a problem hiding this comment.
jmh now uses jmh_generated instead of generated.
|
@chia7712 Pushed a couple of follow ups. I think this is ready to merge. |
chia7712
left a comment
There was a problem hiding this comment.
+1 and thanks for this patch. It does give a good guideline about JMH on kafka.
|
|
||
| ### Using JMH with async profiler | ||
|
|
||
| It's good practice to check profiler output for microbenchmarks in order to verify that they are valid. |
There was a problem hiding this comment.
How about:
"It's good practice to check profiler output for microbenchmarks in order to verify that they represent application behavior and measure what you expect to measure. Some example pitfalls include the use of expensive mocks or accidental inclusion of test setup code in the benchmarked code."
|
|
||
| java -jar <kafka-repo-dir>/jmh-benchmarks/build/libs/kafka-jmh-benchmarks-all.jar -f2 LRUCacheBenchmark | ||
|
|
||
| ### Writing benchmarks |
There was a problem hiding this comment.
Could we include a short section here about what should be put into a PR that has been benchmarked?
I'm thinking:
- Benchmark comparisons for the code before and after the change.
-prof gcresults.- An example async profile from at least one run.
There was a problem hiding this comment.
Good idea. We should also link from the contributor docs.
There was a problem hiding this comment.
I will do this in a separate PR since it's a bit unrelated to the original goal of this PR and it may take a few iterations to get right.
Also updated the jmh readme to make it easier for new people to know
what's possible and best practices.
There were some changes in the generated benchmarking code that
required adjusting
spotbugs-exclude.xmland for ajavacwarningto be suppressed for the benchmarking module. I took the chance
to make the spotbugs exclusion mode maintainable via a regex
pattern.
Tested the commands on Linux and macOS with zsh.
JMH highlights:
pass -prof async:help to look for the accepted options.
if available.
-prof jfr:help to look for the accepted options.
Full details:
Committer Checklist (excluded from commit message)