Skip to content

Instantly share code, notes, and snippets.

@devicezero
Last active January 27, 2022 15:32
Show Gist options
  • Save devicezero/eb98c1ea802e2e12ef92bcf420e2cf01 to your computer and use it in GitHub Desktop.
Save devicezero/eb98c1ea802e2e12ef92bcf420e2cf01 to your computer and use it in GitHub Desktop.
ecosystem.config.js example for psh number of cpus
const fs = require("fs");
let numberOfProcesses = 1;
let maxMemory = 64;
// use number of cpus from config.json on grid
if (fs.existsSync("/run/config.json")) {
const pshConfig = require("/run/config.json");
numberOfProcesses = Math.ceil(pshConfig.info.limits.cpu);
maxMemory = pshConfig.info.limits.memory;
}
// untested territory
// use number of cpus from Node.js OS utility on dedicated generation 2
// if (process.env.PLATFORM_MODE === "enterprise") {
// const os = require("os");
// // how much of the cpu/memory consumption depends on what else is running
// numberOfProcesses = os.cpus().length;
// // this is using 1/3 of the max memory of the machine, adjust as necessary
// maxMemory = Math.ceil((os.totalmem() / 1024 / 1000) * 0.33);
// }
module.exports = {
apps: [
{
script: "index.js",
instances: numberOfProcesses,
exec_mode: "cluster",
max_memory_restart: `${maxMemory}M`,
node_args: `--max_old_space_size=${maxMemory}`,
env: {
NODE_ENV: "production",
},
},
],
};
@raupie
Copy link

raupie commented Jan 26, 2022

update comments from # to //

@devicezero
Copy link
Author

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment