Excess Memory consumption in ec2 instance

0

I have deployed docker containers of my application on ec2. When I'm checking the memory usage of the ec2, it's increasing periodically overtime. I've attached extra storage capacity by adding volume to the ec2, but still the memory usage keeps increasing. How should I fix this issue?

  • You mentioned, you added storage capacity and expecting memory issue to be fixed?

asked 9 months ago704 views
1 Answer
1
Accepted Answer

Adding a new EBS volume won't give you more memory.

You can use that new EBS volume as a swap volume, which isn't a replacement for more RAM but can help if the amount of memory is a reource bottleneck. You don't mention which OS your EC2 is running, but the instructions for how to do this on Red Hat/CentOS/Fedora are at https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/managing_storage_devices/getting-started-with-swap_managing-storage-devices (if it's another flavour of Linux then a Google search will turn up something for you).

This is only addressing a symptom, not the cause of your problem. Indeed, there may not even be a problem - what instance type are you using, and what workloads are you running? You mention you're running containers (plural), what is the projected memory usage of these?

Your mention of running containers and memory usage increasing over time reminds me of this question recently https://repost.aws/en/questions/QULkwTBPOTQn-Q6cTmltB3nA/can-t-connect-to-my-ec2-instance-with-ssh The solution may be either uplifting the instance type, or if you want to stay on the current instance type then (while not being a good solution) regularly stopping and starting your application stack so that memory usage doesn't get to a point where its level of consumption causes concern.

profile picture
EXPERT
Steve_M
answered 9 months ago
  • My ec2 is running on ubuntu, the instance type is t2.micro. I'm using two docker containers for my app both are node js applications which are connected to mongoDB atlas cluster. Mostly the app involves mongoDB write/read/get/delete operations. Initially the available size on /dev/root was 8 Gb then it was completely used, then I had to increase the memory to 15 gb for further deployments, still the used rate is increasing continuously. Filesystem Size Used Avail Use% Mounted on /dev/root 15G 6.4G 8.0G 45% / /dev/root 15G 8.1G 6.4G 56% / /dev/root 15G 9.6G 4.8G 67% / In just 2 days, the used has increased from 6.4 gb to 9.6 gb. I'm not sure what is causing this issue? Is it the instance type or the node js applications or something else?

  • That's not memory that's being consumed, that's diskspace on the root filesystem.

    As it looks like everything is on the one single filesystem it's not clear where to start looking.

    Two places I would start looking at /var/log and /var/lib/docker (the latter is a best guess at where your Docker containers live, you will know better than me if this is right). In each of these run (as root) du -sm * to see the usage of each subdirectory in MB. Then cd into the one that's using the most and run the same command again, and keep drilling down until you identify the culprit.

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