Attempt a GC before taking a snapshot

This commit is contained in:
Koen
2024-01-17 20:44:27 +00:00
parent 1db541f4a0
commit c64118a678
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -68,4 +68,4 @@ EXPOSE 3000
ENV PORT 3000
ENV NEXT_TELEMETRY_DISABLED 1
CMD ["pm2-runtime", "node", "--", "server.js"]
CMD ["pm2-runtime", "node", "--", "server.js", "--", "--expose-gc"]
+3
View File
@@ -5,6 +5,9 @@ import { createReadStream } from 'node:fs';
export default JobEndpoint(async function getHeapDump(req: NextApiRequest, res: NextApiResponse) {
const localPath = `/tmp/heapdump-${Date.now()}.heapsnapshot`;
if (global.gc) {
global.gc();
}
writeHeapSnapshot(localPath);
const readStream = createReadStream(localPath);