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

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9424a81
feat(models): adds benchmark model generator
Jan 31, 2024
b079930
feat(models): move benchmark model generator code
Feb 1, 2024
cf88979
feat(models): minor tweaks
Feb 1, 2024
a7f13db
test(models): adds unit tests
Feb 1, 2024
b61aa59
feat(models): have Blob imported for Node.js v16 compitability
Feb 1, 2024
40c2bc3
fix(models): adds buffer dependency needed for Node.js v16
Feb 1, 2024
fd46196
docs(models generation): adds readme
Feb 1, 2024
1c9b50b
fix(models): polyfill buffer
Feb 1, 2024
33a58e7
refactor(models): more generic generated model namespace
Feb 1, 2024
c39e8de
fix(models): changed model generated class to public by JSDoc
Feb 1, 2024
ecdbf8b
test(models): amend generated models' stats
Feb 1, 2024
2dabc92
fix(models): remove external dependency for name generation
Feb 1, 2024
d01408f
feat(models): adds a heap size check
Feb 1, 2024
99f0c0f
fix(models): optimised model generation
Feb 1, 2024
60199ab
fix(models): added type defs
Feb 1, 2024
7a0ca0b
fix(deps): adds v8 polyfill
Feb 1, 2024
204d0ed
feat(deps): trying to polyfill v8
Feb 1, 2024
f5b02eb
feat(models): heap size performance optimization
Feb 1, 2024
e013197
fix(models): assign class method accessibility
Feb 1, 2024
9b8838d
fix(models): generated model size is compared against total_available…
Feb 1, 2024
7036044
refactor(models): improve error wording
Feb 1, 2024
3edb8e2
fix(deps): adds node polyfill
Feb 1, 2024
02e2088
fix(deps): renamed v8 addressed without node:
Feb 1, 2024
2ea743f
fix(models): limit generated model to a 100 MiB
Feb 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,83 @@ Model converters and codegen for [Concerto](https://github.com/accordproject/con
npm install @accordproject/concerto-codegen --save
```

## Use

### 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:

```js
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`):

```js
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`):

```js
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:

```js
{
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.

## License <a name="license"></a>
Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.

4 changes: 3 additions & 1 deletion lib/codegen/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const JSONSchemaToConcertoVisitor = require(
const OpenApiToConcertoVisitor = require('./fromOpenApi/cto/openApiVisitor');
const RustVisitor = require('./fromcto/rust/rustvisitor');
const VocabularyVisitor = require('./fromcto/vocabulary/vocabularyvisitor');
const BenchmarkModelGenerator = require('../common/benchmarkModelGenerator');

module.exports = {
AbstractPlugin,
Expand All @@ -57,6 +58,7 @@ module.exports = {
OpenApiToConcertoVisitor,
RustVisitor,
VocabularyVisitor,
BenchmarkModelGenerator,
formats: {
golang: GoLangVisitor,
jsonschema: JSONSchemaVisitor,
Expand All @@ -73,6 +75,6 @@ module.exports = {
openapi: OpenApiVisitor,
avro: AvroVisitor,
rust: RustVisitor,
vocabulary: VocabularyVisitor
vocabulary: VocabularyVisitor,
}
};
Loading
Loading