Skip to content

Commit

Permalink
chore: add some memory debugging (aws#24970)
Browse files Browse the repository at this point in the history
The build is running out of memory for unclear reasons. Add some debugging to figure out what's going on.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Apr 6, 2023
1 parent 3be43eb commit 737061d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ done
export PATH=$(npm bin):$PATH
export NODE_OPTIONS="--max-old-space-size=8196 --experimental-worker ${NODE_OPTIONS:-}"

# Temporary log memory for long builds (this may mess with tests that check stderr)
# export NODE_OPTIONS="-r $PWD/scripts/log-memory.js ${NODE_OPTIONS:-}"

if ! [ -x "$(command -v yarn)" ]; then
echo "yarn is not installed. Install it from here- https://yarnpkg.com/en/docs/install."
exit 1
Expand Down
4 changes: 4 additions & 0 deletions buildspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ phases:
# Packing aws-cdk-lib can cause memory errors. Increasing this value
# allows our build to more consistently succeed
- /sbin/sysctl -w vm.max_map_count=2251954

pre_build:
commands:
# Print our ulimits to find out if we might run into a resource limit
- ulimit -a
- /bin/bash ./scripts/cache-load.sh
build:
commands:
- codebuild-breakpoint
- 'if ${BUMP_CANDIDATE:-false}; then /bin/bash ./scripts/bump-candidate.sh; fi'
- /bin/bash ./scripts/align-version.sh
- /bin/bash ./build.sh
Expand Down
15 changes: 15 additions & 0 deletions scripts/log-memory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Script to get Node.js to print its memory usage periodically
//
// Use as follows:
//
// export NODE_OPTIONS="-r $PWD/scripts/log-memory.js ${NODE_OPTIONS:-}"
const { memoryUsage } = require('process');

const MB = 1024 * 1024;

setInterval(() => {
const now = new Date();
const HH = `0${now.getHours()}`.slice(-2);
const MM = `0${now.getMinutes()}`.slice(-2);
console.error(`[${HH}:${MM}] [node:${process.pid}] rss=${(memoryUsage.rss() / MB).toFixed(1)}`);
}, 60000).unref();

0 comments on commit 737061d

Please sign in to comment.