Skip to content

change to create a PR #132

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

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1a8f7c9
Add sirun tests
uurien Apr 11, 2025
38ffadf
fix lint
uurien Apr 14, 2025
2b4deae
Scripts to run tests
uurien Apr 23, 2025
1469dd9
Run the CI to see the failures
uurien Apr 24, 2025
fd544d3
Add upstream branch and commit
uurien Apr 24, 2025
cd551d0
set node major version for benchmarks
uurien Apr 24, 2025
a8107c1
Increase timeout
uurien Apr 24, 2025
687a0ed
trying
uurien Apr 24, 2025
c558df6
show errors
uurien Apr 24, 2025
960cd3f
fix lint
uurien Apr 24, 2025
3166ad6
Do not ignore tests fake node_modules
uurien Apr 24, 2025
2b17c40
Make tests longer
uurien Apr 25, 2025
0392748
Write PR comment in different step
uurien Apr 25, 2025
b5c69e7
Update stage
uurien Apr 25, 2025
10ab2c2
Simplify CI, only run in node22
uurien Apr 25, 2025
d600452
Tiny changes
uurien Apr 25, 2025
148a59a
add extraline
uurien Apr 25, 2025
da66b9a
Add empty line
uurien Apr 28, 2025
840908b
Improve initialization test
uurien May 5, 2025
4dd07eb
Improve rewrite tests
uurien May 5, 2025
461ec36
Adjust init timeout
uurien May 6, 2025
e63d0ca
Update runall algorithm and address other PR comments
uurien May 8, 2025
8074a10
Fix lint
uurien May 8, 2025
d9a1159
Add logs
uurien May 8, 2025
2c4bf77
Use different logs logs
uurien May 8, 2025
f46228a
Removing logs
uurien May 9, 2025
75a6c86
Use TOTAL_CPU_CORES for CPU_AFFINITY
uurien May 9, 2025
0b700f9
Cleaning logs
uurien May 9, 2025
d9a7de2
Fix meta.json and reduce iterations
uurien May 9, 2025
0bcedd3
Modify rewrite test to not use server
uurien May 9, 2025
598ac35
Cleaning
uurien May 9, 2025
cb05e58
More cleaning
uurien May 9, 2025
d52d96a
change to create a PR
uurien Apr 24, 2025
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ build
.vscode

wasm

# benchmark results
results.ndjson
*.lock_core
6 changes: 6 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add a new stage called “benchmarks”
stages:
- benchmarks

# … and include a file that specifies benchmarks CI jobs
include: ".gitlab/benchmarks.yml"
33 changes: 33 additions & 0 deletions .gitlab/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
variables:
BASE_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:dd-wasm-js-rewriter

benchmarks:
stage: benchmarks
when: on_success
tags: ["runner:apm-k8s-tweaked-metal"]
image: $BASE_CI_IMAGE
interruptible: true
timeout: 1h
script:
- export ARTIFACTS_DIR="$(pwd)/artifacts" && (mkdir "${ARTIFACTS_DIR}" || :)
- git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/".insteadOf "https://github.com/DataDog/"
- git clone --branch dd-wasm-js-rewriter https://github.com/DataDog/benchmarking-platform platform && cd platform
- ./steps/capture-hardware-software-info.sh
- ./steps/run-benchmarks.sh
- ./steps/analyze-results.sh
- "./steps/upload-results-to-s3.sh || :"
- "./steps/post-pr-comment.sh || :"
artifacts:
name: "artifacts"
when: always
paths:
- artifacts/
expire_in: 3 months
variables:
KUBERNETES_SERVICE_ACCOUNT_OVERWRITE: dd-wasm-js-rewriter
FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY: "true"
UPSTREAM_BRANCH: $CI_COMMIT_REF_NAME # The branch or tag name for which project is built.
UPSTREAM_COMMIT_SHA: $CI_COMMIT_SHA # The commit revision the project is built for.
UPSTREAM_PROJECT_ID: $CI_PROJECT_ID # The ID of the current project. This ID is unique across all projects on the GitLab instance.
UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME # "dd-wasm-js-rewriter"
MAJOR_VERSION: 22
9 changes: 9 additions & 0 deletions benchmark/sirun/get-variants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

'use strict'

const path = require('path')
const metaJson = require(path.join(process.cwd(), 'meta.json'))
const variants = (metaJson.variants && Object.keys(metaJson.variants)) || []

process.stdout.write(variants.join(' '))
172 changes: 172 additions & 0 deletions benchmark/sirun/initialize/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
const configs = [{
csiMethods: [
{ src: 'concat' },
{ src: 'join' },
{ src: 'parse' },
{ src: 'plusOperator', operator: true },
{ src: 'random' },
{ src: 'replace' },
{ src: 'slice' },
{ src: 'substr' },
{ src: 'substring' },
{ src: 'toLowerCase', dst: 'stringCase' },
{ src: 'toUpperCase', dst: 'stringCase' },
{ src: 'tplOperator', operator: true },
{ src: 'trim' },
{ src: 'trimEnd' },
{ src: 'trimStart', dst: 'trim' },
{ src: 'eval', allowedWithoutCallee: true }
],
orchestrion: `version: 1
dc_module: dc-polyfill
instrumentations:
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/runnables/base.js
function_query:
name: invoke
type: method
kind: async
class: RunnableSequence
operator: tracePromise
channel_name: "RunnableSequence_invoke"
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/runnables/base.js
function_query:
name: batch
type: method
kind: async
class: RunnableSequence
operator: tracePromise
channel_name: "RunnableSequence_batch"
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/language_models/chat_models.js
function_query:
name: generate
type: method
kind: async
class: BaseChatModel
operator: tracePromise
channel_name: "BaseChatModel_generate"
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/language_models/llms.js
function_query:
name: generate
type: method
kind: async
operator: tracePromise
channel_name: "BaseLLM_generate"
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/embeddings.js
function_query:
name: constructor
type: method
kind: sync
class: Embeddings
operator: traceSync
channel_name: "Embeddings_constructor"`
}, {
csiMethods: [
{ src: 'concat' },
{ src: 'join' },
{ src: 'parse' },
{ src: 'plusOperator', operator: true },
{ src: 'random' }
],
orchestrion: `version: 1
dc_module: dc-polyfill
instrumentations:
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/runnables/base.js
function_query:
name: invoke
type: method
kind: async
class: RunnableSequence
operator: tracePromise
channel_name: "RunnableSequence_invoke"
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/language_models/chat_models.js
function_query:
name: generate
type: method
kind: async
class: BaseChatModel
operator: tracePromise
channel_name: "BaseChatModel_generate"`
}, {
csiMethods: [
{ src: 'slice' },
{ src: 'substr' },
{ src: 'substring' },
{ src: 'toLowerCase', dst: 'stringCase' },
{ src: 'toUpperCase', dst: 'stringCase' }
],
orchestrion: `version: 1
dc_module: dc-polyfill
instrumentations:
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/language_models/llms.js
function_query:
name: generate
type: method
kind: async
operator: tracePromise
channel_name: "BaseLLM_generate"
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/embeddings.js
function_query:
name: constructor
type: method
kind: sync
class: Embeddings
operator: traceSync
channel_name: "Embeddings_constructor"`
}, {
csiMethods: [
{ src: 'trim' },
{ src: 'trimEnd' },
{ src: 'trimStart', dst: 'trim' },
{ src: 'eval', allowedWithoutCallee: true }
],
orchestrion: `version: 1
dc_module: dc-polyfill
instrumentations:
- module_name: "@langchain/core"
version_range: ">=0.1.0"
file_path: dist/runnables/base.js
function_query:
name: batch
type: method
kind: async
class: RunnableSequence
operator: tracePromise
channel_name: "RunnableSequence_batch"`
}]

let count = 0

const { Rewriter } = require('../../../main')

for (let i = 0; i < 1e4; i++) {
for (const config of configs) {
const instance = new Rewriter({
csiMethods: config.csiMethods,
orchestrion: config.orchestrion
})
count += instance.orchestrionModules ? 1 : 0
}
}

if (count === 0) {
// eslint-disable-next-line no-console
console.log('This cannot happen, but count is used to avoid optimizations')
}
13 changes: 13 additions & 0 deletions benchmark/sirun/initialize/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "initialize",
"cachegrind": false,
"instructions": true,
"iterations": 100,
"timeout": 15,
"variants": {
"main": {
"run": "node ./init.js",
"run_with_affinity": "bash -c \"taskset -c $CPU_AFFINITY node ./init.js\""
}
}
}
1 change: 1 addition & 0 deletions benchmark/sirun/rewrite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
13 changes: 13 additions & 0 deletions benchmark/sirun/rewrite/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "rewrite",
"cachegrind": false,
"instructions": true,
"iterations": 100,
"timeout": 15,
"variants": {
"iast+orchestrion": {
"run": "node rewrite.js",
"run_with_affinity": "bash -c \"taskset -c $CPU_AFFINITY node rewrite.js\""
}
}
}
10 changes: 10 additions & 0 deletions benchmark/sirun/rewrite/node_modules/test/file.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions benchmark/sirun/rewrite/node_modules/test/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions benchmark/sirun/rewrite/orchestrion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 1
dc_module: dc-polyfill
instrumentations:
- module_name: "test"
version_range: ">=0.1.0"
file_path: file.js
function_query:
name: methodToBeRewritten
type: method
kind: async
operator: tracePromise
channel_name: "methodToBeRewritten_invoke"
30 changes: 30 additions & 0 deletions benchmark/sirun/rewrite/rewrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

const fs = require('fs')
const path = require('path')

const { Rewriter } = require('../../../main')

const csiMethods = [
{ src: 'concat' },
{ src: 'join' },
{ src: 'parse' },
{ src: 'plusOperator', operator: true }
]
const filename = path.join(__dirname, 'node_modules', 'test', 'file.js')
const code = fs.readFileSync(filename, 'utf8').toString()
const orchestrion = fs.readFileSync(path.join(__dirname, 'orchestrion.yml'), 'utf8').toString()

const rewriter = new Rewriter({ csiMethods, orchestrion })

let count = 0

for (let i = 0; i < 1e4; i++) {
const rewritten = rewriter.rewrite(code, filename, ['iast', 'orchestrion'])
count += rewritten.content ? 1 : 0
}

if (count === 0) {
// eslint-disable-next-line no-console
console.log('This cannot happen, but count is used to avoid optimizations')
}
9 changes: 9 additions & 0 deletions benchmark/sirun/run-one-variant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

'use strict'

const { exec, stdio } = require('./run-util')

const env = Object.assign({}, process.env)

exec('sirun', ['meta-temp.json'], { env, stdio })
42 changes: 42 additions & 0 deletions benchmark/sirun/run-util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict'

const childProcess = require('child_process')
const readline = require('readline')

function exec (...args) {
return new Promise((resolve, reject) => {
const proc = childProcess.spawn(...args)
streamAddVersion(proc.stdout)
proc.on('error', (e) => {
reject(e)
})
proc.on('exit', (code) => {
if (code === 0) {
resolve()
} else {
reject(new Error('Process exited with non-zero code. - ' + code))
}
})
})
}

function streamAddVersion (input) {
input.rl = readline.createInterface({ input })
input.rl.on('line', function (line) {
try {
const json = JSON.parse(line.toString())
json.nodeVersion = process.versions.node
// eslint-disable-next-line no-console
console.log(JSON.stringify(json))
} catch (e) {
// eslint-disable-next-line no-console
console.log(line)
}
})
}

module.exports = {
exec,
stdio: ['inherit', 'pipe', 'inherit'],
streamAddVersion
}
Loading
Loading