Skip to content

MINOR: Update jmh to 1.27 for async profiler support#9129

Merged
ijuma merged 12 commits into
apache:trunkfrom
ijuma:jmh-1.24
Dec 11, 2020
Merged

MINOR: Update jmh to 1.27 for async profiler support#9129
ijuma merged 12 commits into
apache:trunkfrom
ijuma:jmh-1.24

Conversation

@ijuma

@ijuma ijuma commented Aug 5, 2020

Copy link
Copy Markdown
Member

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.xml and for a javac warning
to 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:

  • 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.
  • JFR profiler integration. Can be used with -prof jfr, pass
    -prof jfr:help to look for the accepted options.

Full details:

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@ijuma

ijuma commented Aug 5, 2020

Copy link
Copy Markdown
Member Author

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.

@ijuma

ijuma commented Aug 11, 2020

Copy link
Copy Markdown
Member Author

@omkreddy this is ready for review.

@bbejeck bbejeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ijuma LGTM.

The test failures are related due to spotbugs findings. But considering what's changed here I can't see what it could be.

Comment thread README.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.".

Comment thread README.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll provide some text for this soon.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including only the link sounds good.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop this and include that link before merge.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I fixed this in my local copy, but I wanted to test it before pushing the changes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@lbradstreet

Copy link
Copy Markdown
Contributor

@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?

@ijuma ijuma changed the title MINOR: Update jmh to 1.24 for async profiler support MINOR: Update jmh to 1.25 for async profiler support Aug 22, 2020

@lbradstreet lbradstreet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a few suggested changes.

Comment thread jmh-benchmarks/README.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add.

Comment thread jmh-benchmarks/README.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I tested this variant on Mac, but not Linux yet. Will do before changing.

@lbradstreet

Copy link
Copy Markdown
Contributor

@ijuma we should bump this to 1.26 as it has some relevant bug fixes, e.g. openjdk/jmh@2398e8e

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love those new document about JMH usage.

@ijuma ijuma changed the title MINOR: Update jmh to 1.25 for async profiler support MINOR: Update jmh to 1.26 for async profiler support Dec 9, 2020
@ijuma ijuma changed the title MINOR: Update jmh to 1.26 for async profiler support MINOR: Update jmh to 1.27 for async profiler support Dec 9, 2020
@ijuma

ijuma commented Dec 10, 2020

Copy link
Copy Markdown
Member Author

@lbradstreet @chia7712 @omkreddy Please take a look when you have a chance.

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijuma +1 to this nice documentation.

Comment thread jmh-benchmarks/README.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file name of async-profiler is libasyncProfiler.so. Should we follow the naming in this example?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. Will do when I'm near a computer.

<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"/>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jmh now uses jmh_generated instead of generated.

@ijuma

ijuma commented Dec 10, 2020

Copy link
Copy Markdown
Member Author

@chia7712 Pushed a couple of follow ups. I think this is ready to merge.

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 and thanks for this patch. It does give a good guideline about JMH on kafka.

Comment thread jmh-benchmarks/README.md Outdated

### Using JMH with async profiler

It's good practice to check profiler output for microbenchmarks in order to verify that they are valid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add.

Comment thread jmh-benchmarks/README.md

java -jar <kafka-repo-dir>/jmh-benchmarks/build/libs/kafka-jmh-benchmarks-all.jar -f2 LRUCacheBenchmark

### Writing benchmarks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we include a short section here about what should be put into a PR that has been benchmarked?

I'm thinking:

  1. Benchmark comparisons for the code before and after the change.
  2. -prof gc results.
  3. An example async profile from at least one run.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. We should also link from the contributor docs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ijuma ijuma merged commit 8cabd57 into apache:trunk Dec 11, 2020
@ijuma ijuma deleted the jmh-1.24 branch December 11, 2020 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants