Making Swap Memory to deal with the memory shortage problem

Juhan Kim·2024년 6월 3일
0
post-thumbnail

Running an EC2 instance on the AWS Free Tier often leads to RAM shortages, causing the server to crash frequently. This issue can be particularly problematic during project builds, where processes might stop abruptly or the server may experience unexpected downtimes. Here are some strategies to mitigate these issues:

The AWS Free Tier typically provides instances with around 1GB of memory. Initially, there is no swap memory allocated.

You can check EBS volume that you have set. In my case, I set the max volume which is 30GB.

Adding swap space can help alleviate memory pressure by using disk space as additional RAM. However, this is slower than actual RAM.

sudo dd if=/dev/xvda1 of=/swapfile bs=1M count=2048  # Creates a 2GB swap file
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab # Make swap permanent

Tip :

Given that Free Tier instances are highly vulnerable and prone to shutdowns, the best approach is to create images of your development projects and make templates by versions. This way, you can quickly launch a server with the desired version of your project immediately whenever needed.

Making AMI

Making Template

Running Daemon on ec2 After Adding Swap Memory

Confirmed that the swap memory is actually being used.

profile
지식에 대한 열망이 있는 사람

0개의 댓글