High Memory Usage

Hello, So I’m running a NodeJS app that doesn’t use much ram But in the dashboard the avg memory usage is always very high (~173 MB/232 MB). and I made sure it’s not from the app itself. I SSH into my app and installed htop and the memory usage is always around ~88mb with 13H uptime. And I do get OOM Issues otherwise I wouldn’t have cared. been using fly.io for more than 2 weeks now and I really like it. this is the only problem I have.

I took a look at your VM and it looks like node.js is consuming 170MB of RSS memory.

Node.js has various defaults for memory usage which assume it has plenty of available memory to work with.

A 256MB VM is rather small in this respect :slight_smile: This is fine though! We love apps running in 256MB VMs here.

Here are some ideas:


I don’t know which one you looked at, But I meant the one with the name ‘Klein’,
also do you mind telling me how you got this RSS memory? shouldn’t the dashboard read the same as htop and ‘free’? that’s what confuses me.

I already had the idea of enabling swap, but I would have to implement it in my code since I don’t use docker. Thanks for the other Idea. I will set it up and see what happens.

I think the “mem used” metric in our dashboard includes RSS, caches and buffers. Because the query is just total - free:

 avg(fly_instance_memory_mem_total{app="flyio-web"}) - avg(fly_instance_memory_mem_free{app="flyio-web"})

You’re saying this klein app OOMed before? Without setting max-old-space-size to something lower, node.js will happily use way more than it should given the VM’s constraints.

Your node.js process should be able to use as much memory as is available. Looks like 124MB are available to be freed in that VM right now.

I wrote one up for our Node app on Fly, here: https://github.com/serverless-dns/serverless-dns/blob/ecaafa2/src/core/linux/swap.js

swap="auto" in [experimental] would be nice (: RAM limits for deploys - #3 by ignoramous

1 Like

I am having the exact same issue using a 256MB VM. This VM is my scheduler in which i just want to have cron process running my database update scripts. I tried optimizing the script to not store data on memory but it still gets killed by out of memory error. Can i limit the memory size using this NODE_OPTIONS setting? Any help would be appriciated!

Can you share more about your app?

  • What is your Dockerfile / buildpack?
  • Are you running npm start or node ... directly?

I recently learned that npm start will use ~50MB on its own! It makes a big difference in a small VM.

You can troubleshoot memory usage by SSHing into your instance (fly ssh console) and running various commands like ps or top. You might need to install extra packages to debug this.

1 Like

Thats what i thought as well and npm start is not needed in my case since this is a backend only web app does not need to serve www to the world. The reason i ended up with this dockerfile is because i couldnt use prisma to execute db operations without having the same dependencies with my actual project (different webapp). So i copied its dockerfile and added the extra stuff i wanted.

How should i share my dockerfile with you?

I was only interested in the Dockerfile to see if it was doing a npm start or direct node invocation.

You need to go troubleshoot it at runtime via fly ssh console. Check what uses memory.

Maybe you just need more memory too! :slight_smile:

thanks :slight_smile:

I tried removing all the packages of npm and that worked, i managed to run the script. The problem I have now is that since i dont use npm start in my Dockerfile, deployment fails (Failed due to unhealthy allocations - no stable job version to auto revert to.)