diff --git a/backend/package-lock.json b/backend/package-lock.json index bbb60757..18fe6bff 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -8,6 +8,7 @@ "name": "@zeppelin/backend", "version": "0.0.1", "dependencies": { + "@clinic/heap-profiler": "^4.1.0", "@silvia-odwyer/photon-node": "^0.3.1", "bufferutil": "^4.0.3", "clinic": "^12.1.0", diff --git a/backend/package.json b/backend/package.json index 5261c052..9c82e322 100644 --- a/backend/package.json +++ b/backend/package.json @@ -8,14 +8,12 @@ "watch-yaml-parse-test": "cross-env NODE_ENV=development tsc-watch --onSuccess \"node dist/backend/src/yamlParseTest.js\"", "build": "rimraf dist && tsc", "start-bot-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9229 dist/backend/src/index.js", - "start-bot-dev-debug": "NODE_ENV=development clinic heapprofiler --collect-only --dest .clinic-bot -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9229 dist/backend/src/index.js", "start-bot-prod": "cross-env NODE_ENV=production node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/index.js", - "start-bot-prod-debug": "NODE_ENV=production clinic heapprofiler --collect-only --dest .clinic-bot -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/index.js", + "start-bot-prod-debug": "cross-env NODE_ENV=production node start-bot-prod-debug.js", "watch-bot": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-bot-dev\"", "start-api-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9239 dist/backend/src/api/index.js", - "start-api-dev-debug": "NODE_ENV=development clinic heapprofiler --collect-only --dest .clinic-api -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9239 dist/backend/src/api/index.js", "start-api-prod": "cross-env NODE_ENV=production node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/api/index.js", - "start-api-prod-debug": "NODE_ENV=production clinic heapprofiler --collect-only --dest .clinic-api -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/api/index.js", + "start-api-prod-debug": "cross-env NODE_ENV=production node start-api-prod-debug.js", "watch-api": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-api-dev\"", "typeorm": "node -r ./register-tsconfig-paths.js ./node_modules/typeorm/cli.js", "migrate-prod": "cross-env NODE_ENV=production npm run typeorm -- migration:run", @@ -27,6 +25,7 @@ "test-watch": "tsc-watch --onSuccess \"npx ava\"" }, "dependencies": { + "@clinic/heap-profiler": "^4.1.0", "@silvia-odwyer/photon-node": "^0.3.1", "bufferutil": "^4.0.3", "clinic": "^12.1.0", diff --git a/backend/start-api-prod-debug.js b/backend/start-api-prod-debug.js new file mode 100644 index 00000000..32089891 --- /dev/null +++ b/backend/start-api-prod-debug.js @@ -0,0 +1,22 @@ +const ClinicHeapProfiler = require('@clinic/heap-profiler'); + +const heapProfiler = new ClinicHeapProfiler({ + name: `api-${Date.now()}`, + collectOnFailure: true, +}); + +console.log("Starting API with heap collection"); +heapProfiler.collect([ + "node", + "-r", + "./register-tsconfig-paths.js", + "--unhandled-rejections=strict", + "--enable-source-maps", + "--stack-trace-limit=30", + "dist/backend/src/api/index.js" +], function (err, filepath) { + if (err) { + throw err; + } + console.log(`Saved collected data in ${filepath}`); +}); diff --git a/backend/start-bot-prod-debug.js b/backend/start-bot-prod-debug.js new file mode 100644 index 00000000..08f6ab60 --- /dev/null +++ b/backend/start-bot-prod-debug.js @@ -0,0 +1,22 @@ +const ClinicHeapProfiler = require('@clinic/heap-profiler'); + +const heapProfiler = new ClinicHeapProfiler({ + name: `bot-${Date.now()}`, + collectOnFailure: true, +}); + +console.log("Starting bot with heap collection"); +heapProfiler.collect([ + "node", + "-r", + "./register-tsconfig-paths.js", + "--unhandled-rejections=strict", + "--enable-source-maps", + "--stack-trace-limit=30", + "dist/backend/src/index.js" +], function (err, filepath) { + if (err) { + throw err; + } + console.log(`Saved collected data in ${filepath}`); +}); diff --git a/docker/production/start-api.sh b/docker/production/start-api.sh index b92ee6b7..f1bbc21b 100755 --- a/docker/production/start-api.sh +++ b/docker/production/start-api.sh @@ -11,7 +11,7 @@ while ping -c1 prepare_backend &>/dev/null; do sleep 1; done; cd /zeppelin/backend if [ -n "$DEBUG" ]; then echo "Starting API in debug mode" - exec env NO_INSIGHT=true npm run start-api-prod-debug + exec npm run start-api-prod-debug else echo "Starting API" exec npm run start-api-prod diff --git a/docker/production/start-bot.sh b/docker/production/start-bot.sh index f8b8bacc..74fcf336 100644 --- a/docker/production/start-bot.sh +++ b/docker/production/start-bot.sh @@ -11,7 +11,7 @@ while ping -c1 prepare_backend &>/dev/null; do sleep 1; done; cd /zeppelin/backend if [ -n "$DEBUG" ]; then echo "Starting bot in debug mode" - exec env NO_INSIGHT=true npm run start-bot-prod-debug + exec npm run start-bot-prod-debug else echo "Starting bot" exec npm run start-bot-prod