Skip to content

Commit

Permalink
Merge pull request #3589 from daviwil/add-max-memory-size-param
Browse files Browse the repository at this point in the history
Add --max-memory-size parameter for increasing Node.js heap size
  • Loading branch information
daviwil authored Sep 15, 2020
2 parents 4dd458e + 67a7f76 commit fd7232c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 15 additions & 5 deletions autorest/entrypoints/app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/usr/bin/env node
// load modules from static linker filesystem.

global.isDebuggerEnabled =
!!require('inspector').url()
|| global.v8debug
|| /--debug|--inspect/.test(process.execArgv.join(' '));

const maxMemorySizeArg = process.argv.join(' ').match(/--max-memory-size=(\w+)/);
const maxMemorySize = maxMemorySizeArg && parseInt(maxMemorySizeArg[1]);
if (isNaN(maxMemorySize)) {
console.error(`\nWarning: --max-memory-size parameter '${maxMemorySizeArg[1]}' is not an integer, ignoring it.\n`);
}

// if the process was started with a low heap size (and we're not debugging!) then respawn with a bigger heap size.
if ((require('v8').getHeapStatistics()).heap_size_limit < 8000000000 && !(require('inspector').url() || global.v8debug || /--debug|--inspect/.test(process.execArgv.join(' ')))) {
process.env['NODE_OPTIONS'] = `${process.env['NODE_OPTIONS'] || ''} --max-old-space-size=8192 --no-warnings`;
if (maxMemorySize && !isDebuggerEnabled && (require('v8').getHeapStatistics()).heap_size_limit < (maxMemorySize * 1024000)) {
process.env['NODE_OPTIONS'] = `${process.env['NODE_OPTIONS'] || ''} --max-old-space-size=${maxMemorySize} --no-warnings`;
const argv = process.argv.indexOf('--break') === -1 ? process.argv.slice(1) : ['--inspect-brk', ...process.argv.slice(1).filter(each => each !== '--break')];
require('child_process').spawn(process.execPath, argv, { argv0: 'node', stdio: 'inherit' }).on('close', code => { process.exit(code); });
} else {
global.isDebuggerEnabled = !!require('inspector').url();

// load modules from static linker filesystem.
if (isDebuggerEnabled) {
try {
// try to let source maps resolve
Expand Down
3 changes: 3 additions & 0 deletions core/resources/help-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ help-content: # type: Help as defined in autorest-core/help.ts
- key: github-auth-token
type: string
description: OAuth token to use when pointing AutoRest at files living in a private GitHub repository
- key: max-memory-size
type: string
description: Increases the maximum memory size in MB used by Node.js when running AutoRest (translates to the Node.js parameter --max-old-space-size)
_autorest-core-1:
categoryFriendlyName: Core Functionality
description: "> While AutoRest can be extended arbitrarily by 3rd parties (say, with a custom generator),\n> we officially support and maintain the following functionality.\n> More specific help is shown when combining the following switches with `--help` ."
Expand Down

0 comments on commit fd7232c

Please sign in to comment.