-
Notifications
You must be signed in to change notification settings - Fork 258
ci(NODE-5403): add string deserialization benchmark to ci #593
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9c671f1
test(NODE-5403): add benchmark to ci
W-A-James 943b9d1
ci(NODE-5403): fix .evergreen/config.yml
W-A-James 9b2819a
ci(NODE-5403): update ci config and tests
W-A-James c50fd2e
style(NODE-5403): eslint
W-A-James 7c7770f
ci(NODE-5403): pin benchmark task to node v16.20.1
W-A-James 069f9e5
ci(NODE-5403): fix perf.send report
W-A-James 214a546
Merge branch 'main' into NODE-5403
W-A-James 23ce05c
test(NODE-5403): increase benchmark iter count
W-A-James a603a9a
ci(NODE-5403): update benchmark infrastructure
W-A-James 7c31d04
ci(NODE-5403): update benchmarks
W-A-James 5dea527
style(NODE-5403): add comment
W-A-James 5346e9c
ci(NODE-5403): remove unnecessary config files
W-A-James 7c6c2fb
ci(NODE-5403): suite name fix
W-A-James 12bd7c3
ci(NODE-5403): update evergreen config
W-A-James File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" | ||
|
||
npm run check:bench |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getStringDeserializationSuite } from './suites/string_deserialization'; | ||
import { type PerfSendData } from './util'; | ||
import { writeFile } from 'fs'; | ||
import { cpus, totalmem } from 'os'; | ||
|
||
const hw = cpus(); | ||
const platform = { name: hw[0].model, cores: hw.length, ram: `${totalmem() / 1024 ** 3}GiB` }; | ||
|
||
const results: PerfSendData[][] = []; | ||
|
||
console.log( | ||
[ | ||
`\n- cpu: ${platform.name}`, | ||
`- cores: ${platform.cores}`, | ||
`- os: ${process.platform}`, | ||
`- ram: ${platform.ram}` | ||
].join('\n') | ||
); | ||
|
||
for (const suite of [getStringDeserializationSuite()]) { | ||
suite.run(); | ||
results.push(suite.results); | ||
} | ||
|
||
writeFile('benchmarks.json', JSON.stringify(results.flat()), err => { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
|
||
console.log('Wrote results to benchmarks.json'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Task } from './task'; | ||
import { type PerfSendData } from './util'; | ||
|
||
export class Suite { | ||
name: string; | ||
tasks: Task[]; | ||
results: PerfSendData[]; | ||
constructor(name: string) { | ||
this.name = name; | ||
this.tasks = []; | ||
this.results = []; | ||
} | ||
|
||
task(opts: { | ||
name: string; | ||
data: any; | ||
fn: (data: any) => void; | ||
iterations: number; | ||
resultUnit?: string; | ||
transform?: (x: number) => number; | ||
args?: Record<string, string>; | ||
}) { | ||
this.tasks.push( | ||
new Task( | ||
this, | ||
opts.name, | ||
opts.data, | ||
opts.fn, | ||
opts.iterations, | ||
opts.resultUnit, | ||
opts.transform, | ||
opts.args | ||
) | ||
); | ||
return this; | ||
} | ||
|
||
run() { | ||
console.log(`Running suite: ${this.name}`); | ||
|
||
for (const task of this.tasks) { | ||
task.run(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Suite } from '../suite'; | ||
import * as BSON from '../../../../'; | ||
|
||
export function getStringDeserializationSuite(): Suite { | ||
const DOC: Uint8Array = BSON.serialize({ | ||
nextBatch: Array.from({ length: 1000 }, () => { | ||
return { | ||
_id: new BSON.ObjectId(), | ||
arrayField: Array.from({ length: 20 }, (_, i) => `5e99f3f5d3ab06936d36000${i}`) | ||
}; | ||
}) | ||
}); | ||
const suite = new Suite('string deserialization'); | ||
for (const utf8Validation of [true, false]) { | ||
suite.task({ | ||
name: `stringDeserializationUTF8${utf8Validation ? 'On' : 'Off'}-${ | ||
process.env.WEB === 'true' ? 'web' : 'node' | ||
}`, | ||
data: DOC, | ||
fn: serializedDoc => | ||
BSON.deserialize(serializedDoc, { validation: { utf8: utf8Validation } }), | ||
iterations: 10_000, | ||
resultUnit: 'megabytes_per_second', | ||
transform: (runtimeMS: number) => { | ||
return DOC.byteLength / 1024 ** 2 / (runtimeMS / 1000); | ||
} | ||
}); | ||
} | ||
|
||
return suite; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { type Suite } from './suite'; | ||
import { convertToPerfSendFormat } from './util'; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { performance } from 'perf_hooks'; | ||
|
||
export class Task { | ||
name: string; | ||
parent: Suite; | ||
data: any; | ||
fn: (data: any) => void; | ||
iterations: number; | ||
transform?: (x: number) => number; | ||
resultUnit: string; | ||
args?: Record<string, string>; | ||
|
||
constructor( | ||
parent: Suite, | ||
name: string, | ||
data: any, | ||
fn: (data: any) => void, | ||
iterations: number, | ||
resultUnit?: string, | ||
transform?: (x: number) => number, | ||
args?: Record<string, string> | ||
) { | ||
this.parent = parent; | ||
this.name = name; | ||
this.iterations = iterations; | ||
this.data = data; | ||
this.fn = fn; | ||
this.transform = transform; | ||
this.args = args; | ||
this.resultUnit = resultUnit ? resultUnit : 'ms'; | ||
} | ||
|
||
// TODO: Ensure that each task runs on a separate node process | ||
run() { | ||
console.log(`\t ${this.name} - iters: ${this.iterations}`); | ||
const data = this.data; | ||
const fn = this.fn; | ||
// Warmup | ||
for (let i = 0; i < this.iterations; i++) { | ||
fn(data); | ||
} | ||
const results: number[] = []; | ||
|
||
for (let i = 0; i < this.iterations; i++) { | ||
const start = performance.now(); | ||
fn(data); | ||
const end = performance.now(); | ||
results.push(end - start); // ms | ||
} | ||
this.parent.results.push( | ||
convertToPerfSendFormat( | ||
this.name, | ||
[ | ||
{ | ||
name: this.resultUnit, | ||
results: this.transform ? results.map(this.transform) : results | ||
} | ||
], | ||
this.args | ||
) | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export type PerfSendData = { | ||
info: { | ||
test_name: string; | ||
tags?: string[]; | ||
args?: Record<string, string>; | ||
}; | ||
metrics: { name: string; value: number }[]; | ||
}; | ||
|
||
export function convertToPerfSendFormat( | ||
benchmarkName: string, | ||
metrics: { | ||
name: string; | ||
results: number[]; | ||
}[], | ||
args?: Record<string, string> | ||
): PerfSendData { | ||
return { | ||
info: { | ||
test_name: benchmarkName.replaceAll(' ', '_'), | ||
tags: ['js-bson'], | ||
args: args | ||
}, | ||
metrics: metrics.map(({ name, results }) => ({ | ||
name, | ||
value: results.reduce((acc, x) => acc + x, 0) / results.length | ||
})) | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": false, | ||
"checkJs": false, | ||
"strict": true, | ||
"alwaysStrict": true, | ||
"target": "es2021", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"skipLibCheck": true, | ||
"lib": [ | ||
"es2021" | ||
], | ||
"outDir": "./lib", | ||
"importHelpers": false, | ||
"noEmitHelpers": false, | ||
"noEmitOnError": true, | ||
"emitDeclarationOnly": false, | ||
"sourceMap": true, | ||
"inlineSourceMap": false, | ||
"inlineSources": false, | ||
"types": ["node"] | ||
}, | ||
"include": [ | ||
"./src/**/*.ts" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.