Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(benchmark-tools): Update benchmark-tool to support custom measurement benchmarks #21555

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

chentong7
Copy link
Contributor

@chentong7 chentong7 commented Jun 20, 2024

Description

We've run into several scenarios in the past where we want to have benchmark tests which report their own measurements of something (other than the execution time and memory usage that benchmark-tool currently supports), and have those measurements go to Kusto so we can track them through time.

POC: #20772

Sample

  Op Size
spec.js:54
    Insert Nodes
spec.js:54
      Many Transactions
spec.js:54
        ✔ 100 small nodes in 100 transactions @CustomBenchmark (134ms)
spec.js:83
        ✔ 100 medium nodes in 100 transactions @CustomBenchmark (89ms)
spec.js:83
        ✔ 100 large nodes in 100 transactions @CustomBenchmark (78ms)
spec.js:83
      Single Transaction
spec.js:54
        ✔ 100 small nodes in 1 transaction @CustomBenchmark (66ms)
spec.js:83
        ✔ 100 medium nodes in 1 transaction @CustomBenchmark (54ms)
spec.js:83
        ✔ 100 large nodes in 1 transaction @CustomBenchmark (53ms)
spec.js:83
    Remove Nodes
spec.js:54
      Many Transactions
spec.js:54
        ✔ 100 small nodes in 100 transactions (63ms)
spec.js:83
        ✔ 100 medium nodes in 100 transactions (62ms)
spec.js:83
        ✔ 100 large nodes in 100 transactions (62ms)
spec.js:83
      Single Transaction
spec.js:54
        ✔ 100 small nodes in 1 transactions containing 1 removal of 100 nodes
spec.js:76
        ✔ 100 medium nodes in 1 transactions containing 1 removal of 100 nodes
spec.js:76

Unit test

Writing test results relative to package to nyc/junit-report.xml and nyc/junit-report.json
.mocharc.cjs:11

spec.js:54
  `benchmarkCustom` function
spec.js:54
    uses `before` and `after`
spec.js:54
      ✔ test @CustomBenchmark
spec.js:76
      ✔ run BenchmarkCustom
spec.js:76
  2 passing (8ms)

@chentong7 chentong7 requested review from a team as code owners June 20, 2024 18:14
@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree dependencies Pull requests that update a dependency file public api change Changes to a public API base: main PRs targeted against main branch labels Jun 20, 2024
@Josmithr
Copy link
Contributor

Note that this package is versioned and published independently from others in our repo. In order to publish the changes made here, you will want to update the package.json's version, and add notes to the package's CHANGELOG.md file about the changes.

pnpm-lock.yaml Outdated Show resolved Hide resolved
@chentong7 chentong7 changed the title feature(benchmark): Update benchmark-tool to support custom measurement benchmarks feat(benchmark-tools): Update benchmark-tool to support custom measurement benchmarks Jun 20, 2024
@chentong7
Copy link
Contributor Author

Note that this package is versioned and published independently from others in our repo. In order to publish the changes made here, you will want to update the package.json's version, and add notes to the package's CHANGELOG.md file about the changes.

Updated. Thx!

@github-actions github-actions bot removed area: dds: tree dependencies Pull requests that update a dependency file area: dds Issues related to distributed data structures public api change Changes to a public API labels Jun 20, 2024
@github-actions github-actions bot added the public api change Changes to a public API label Jul 16, 2024
tools/benchmark/CHANGELOG.md Outdated Show resolved Hide resolved
tools/benchmark/src/mocha/customOutputRunner.ts Outdated Show resolved Hide resolved
@chentong7 chentong7 requested a review from Josmithr July 16, 2024 20:01
Copy link
Contributor

@CraigMacomber CraigMacomber left a comment

Choose a reason for hiding this comment

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

I left a suggested simplification.

Generally, though this is looking great. It's exciting to see reporter refactoring paying off. So clean :)

tools/benchmark/src/mocha/customOutputRunner.ts Outdated Show resolved Hide resolved
Co-authored-by: Craig Macomber (Microsoft) <42876482+CraigMacomber@users.noreply.github.com>
@chentong7
Copy link
Contributor Author

CI is failing: you should fix the issues it found.

I see new APIs being added, but I don't see any changes to the tests. New APIs should get tests to both show how the new APIs are used (helpful for future developers working on this, customers and reviewers) as well as help ensure the APIs actually work correctly (which also helps reviewers).

Without any tests or docs added to the readme, or an explanation of the new features in the changelog, its a bit hard to find a good spot to start evaluating the design.

Given that, I think I know whats going on in this change, and I don't think its the way to get to where we want to go.

Currently the problem as I understand it is that:

  • We do not offer an API for reporting arbitrary data as benchmark results
  • We can't implement such an API since our reporter is not general enough to support that.

Last time we had this problem when trying to add memory tests, the approach taken was to duplicate a bunch of code, then customize it for that use case.

What I would like to see:

Rather than adding a bunch of new code which is mostly duplicating code we already have two copies of (for runtime benchmarks and memory benchmarks), I think we should instead work toward deduplicating the existing code.

Before the memory stuff was added, we had one reporter, factored into two parts:

  • Reporter: logic for the reporter containing everything that's not test runner specific, making it easy to author reporters for specific test runners
  • MochaReporter: Repoter+Mocha specific bits.

This made it easy for customers using other test runners to create the reporters they needed (ex: to work with jest).

When the memory stuff was added, it added a second reporter. This made running the tests harder (need to configure memory tests with a different reporter) and it didn't split out the test framework independent parts, so supporting other test runners is much less straight forward. Ideally a user of our library could just add a memory or custom test, and not need to author new reporters for their test framework, reconfigure their testing command line to include those reporters etc.

I view that as technical debt we should pay off before we continue work on this package.

What I think we should do in this change is modify our existing Reporter and MochaReporter to be sufficiently general that they can handle other kinds of data, like memory or custom. Infact they should only support arbitrary custom data, since that should be general enough to handle all cases. Then we can delete the memory reporter, and get down to a single reporter instead or going up to three different ones.

Once thats complete, then (in a separate PR) we could add the feature of this custom benchmark API. Some of new API should actually be used in the implementation of the time and memory benchmarks as they should all be able to be written as helpers using the new general purpose custom API.

Then we are left with a single reporter easy to use with multiple test framework and built in support for mocha, a library for making tests which report data to it, and a collection of helper libraries to measuring different things, including time and memory.

That leaves us with a much simpler to use library, with a much more modular implementation that I would expect to be far easier to understand, maintain, test and extend.

I guess that rant amounts to a proposed design doc for this work.

Link the refactoring PR here: #21730

tools/benchmark/README.md Outdated Show resolved Hide resolved
chentong7 and others added 2 commits July 16, 2024 16:37
Co-authored-by: Joshua Smithrud <54606601+Josmithr@users.noreply.github.com>
@chentong7 chentong7 enabled auto-merge (squash) July 16, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base: main PRs targeted against main branch public api change Changes to a public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants