Profiling memory for a NodeJS Lambda function

2

Is there any tool, solution, framework, service or alike to allow memory profiling for NodeJS based lambda functions? Maybe even running on AWS directly and not on a local development environment? What would be the recommendation for such kind of profiling?

I'm aware that local profiling can be done using Chrome's Inspect / DevTools, but that actually means debugging a "long running process", not a short-lived one like a lambda function.

Additional Context:

We migrated a reporting service from an EC2 instance to a ECS Fargate based docker container using a basic lift & shift approach, but with the catch that we assigned less memory to the ECS Task than the original configuration of the EC2 instance purposely, as usually the instance had quite a lot of unused resources. So, now we are transitioning the "outliers" that fail with OutOfMemoryError into lambdas, but we'd like to improve their code and not just move them to a lambda container.

  • 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?

2 Answers
0

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?

Spi
answered 2 years ago
0

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.

profile pictureAWS
Kris
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions