Run commands/graph with more heap available (#291)

`sourcecred graph` tends to die due to lack of heap during the Git
plugin. Node defaults to ~1.76GB of heap available, which is just not
that much. This commit uses the `--max_old_space_size` argument to
`node` to increase the limit. We use a default value of `8192`, and it's
configurable by the user via a flag.

This command is only available natively in `sourcecred graph`, because
that command turns on other node processes. For commands that run in
their original process, you would need to set the value yourself.
This commit is contained in:
Dandelion Mané 2018-05-16 20:07:40 -07:00 committed by GitHub
parent 64a8514cf8
commit 610a92a683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 5 deletions

View File

@ -4,7 +4,11 @@ import {Command, flags} from "@oclif/command";
import mkdirp from "mkdirp"; import mkdirp from "mkdirp";
import path from "path"; import path from "path";
import {pluginNames, sourcecredDirectoryFlag} from "../common"; import {
pluginNames,
sourcecredDirectoryFlag,
nodeMaxOldSpaceSizeFlag,
} from "../common";
const execDependencyGraph = require("../../tools/execDependencyGraph").default; const execDependencyGraph = require("../../tools/execDependencyGraph").default;
@ -40,6 +44,7 @@ files under SOURCECRED_DIRECTORY/graphs/REPO_OWNER/REPO_NAME.
static flags = { static flags = {
"sourcecred-directory": sourcecredDirectoryFlag(), "sourcecred-directory": sourcecredDirectoryFlag(),
"max-old-space-size": nodeMaxOldSpaceSizeFlag(),
"github-token": flags.string({ "github-token": flags.string({
description: description:
"a GitHub API token, as generated at " + "a GitHub API token, as generated at " +
@ -55,9 +60,10 @@ files under SOURCECRED_DIRECTORY/graphs/REPO_OWNER/REPO_NAME.
flags: { flags: {
"github-token": token, "github-token": token,
"sourcecred-directory": sourcecredDirectory, "sourcecred-directory": sourcecredDirectory,
"max-old-space-size": maxOldSpaceSize,
}, },
} = this.parse(GraphCommand); } = this.parse(GraphCommand);
graph(sourcecredDirectory, repoOwner, repoName, token); graph(sourcecredDirectory, repoOwner, repoName, token, maxOldSpaceSize);
} }
} }
@ -65,7 +71,8 @@ function graph(
sourcecredDirectory: string, sourcecredDirectory: string,
repoOwner: string, repoOwner: string,
repoName: string, repoName: string,
token: string token: string,
maxOldSpaceSize: number
) { ) {
const graphDirectory = path.join( const graphDirectory = path.join(
sourcecredDirectory, sourcecredDirectory,
@ -75,13 +82,21 @@ function graph(
); );
console.log("Storing graphs into: " + graphDirectory); console.log("Storing graphs into: " + graphDirectory);
mkdirp.sync(graphDirectory); mkdirp.sync(graphDirectory);
const tasks = makeTasks(graphDirectory, {repoOwner, repoName, token}); const tasks = makeTasks(graphDirectory, {
repoOwner,
repoName,
token,
maxOldSpaceSize,
});
execDependencyGraph(tasks, {taskPassLabel: "DONE"}).then(({success}) => { execDependencyGraph(tasks, {taskPassLabel: "DONE"}).then(({success}) => {
process.exitCode = success ? 0 : 1; process.exitCode = success ? 0 : 1;
}); });
} }
function makeTasks(graphDirectory, {repoOwner, repoName, token}) { function makeTasks(
graphDirectory,
{repoOwner, repoName, token, maxOldSpaceSize}
) {
const taskId = (id) => `create-${id}`; const taskId = (id) => `create-${id}`;
const graphFilename = (id) => path.join(graphDirectory, `graph-${id}.json`); const graphFilename = (id) => path.join(graphDirectory, `graph-${id}.json`);
const into = "./src/cli/into.sh"; const into = "./src/cli/into.sh";
@ -92,6 +107,7 @@ function makeTasks(graphDirectory, {repoOwner, repoName, token}) {
into, into,
graphFilename(id), graphFilename(id),
"node", "node",
`--max_old_space_size=${maxOldSpaceSize}`,
"./bin/sourcecred.js", "./bin/sourcecred.js",
"plugin-graph", "plugin-graph",
"--plugin", "--plugin",
@ -109,6 +125,7 @@ function makeTasks(graphDirectory, {repoOwner, repoName, token}) {
into, into,
path.join(graphDirectory, "graph.json"), path.join(graphDirectory, "graph.json"),
"node", "node",
`--max_old_space_size=${maxOldSpaceSize}`,
"./bin/sourcecred.js", "./bin/sourcecred.js",
"combine", "combine",
...pluginNames().map((id) => graphFilename(id)), ...pluginNames().map((id) => graphFilename(id)),

View File

@ -21,3 +21,11 @@ export function sourcecredDirectoryFlag() {
default: () => defaultStorageDirectory(), default: () => defaultStorageDirectory(),
}); });
} }
export function nodeMaxOldSpaceSizeFlag() {
return flags.integer({
description: "--max_old_space_size flag to node; increases available heap",
default: 8192,
env: "SOURCECRED_NODE_MAX_OLD_SPACE",
});
}