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(models): adds benchmark model generator #89

Conversation

stefanblaginov
Copy link
Contributor

@stefanblaginov stefanblaginov commented Jan 31, 2024

Changes

Adds a Concerto benchmark model generator. This API allows you to generate models of varying sizes which can be used to test the performance of your Concerto-handling code.

Generate a model up to a specified number of declarations and properties

You can generate a model up to a specified number of declarations and properties using:

const benchmarkModelGenerator = new BenchmarkModelGenerator();
const generated = benchmarkModelGenerator.generateConcertoModels({
    nDeclarations: 5, // Number of declarations in the model
    nProperties: 5, // Number of properties per declaration
});

Generate a model up to a specified size in bytes

You can generate a model up to a specified size in bytes, however you would need to specify how that model should grow.

Grow model by number of declarations

If you'd like to grow it by number of declarations, you will need to specify the number of properties that you wish the model to have (defaults to 1):

const benchmarkModelGenerator = new BenchmarkModelGenerator();
const generated = benchmarkModelGenerator.generateConcertoModels({
    generateUpToSize: 10000, // Target upper limit of growth in bytes
    growBy: 'declarations', // Element type by which the model should grow
    nProperties: 5, // Number of properties per declaration
});
Grow model by number of properties

If you'd like to grow it by number of properties, you will need to specify the number of declarations that you wish the model to have (defaults to 1):

const benchmarkModelGenerator = new BenchmarkModelGenerator();
const generated = benchmarkModelGenerator.generateConcertoModels({
    generateUpToSize: 10000, // Target upper limit of growth in bytes
    growBy: 'properties', // Element type by which the model should grow
    nProperties: 5, // Number of declarations in the model
});

The expected response will include an array of generated models (currently containing only a single model) and a metadata object with information about the generated model e.g:

{
  models: [
    {
      '$class': '[email protected]',
      decorators: [],
      namespace: '[email protected]',
      imports: [],
      declarations: [
        ...
      ]
    }
  ],
  metadata: {
    requestedModelSizeInBytes: 10000,
    humanReadableRequestedModelSize: '9.77 KiB',
    generatedModelSizeInBytes: 9952,
    humanReadableGeneratedModelSize: '9.72 KiB',
    declarationsN: 5,
    propertiesNInSmallestDeclaration: 15,
    propertiesNInLargestDeclaration: 16
  }
}

As you can see from the above example model, the generator will try its best to reach the upper generateUpToSize reqested size, but may fall short by a few bytes.

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
@stefanblaginov stefanblaginov force-pushed the stefanblaginov/benchmark-model-generator branch from c533f06 to 9424a81 Compare January 31, 2024 23:16
Stefan Blaginov added 5 commits February 1, 2024 11:05
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
@coveralls
Copy link

coveralls commented Feb 1, 2024

Coverage Status

coverage: 98.736%. first build
when pulling 2ea743f on stefanblaginov:stefanblaginov/benchmark-model-generator
into 16d9d5a on accordproject:main.

Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
@stefanblaginov stefanblaginov force-pushed the stefanblaginov/benchmark-model-generator branch from 5864ec9 to fd46196 Compare February 1, 2024 12:59
@stefanblaginov stefanblaginov self-assigned this Feb 1, 2024
lib/common/benchmarkModelGenerator.js Outdated Show resolved Hide resolved
lib/common/benchmarkModelGenerator.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
lib/common/benchmarkModelGenerator.js Outdated Show resolved Hide resolved
Stefan Blaginov added 4 commits February 1, 2024 13:39
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Stefan Blaginov added 3 commits February 1, 2024 14:33
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
@stefanblaginov stefanblaginov force-pushed the stefanblaginov/benchmark-model-generator branch from 80bdc3e to 60199ab Compare February 1, 2024 14:54
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
nDeclarations = 1,
nProperties = 1,
}) {
if (generateUpToSize > v8.getHeapStatistics().total_heap_size) {
Copy link
Member

Choose a reason for hiding this comment

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

total_available_size would be a tighter fit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed ✅

Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
@stefanblaginov
Copy link
Contributor Author

stefanblaginov commented Feb 1, 2024

@mttrbrts can you please advise me on the best way to polyfill v8. I'm getting the following error in the pipeline:

[webpack-cli] Failed to load '/home/runner/work/concerto-codegen/concerto-codegen/webpack.config.js' config
[webpack-cli] Error: Cannot find module 'node:v8/'

This seems to be an option: https://www.npmjs.com/package/node-polyfill-webpack-plugin, however it's an extra dependency.

Stefan Blaginov added 3 commits February 1, 2024 15:09
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
…_size

Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
@jamieshorten
Copy link
Contributor

@mttrbrts can you please advise me on the best way to polyfill v8. I'm getting the following error in the pipeline:

[webpack-cli] Failed to load '/home/runner/work/concerto-codegen/concerto-codegen/webpack.config.js' config
[webpack-cli] Error: Cannot find module 'node:v8/'

This seems to be an option: https://www.npmjs.com/package/node-polyfill-webpack-plugin, however it's an extra dependency.

node-polyfill-webpack-plugin is probably what you want. It basically adds the Node pollyfills that were in Webpack 4 and earlier to Webpack 5+.

Stefan Blaginov added 3 commits February 1, 2024 15:40
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
@stefanblaginov
Copy link
Contributor Author

@mttrbrts can you please advise me on the best way to polyfill v8. I'm getting the following error in the pipeline:

[webpack-cli] Failed to load '/home/runner/work/concerto-codegen/concerto-codegen/webpack.config.js' config
[webpack-cli] Error: Cannot find module 'node:v8/'

This seems to be an option: https://www.npmjs.com/package/node-polyfill-webpack-plugin, however it's an extra dependency.

node-polyfill-webpack-plugin is probably what you want. It basically adds the Node pollyfills that were in Webpack 4 and earlier to Webpack 5+.

Unfortunately it doesn't polyfill the v8 engine.

Signed-off-by: Stefan Blaginov <[email protected]>
Signed-off-by: Stefan Blaginov <[email protected]>
@stefanblaginov
Copy link
Contributor Author

@mttrbrts can you please advise me on the best way to polyfill v8. I'm getting the following error in the pipeline:

[webpack-cli] Failed to load '/home/runner/work/concerto-codegen/concerto-codegen/webpack.config.js' config
[webpack-cli] Error: Cannot find module 'node:v8/'

This seems to be an option: https://www.npmjs.com/package/node-polyfill-webpack-plugin, however it's an extra dependency.

node-polyfill-webpack-plugin is probably what you want. It basically adds the Node pollyfills that were in Webpack 4 and earlier to Webpack 5+.

Unfortunately it doesn't polyfill the v8 engine.

Addressed by limiting model size to 100 MiB.

@mttrbrts mttrbrts enabled auto-merge (squash) February 1, 2024 16:34
@mttrbrts mttrbrts merged commit 61e1544 into accordproject:main Feb 1, 2024
11 checks passed
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.

5 participants