- Newest
- Most votes
- Most comments
Also searching for the best solution to create a heap snapshot from AWS Lambda written in NodeJS. Tried to call V8 heap utilities. Statistics works but as soon as I want to get a dump, it hangs:
// THIS WORKS.
console.log("Heap space stats = ", v8.getHeapSpaceStatistics())
console.log("Heap code stats heapdump = ", v8.getHeapCodeStatistics())
console.log("Heap stats = ", v8.getHeapStatistics())
// THIS HANGS.
console.log("Getting heapdump...")
const snapshotStream = v8.getHeapSnapshot()
Any idea why? Is this even possible in the context of AWS Lambda? Any alternative - I'd really like to get memory details, not just stats?
Trying to reproduce with (almost) same code and I got it working. Instead of using getHeapSnapshot, I wrote it to a tmp file before sending to S3. Can you check this repo and tell me what's different in your code ? https://github.com/vdesaintpern/lambda-heap-dump-to-s3-v8
You can also check Lambda PowerTools for Typescript which can probably help you for tracing. https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/
Jeff's questions are good. We may be able to provide more suggestions if you can answer those. In the meantime, one easy way to get basic insight into memory usage in a NodeJS script is to use the process.memoryUsage()
method. This article provides a nice overview with examples.
Relevant content
- asked 2 years ago
- asked 8 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
What is your goal for using a memory profiler? Are you running out of memory in some invocations? Are you trying to optimize memory usage to optimize the cost of Lambda? What details are you trying to capture that are missing from the the Lambda invocation logs that show the total memory used?