Amazon EC2 – How to Choose the Best EC2 Instance for Your System

amazon ec2amazon-web-services

I have hosted an e-commerce site in AWS-EC2 in a t3a.medium instance type. Now that the traffic is increasing CPU utilization is very high and site stops working time and again. Looking into htop, mysql is utilizing maximum CPU.

As in the current instance, vcpu is only 2 so I want to change the instance type. But the problem is how do I know which would best fit my system?

Best Answer

  1. It's easy to change the instance types up, down, or sideways. Don't try to guess which one will work the best for you - instead test it out. If you've got t3a.medium now try upgrading to t3a.large. Or to m5.large - it may be cheaper if you're maxing out the t3a.large and constantly running out of CPU credits (check the monitoring tab in the instance details).

    If your app is memory-hungry look at r5.* instances, if it's cpu-heavy look at c5.* instances. They tend to be cheaper than the general purpose for some workloads.

  2. Best practice is to decouple your database from your app/web frontend, don't host them on the same instance. Move the database to AWS RDS service - it will manage it for you, including backups, upgrades, fail over, etc.

  3. Once your app is decoupled from the database look at Auto-Scaling - instead of upgrading to a larger and larger instance as your traffic grows you can scale horizontally by adding more and more smaller instances, all configured the same. That allows you to run with fewer instances in quiet times (night, weekends) and add more of the same in busy times. That way your per-hour bill will fluctuate with the traffic load.

The bottom line is that there is no "best EC2 instance" - it all depends on your actual usage.

The good thing is that there is no long-term commitment in AWS, simply test things out and evolve the architecture as needed.

Hope that helps :)

Related Topic