Background
AWS EC2 is AWS’s Elastic Compute Service, providing developers with simple and flexible virtual machines. It is one of AWS’s oldest services (the other being S3) and has been evolving for nearly 17 years since its launch in 2006.
Many newcomers to EC2 might have the following similar experiences:
There are so many types of AWS EC2 (hundreds)! Which EC2 instance should I choose to meet my business needs without exceeding my budget?
If the CPU and memory configurations of EC2 are the same, does that mean their performance is also the same?
What kind of EC2 payment model is the most cost-effective?
When EC2 was first launched, there were only two instance types available. Now, there are 781 types, and the vast array of EC2 options can inevitably cause choice paralysis for developers. This article will briefly introduce some tips for choosing EC2 instances to help readers quickly select the appropriate EC2 instance.
EC2 Instance Types and Selection
Although AWS offers hundreds of EC2 instance types, they can be categorized into the following six major categories:
General Purpose: Balanced in compute, memory, and networking resources, such as the M and T series. General Purpose instances are sufficient for most scenarios.
Compute Optimized: Designed for compute-intensive applications, represented by the C series.
Memory Optimized: These instances are tailored for workloads requiring fast performance for large data sets, primarily including the R and X series.
Accelerated Computing: Instances that use hardware accelerators or co-processors to perform functions like floating-point calculations, graphics processing, or data pattern matching more efficiently than software running on CPUs.
Storage Optimized: These instances are designed for workloads that require high-speed, sequential read and write access to very large data sets on local storage.
HPC Optimized: A new category from AWS (HPC series) primarily suited for applications needing high-performance processing, such as large-scale complex simulations and deep learning workloads.
Generally, each specific EC2 model belongs to a Family with a corresponding numerical identifier. For example, in the General Purpose M series:
M7g / M7i / M7i-flex / M7a
M6g / M6i / M6in / M6a
M5 / M5n / M5zn / M5a
M4
From the series, we can see that the M7 series is the latest generation, while the M4 series is relatively older. The higher the number, the newer the instance and CPU model, which means that the price might also be more affordable for the same configuration (as hardware continually depreciates).
From a typical AWS EC2 instance specification, we can extract the following key parameters:
1. Specific EC2 Model
Typically named <family>.<size>, such as m7g.large or m7g.xlarge. For EC2, a specific model is unique globally.
2. CPU and Memory Size
As shown in the image above, this refers to the size of vCPU and Memory. Most EC2 instances have a 1:4 ratio, meaning that for each vCPU, there are typically 4 GiB of Memory. For example, if there is 1 vCPU, the Memory is usually 4 GiB; if there are 2 vCPUs, the Memory is usually 8 GiB, and so on.
3. Instance Storage
EC2 can typically attach different types of persistent storage volumes, primarily including:
a) gp2/gp3: These are general-purpose SSDs. The official recommendation is to use gp3 for better cost-effectiveness. The default is usually 3000 IOPS, but it also supports on-demand IOPS increases without downtime (which costs more).
b) io1/io2: These offer better performance and higher prices and support features like Multi-Attach (most other EBS types can only be attached to a single EC2 instance).
c) EBS: EBS is AWS’s distributed block storage service and is typically the default persistent storage option for most EC2 instances. Some instances can only use EBS. EBS is tied to specific Availability Zones (AZs), so read/write latency is higher than local SSDs, but it is acceptable for most scenarios. EBS has different types based on parameters like IOPS and throughput.
d) Local Storage: Some instances support both EBS and local storage, which generally comes at a higher price. These instances usually have “d” in their names. For example, m7g.large is an EBS-only instance, while m7gd.large has 1x 118 GiB NVME SSD local storage. Some special instances also support larger local HDDs.
4. EBS Bandwidth
For newer EC2 instance types that are EBS-optimized, AWS provides dedicated EBS bandwidth. This means that in high data throughput scenarios, EBS-optimized instances can enjoy better throughput without competing for resources with the instance’s network bandwidth.
5. Network Bandwidth
This refers to the network bandwidth corresponding to the EC2 instance type.
6. CPU Model
In most cases, you can see the following types of CPUs:
● AWS’s custom ARM-based Graviton processors (currently up to Graviton 3), such as the M7g series.
● Intel x86-64 architecture CPUs.
● AMD x86-64 architecture CPUs.
Generally, for similar configurations, the price order is Intel > AMD > Graviton, while the performance order is the opposite. For general scenarios that are not performance-sensitive, users might consider ARM-based instances to achieve better cost-effectiveness.
AWS was the first cloud provider to introduce ARM architecture into server CPUs. After years of development, the Graviton CPU has made significant progress, offering a strong competitive edge in terms of cost-effectiveness. It is expected that AWS will encourage more customers to use Graviton CPU instances in the future.
7. Virtualization Technology
Different EC2 instance types use different underlying virtualization technologies, leading to some parameter differences. For example, newer EC2 instances generally use Nitro virtualization technology. Nitro is AWS’s latest virtualization technology that offloads many virtualization tasks to hardware, making the software layer lighter, thus enhancing virtualization performance. From the user’s perspective, this results in better performance for the same configuration (due to lower virtualization overhead).
8. Suitability for Machine Learning Scenarios
With the development of LLM technology, more companies are choosing to train their models in the cloud. To use AWS EC2 for model training, the Accelerated Computing instance category is generally used, such as:
P Series and G Series: These use Nvidia GPU chips. At re: Invent 2023, Nvidia and AWS announced a deeper strategic partnership, with AWS planning to use Nvidia’s latest and most powerful GPUs to create a computing platform specifically for generative AI.
Trn and Inf Series: Besides using Nvidia GPUs, AWS has also developed its own chips for machine learning, such as the Trainium chip for training and the Inferentia chip for model inference. The Trn series and Inf series EC2 instances correspond to these AWS-developed machine learning chips, respectively.
Key Takeaways
Based on our simple introduction above (EC2 has much more to offer), we have summarized some tips for readers:
1. For most EC2 instances, generally, the higher the number, the newer the CPU model, the better the performance, and the cheaper the price, making it more cost-effective.
2. In the General Purpose category, the T series is relatively inexpensive and offers a Burstable CPU feature: instances run at baseline performance while accumulating CPU credits, allowing them to exceed baseline performance for certain periods under high load scenarios (at no additional cost). However, the T series has limited performance, generally lower bandwidth, and lacks EBS optimization. Therefore, the T series is more suitable for non-performance-critical test environments.
3. For cost-effectiveness in the General Purpose category, consider choosing AWS ARM architecture instances.
4. The AWS website’s EC2 Pricing is challenging to read. We recommend going to https://ec2instances.info/ for price information (this is also an open-source project).
5. For most cloud users, EC2 costs are typically a significant expense. Here are a few strategies to minimize these costs:
Utilize Cloud Elasticity: Make your architecture as elastic as possible and use computing power on demand. AWS’s Karpenter or Cluster Autoscaler can enable your EC2 instances to scale flexibly.
Use Spot Instances: Spot instances can be 30% to 90% cheaper than On-Demand instances but are subject to interruption and cannot run stably for long periods. AWS will notify you 2 minutes before reclaiming the instance. Properly managed Spot instances are ideal for elastic computing and interrupt-tolerant scenarios. For example, the SkyPilot project uses Spot instances from different clouds for machine learning training.
Optimize Payment Models: Besides technical measures, you can achieve lower unit usage costs than On-Demand instances by purchasing Saving Plans. The drawback is reduced flexibility, which is more suitable for relatively stable business architectures.
Summary
Efficiently selecting and using EC2 must be tailored to the user’s specific scenarios and requires case-by-case analysis. It is an ongoing process of iterative optimization. In summary, fully utilizing cloud elasticity and understanding the key parameters of different EC2 instance types are essential skills that every AWS user must master.