Last active
June 7, 2024 11:14
-
-
Save devicezero/5074169c36020c31019389cc5d2720ed to your computer and use it in GitHub Desktop.
pm2 nuxt js example
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
// production usage at your own risk | |
const fs = require("fs"); | |
let numberOfProcesses = 1; | |
let maxMemory = 128; | |
let maxMemoryPerInstance = 128; | |
if (fs.existsSync("/run/config.json")) { | |
const pshConfig = require("/run/config.json"); | |
// on grid environments, we don't want to round up to not run too many processes | |
if (pshConfig.info.limits.cpu > 1) { | |
numberOfProcesses = Math.floor(pshConfig.info.limits.cpu); | |
} | |
// on DG3 environments we can safely round up | |
if (process.env.PLATFORM_MODE) { | |
numberOfProcesses = Math.ceil(pshConfig.info.limits.cpu); | |
} | |
maxMemory = pshConfig.info.limits.memory; | |
// Distribute the available memory across all instances | |
maxMemoryPerInstance = Math.ceil(maxMemory / numberOfProcesses); | |
} | |
module.exports = { | |
apps: [ | |
{ | |
name: "index", | |
script: "./index.js", | |
// args: `start -c ${process.cwd()}/nuxt.config.js`, | |
cwd: '/app', | |
instances: numberOfProcesses, | |
exec_mode: "cluster", | |
max_memory_restart: `${maxMemoryPerInstance}M`, | |
node_args: `--max_old_space_size=${maxMemoryPerInstance}`, | |
}, | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.platform.app.yaml modifications
pm2 needs a mount
new start command
nuxt.config.js
modificationwe will need this at the root level (telemetry messes with the start command and due to the pm2 setup we need to specify the build + root dir to nuxt)