-
Notifications
You must be signed in to change notification settings - Fork 246
Add benchmarks #1145
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
Merged
Add benchmarks #1145
Changes from 57 commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
08d8583
chore: add simple benchmarks
watson 1492dc6
ci(jenkins): enable benchmark stage and added some references in the …
v1v 1505f2e
ci(jenkins): use a docker based agent
v1v 7e53d8b
ci(jenkins): use a docker container for testing purposes
v1v d757ab7
Revert "ci(jenkins): use a docker container for testing purposes"
v1v ce2e58c
Revert "ci(jenkins): use a docker based agent"
v1v 88752ee
ci(jenkins): nvm is already provided in the bare metal server: https:…
v1v 0a04001
ci(jenkins): nvm is not provided by default, let's install it within …
v1v 75210a5
ci(jenkins): this debug command is not required
v1v d315458
ci(jenkins): add verbose output to track what's going on in the barem…
v1v eb06cbf
chore: rename npm scripts for running benchmarks
watson abe1237
chore(benchmark): calculate deltas
watson 9d3befa
chore: rename benchmark files to better names
watson 1207997
fix: don't measure metrics during benchmark
watson 51faf6b
chore: add a few other benchmarks
watson 9ae7564
refactor: compare with and without the agent
watson 5ec53ae
chore: remove unused packages
watson 8074319
fix: ensure git rev+branch is recorded
watson 7a6555c
fix: don't try to fetch central config
watson b6034a9
refactor: be more explicit about agent defaults
watson 81d7c8b
chore: code cleanup
watson 4b5295d
feat: add debug feature, 'DEBUG=1 npm run bench'
watson 739b54c
chore: almost ready to upload
watson ff18477
ci(jenkins): as review commented
v1v fe0156b
ci(jenkins): use -n to run benchmarks
watson 315bdec
ci(jenkins): use args
v1v d231d1f
Merge branch 'benchmark' of https://github.com/watson/apm-agent-nodej…
v1v 461244c
ci(jenkins): simplify out file
v1v 6beec6f
ci: write benchmark in ndjson format
watson 48f0be2
ci(benchmark): fix linting
watson 415afd6
ci(jenkins): requires relative path
v1v 455110d
Merge branch 'benchmark' of https://github.com/watson/apm-agent-nodej…
v1v 4abfa7c
Merge branch 'benchmark' of https://github.com/watson/apm-agent-nodej…
v1v 5f50b44
Merge branch 'benchmark' of https://github.com/watson/apm-agent-nodej…
v1v bfe0017
ci(jenkins): preserve-env with sudo
v1v 80b195a
ci(jenkins): remove with sudo
v1v 2b8460f
Revert "ci(jenkins): remove with sudo"
v1v 51dde2e
chore: for debugging purposes
v1v 30356f1
ci(jenkins): sudo env context
v1v bc73826
chore: for debugging purposes
v1v 629a728
ci(jenkins): ensure concurrent builds
v1v decdc93
chore: if sudo run
v1v e0c1bb1
ci(jenkins): delete folders
v1v f3312c8
chore: delete later on
v1v 05f28e5
ci(benchmark): clean up require order
watson 41e655e
ci(benchmark): improve benchmark accuracy
watson c42bc9d
ci(benchmark): detailed logging of results
watson 419e388
ci(benchmark): fix linting
watson 13ab7a8
ci(benchmark): add missing devDependencies
watson 0ed7bfd
chore: benchmark context for ci
v1v 5afcaf1
ci(jenkins): delete folder
v1v a620bd3
ci(jenkins): node_version variable
v1v 9b75bbd
chore: as suggested in the review
v1v 9957434
chore: as suggested in the review
v1v a756c5b
Merge branch 'benchmark' of https://github.com/watson/apm-agent-nodej…
v1v 7f1e265
ci(jenkins): enable node version in jenkins
v1v 910a1b8
chore: remove debug
v1v 56a9ab1
ci(benchmark): seed bulk upload file
watson 8c59958
ci(jenkins): deletedir always
v1v cb53f4b
Merge branch 'benchmark' of https://github.com/watson/apm-agent-nodej…
v1v a8389aa
ci(benchmark): fix bulk API metadata line
watson 81732b6
ci(jenkins): sudo is temperamental
v1v 0acdf79
Merge branch 'benchmark' of https://github.com/watson/apm-agent-nodej…
v1v 3ec6ee3
ci(jenkins): change permissions for sudo
v1v f09af4a
chore: revert debug
v1v 407228f
ci(benchmark): add @timestamp
watson c80ac89
ci(jenkins): expose CI env variables
v1v d6258f4
ci(benchmark): improve collected ci/git/pr info
watson 1b28436
ci(jenkins): reorder the sudo command
v1v 1e5a6b8
ci(jenkins): env variables firstly
v1v 6a4303d
ci(jenkins): export and source
v1v a705eb7
ci(jenkins): quote to avoid space issues
v1v e48c477
ci(benchmark): store pr.id as number
watson 2f34190
ci(benchmark): remove unused require call
watson 256afb6
Merge remote-tracking branch 'upstream/master' into benchmark
v1v 37e6e65
ci(jenkins): disable benchmark from daily run
v1v c3ab6d9
ci(benchmark): ensure CHANGE_TITLE is properly escaped
watson 6415e4e
ci(benchmark): try to fix escaping
watson cebf474
ci(benchmark): clean up old output file
watson 9488715
ci(jenkins): when sudo chmod 777
v1v a8b9cfb
ci(jenkins): trap int term
v1v 606a35b
ci(jenkins): trap int term
v1v 7467ac2
ci(jenkins): term exit traps
v1v a5b76be
ci(jenkins): for fixing the workspace
v1v 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env bash | ||
| set -eo pipefail | ||
|
|
||
| # This particular configuration is required to be installed in the baremetal | ||
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash | ||
| export NVM_DIR="$HOME/.nvm" | ||
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
| command -v nvm | ||
|
|
||
| ## If NODE_VERSION env variable exists then use it otherwise use node as default | ||
| if [ -z "${NODE_VERSION}" ] ; then | ||
| NODE_VERSION="node" | ||
| fi | ||
| nvm install ${NODE_VERSION} | ||
|
|
||
| set +x | ||
| npm config list | ||
| npm install | ||
|
|
||
| node --version | ||
| npm --version |
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,9 @@ | ||
| #!/usr/bin/env bash | ||
| set -ueo pipefail | ||
|
|
||
| SCRIPTPATH=$(dirname "$0") | ||
| source ./${SCRIPTPATH}/prepare-benchmarks-env.sh | ||
|
|
||
| RESULT_FILE=${1:-apm-agent-benchmark-results.json} | ||
|
|
||
| npm run bench:ci ${RESULT_FILE} |
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 |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ test/types/transpile/index.js | |
| build | ||
| coverage | ||
| node_modules | ||
| test/benchmarks/.tmp | ||
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
29 changes: 29 additions & 0 deletions
29
test/benchmarks/001-transaction-and-span-no-stack-trace.js
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 @@ | ||
| 'use strict' | ||
|
|
||
| /* eslint-disable no-unused-vars, no-undef */ | ||
|
|
||
| const bench = require('./utils/bench') | ||
|
|
||
| bench('transaction-and-span-no-stack-trace', { | ||
| agentConf: { | ||
| captureSpanStackTraces: false | ||
| }, | ||
| setup () { | ||
| var agent = this.benchmark.agent | ||
| }, | ||
| fn (deferred) { | ||
| if (agent) agent.startTransaction() | ||
| setImmediate(() => { | ||
| const span = agent && agent.startSpan() | ||
| setImmediate(() => { | ||
| if (agent) { | ||
| span.end() | ||
| agent.endTransaction() | ||
| } | ||
| setImmediate(() => { | ||
| deferred.resolve() | ||
| }) | ||
| }) | ||
| }) | ||
| } | ||
| }) | ||
43 changes: 43 additions & 0 deletions
43
test/benchmarks/002-transaction-and-span-overhead-realistic-size.js
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,43 @@ | ||
| 'use strict' | ||
|
|
||
| /* eslint-disable no-unused-vars, no-undef */ | ||
|
|
||
| const bench = require('./utils/bench') | ||
|
|
||
| bench('transaction-and-span-overhead-realistic-size', { | ||
| agentConf: { | ||
| captureSpanStackTraces: true | ||
| }, | ||
| setup () { | ||
| var agent = this.benchmark.agent | ||
| var callstack = this.benchmark.callstack | ||
|
|
||
| // To avoid randomness, but still generate what appears to be natural random | ||
| // call stacks, number of spans etc, use a pre-defined set of numbers | ||
| var numbers = [2, 5, 10, 1, 2, 21, 2, 5, 6, 9, 1, 11, 9, 8, 12] | ||
| var numbersSpanIndex = 5 | ||
| var numbersStackLevelIndex = 0 | ||
|
|
||
| function addSpan (amount, cb) { | ||
| setImmediate(() => { | ||
| const span = agent && agent.startSpan() | ||
| setImmediate(() => { | ||
| if (agent) span.end() | ||
| if (--amount === 0) cb() | ||
| else addSpan(amount, cb) | ||
| }) | ||
| }) | ||
| } | ||
| }, | ||
| fn (deferred) { | ||
| if (agent) agent.startTransaction() | ||
| const amount = numbers[numbersStackLevelIndex++ % numbers.length] | ||
| callstack(amount, () => { | ||
| const amount = numbers[numbersSpanIndex++ % numbers.length] | ||
| addSpan(amount, () => { | ||
| if (agent) agent.endTransaction() | ||
| deferred.resolve() | ||
| }) | ||
| }) | ||
| } | ||
| }) |
27 changes: 27 additions & 0 deletions
27
test/benchmarks/003-transaction-and-span-with-stack-trace.js
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 @@ | ||
| 'use strict' | ||
|
|
||
| /* eslint-disable no-unused-vars, no-undef */ | ||
|
|
||
| const bench = require('./utils/bench') | ||
|
|
||
| bench('transaction-and-span-with-stack-trace', { | ||
| agentConf: { | ||
| captureSpanStackTraces: false | ||
| }, | ||
| setup () { | ||
| var agent = this.benchmark.agent | ||
| }, | ||
| fn (deferred) { | ||
| if (agent) agent.startTransaction() | ||
| setImmediate(() => { | ||
| const span = agent && agent.startSpan() | ||
| setImmediate(() => { | ||
| if (agent) { | ||
| span.end() | ||
| agent.endTransaction() | ||
| } | ||
| deferred.resolve() | ||
| }) | ||
| }) | ||
| } | ||
| }) |
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,20 @@ | ||
| 'use strict' | ||
|
|
||
| /* eslint-disable no-unused-vars, no-undef */ | ||
|
|
||
| const bench = require('./utils/bench') | ||
|
|
||
| bench('transaction', { | ||
| setup () { | ||
| var agent = this.benchmark.agent | ||
| }, | ||
| fn (deferred) { | ||
| if (agent) agent.startTransaction() | ||
| setImmediate(() => { | ||
| if (agent) agent.endTransaction() | ||
| setImmediate(() => { | ||
| deferred.resolve() | ||
| }) | ||
| }) | ||
| } | ||
| }) |
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,21 @@ | ||
| 'use strict' | ||
|
|
||
| /* eslint-disable no-unused-vars, no-undef */ | ||
|
|
||
| const bench = require('./utils/bench') | ||
|
|
||
| bench('transaction-reading-file', { | ||
| setup () { | ||
| var agent = this.benchmark.agent | ||
| var fs = this.benchmark.fs | ||
| var filename = this.benchmark.testFile | ||
| }, | ||
| fn (deferred) { | ||
| if (agent) agent.startTransaction() | ||
| fs.readFile(filename, err => { | ||
| if (err) throw err | ||
| if (agent) agent.endTransaction() | ||
| deferred.resolve() | ||
| }) | ||
| } | ||
| }) |
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,86 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -exo pipefail | ||
|
|
||
| SCRIPTPATH=$(dirname "$0") | ||
| RESULT_FILE=${1} | ||
|
|
||
| if [ -z "$1" ] | ||
| then | ||
| echo "Usage:" | ||
| echo " run-benchmarks-ci.sh <output-file>" | ||
| echo | ||
| echo "Examples:" | ||
| echo " run-benchmarks-ci.sh out.ndjson - Run benchmark + store result in out.ndjson" | ||
| echo | ||
| exit | ||
| fi | ||
|
|
||
| echo $(pwd) | ||
|
|
||
| function setUp() { | ||
| echo "Setting CPU frequency to base frequency" | ||
|
|
||
| CPU_MODEL=$(lscpu | grep "Model name" | awk '{for(i=3;i<=NF;i++){printf "%s ", $i}; printf "\n"}') | ||
| if [ "${CPU_MODEL}" == "Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz " ] | ||
| then | ||
| # could also use `nproc` | ||
| CORE_INDEX=7 | ||
| BASE_FREQ="3.5GHz" | ||
| elif [ "${CPU_MODEL}" == "Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz " ] | ||
| then | ||
| CORE_INDEX=7 | ||
| BASE_FREQ="3.4GHz" | ||
| elif [ "${CPU_MODEL}" == "Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz " ] | ||
| then | ||
| CORE_INDEX=7 | ||
| BASE_FREQ="3.6GHz" | ||
| elif [ "${CPU_MODEL}" == "Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz " ] | ||
| then | ||
| CORE_INDEX=9 | ||
| BASE_FREQ="2.90GHz" | ||
| else | ||
| >&2 echo "Cannot determine base frequency for CPU model [${CPU_MODEL}]. Please adjust the build script." | ||
| exit 1 | ||
| fi | ||
| MIN_FREQ=$(cpufreq-info -l -c 0 | awk '{print $1}') | ||
| # This is the frequency including Turbo Boost. See also http://ark.intel.com/products/80916/Intel-Xeon-Processor-E3-1246-v3-8M-Cache-3_50-GHz | ||
| MAX_FREQ=$(cpufreq-info -l -c 0 | awk '{print $2}') | ||
|
|
||
| # set all CPUs to the base frequency | ||
| for (( cpu=0; cpu<=${CORE_INDEX}; cpu++ )) | ||
| do | ||
| sudo -n cpufreq-set -c ${cpu} --min ${BASE_FREQ} --max ${BASE_FREQ} | ||
| done | ||
|
|
||
| # Build cgroups to isolate microbenchmarks and JVM threads | ||
| echo "Creating groups for OS and microbenchmarks" | ||
| # Isolate the OS to the first core | ||
| sudo -n cset set --set=/os --cpu=0-1 | ||
| sudo -n cset proc --move --fromset=/ --toset=/os | ||
|
|
||
| # Isolate the microbenchmarks to all cores except the first two (first physical core) | ||
| # On a 4 core CPU with hyper threading, this would be 6 cores (3 physical cores) | ||
| sudo -n cset set --set=/benchmark --cpu=2-${CORE_INDEX} | ||
| } | ||
|
|
||
| function benchmark() { | ||
| sudo -n cset proc --exec /benchmark -- ./${SCRIPTPATH}/run-benchmarks.sh all ${RESULT_FILE} | ||
| } | ||
|
|
||
| function tearDown() { | ||
| echo "Destroying cgroups" | ||
| sudo -n cset set --destroy /os | ||
| sudo -n cset set --destroy /benchmark | ||
|
|
||
| echo "Setting normal frequency range" | ||
| for (( cpu=0; cpu<=${CORE_INDEX}; cpu++ )) | ||
| do | ||
| sudo -n cpufreq-set -c ${cpu} --min ${MIN_FREQ} --max ${MAX_FREQ} | ||
| done | ||
| } | ||
|
|
||
| trap "tearDown" EXIT | ||
|
|
||
| setUp | ||
| benchmark |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this gets into the
fn(...)scope below by benchmark.js generating code from the contents of the input functions and eval'ing that? 🤔Seems a bit confusing and looks like dead code at first glance. Also, I feel like the linter would likely complain about this sort of thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Which is also why I have to use
varinstead ofconstas those are not hoisted in the generated code where it happens to wrap thesetupin a try-catch. To get the linter to behave, I've added aeslint-disablecomment at the top of the file.Check out this example to see how the code compilation works: https://benchmarkjs.com/docs#prototype_setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. 👍