Skip to content

Conversation

@dweiss
Copy link
Contributor

@dweiss dweiss commented Oct 12, 2023

As per discussion in: #12641

This patch adds the ability to compile JMH microbenchmarks and run them from within Lucene codebase. I didn't use any plugins as they, in my opinion, obscure the view of what's happening and what's needed. I also wanted it to work with the module system and without uber-jars.

gradlew -p lucene/benchmark-jmh assemble

compiles microbenchmarks with JMH, then displays a short help on what to do next:

JMH benchmarks compiled. Run them with:

java -jar lucene\benchmark-jmh\build\benchmarks\lucene-benchmark-jmh-10.0.0-SNAPSHOT.jar

or

java --module-path lucene\benchmark-jmh\build\benchmarks --module org.apache.lucene.benchmark.jmh

JMH options you can use with the above:

  -h      displays verbose help for all options
  -l      list available benchmarks
  -lp     list benchmarks that pass the filter and their parameters
  regexp  execute all benchmark containing regexp

I didn't add any gradle-specific tasks to run the benchmarks directly - it's technically easy but it seems like a bad idea to fork a subprocess from (quite heavy) gradle when such delicate things are being measured? I'm not sure here.

Some future improvements/ remaining issues include:

  1. multi-source compilation so that code can be compiled against future APIs (not the one gradle runs with).
  2. forbiddenapis doesn't have access to vectors and I had to turn it off,
  3. jmh is GPL. It's a dev tool, I don't think it's a problem. I left license checks out of it for the time being.

@dweiss dweiss self-assigned this Oct 12, 2023
@dweiss dweiss linked an issue Oct 12, 2023 that may be closed by this pull request
@rmuir
Copy link
Member

rmuir commented Oct 12, 2023

@dweiss thank you for this! I tried it out and it works great. Glad to see the cosineDistanceVectorUtil() working in this example which is exactly what I want to do.

@dweiss
Copy link
Contributor Author

dweiss commented Oct 12, 2023

Let me review the minor remaining bits - I had to leave the computer before the tests completed.

@benwtrent
Copy link
Member

@dweiss this is awesome!!! Thank you so much!

@benwtrent
Copy link
Member

@dweiss one suggestion I have is adding a README for lucene/benchmark-jmh on how to run the benchmarks and add new ones. Your description on how to use it in this PR seems adequate.

I tested this locally and was able to follow your directions and get the benchmarks to run without issue.

@dweiss
Copy link
Contributor Author

dweiss commented Oct 12, 2023

I enabled forbiddenapis to the extent possible, to make Uwe happier. ;) I like those flame-graphs that Solr has, etc., but these can come later. I'll add a simple gradlew :helpJmh target similar to everything else.

@dweiss
Copy link
Contributor Author

dweiss commented Oct 12, 2023

@benwtrent Can you take a look? If there's any wording you think would work better, please do change it. Explaining how JMH works is perhaps beyond the scope of the readme file... ;)

-h displays verbose help for all options
-l list available benchmarks
-lp list benchmarks that pass the filter and their parameters
regexp execute all benchmark containing regexp
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
regexp execute all benchmark containing regexp
regexp execute all benchmark containing regexp
Here is an example running a single benchmark:
java --module-path lucene\benchmark-jmh\build\benchmarks --module org.apache.lucene.benchmark.jmh org.apache.lucene.benchmark.jmh.BinaryCosineBenchmark.cosineDistanceNew
Or running all of BinaryCosineBenchmark
java --module-path lucene\benchmark-jmh\build\benchmarks --module org.apache.lucene.benchmark.jmh org.apache.lucene.benchmark.jmh.BinaryCosineBenchmark

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, apologies - I thought you added that change to the branch, not as github's suggested change. I added this manually.

@benwtrent
Copy link
Member

Looks good @dweiss I added a line with an example for running a single benchmark or suite of benchmarks.

@dweiss dweiss merged commit 603cd41 into apache:main Oct 12, 2023
@dweiss dweiss added this to the 10.0.0 milestone Oct 12, 2023
@dweiss dweiss deleted the 12641-jmh-benchmarks branch October 12, 2023 18:29
asfgit pushed a commit that referenced this pull request Oct 12, 2023
rmuir pushed a commit to rmuir/lucene that referenced this pull request Nov 13, 2023
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.

ability to run JMH benchmarks from gradle

3 participants