Optimizing Performance: A Comprehensive Guide to Choosing the Right T-Family Instance with Metrics and Amazon Q
Tags: amazonq, ec2, devops, aws
Published: 2024-02-04 15:37:08

Amazon Web Services (AWS) offers a diverse range of EC2 instances tailored to meet the specific needs of different workloads. Among these, the T-family instances, including previous generation T2, and latest generation: T3, T3a and T4g instances, are unique as they belong to the burstable performance category. In this detailed technical article, we will explore the key concepts, best practices, and features associated with these instances, shedding light on their inner workings and helping you make informed decisions for your applications.

## Key Concepts and Definitions for Burstable Performance Instances:

**Earn CPU Credits:** Burstable performance instances operate on a credit-based system. Credits are earned during periods of low CPU utilization and spent when the CPU needs to burst to higher performance levels. A t3.nano instance, for example, earns 6 credits per hour with 2 vCPUs. These credits act as a currency that allows the instance to burst beyond its baseline capacity.

**CPU Credit Earn Rate:** The rate at which credits are earned varies based on the instance type. It is crucial to understand this metric to estimate how quickly the instance can accumulate credits during low utilization periods. AWS provides detailed documentation on the earn rate for each instance type, aiding users in making informed decisions.

**CPU Credit Accrual Limit:** To prevent excessive accumulation of credits, AWS imposes a limit on the maximum number of credits an instance can accrue. This limit ensures fair usage and prevents instances from gaining an unfair advantage during burst periods. Users should be aware of this limit and plan accordingly.

**Accrued CPU Credits Lifespan:** CPU credits have a limited lifespan, and they expire if not used within that period. The accrual limit, therefore, becomes critical to avoid unnecessary credit wastage. By monitoring and understanding the lifespan of accrued credits, users can optimize the burstable performance of their instances.

**Baseline Utilization:** The baseline utilization represents the average CPU usage of an instance over time, calculated as `(number of credits earned/number of vCPUs)/60 minutes`. For instance, a T3.nano instance with 2 vCPUs earning 6 credits per hour results in a baseline utilization of 5%.
This metric helps users gauge the efficiency of their instances and determine if they are operating within the expected baseline. 

## Unlimited Mode for Burstable Performance Instances

![Unlimited Mode for Burstable Performance Instances](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/af8z20qcppfn8cz0u2sv.gif)

AWS offers an "Unlimited" mode for burstable performance instances, allowing them to burst beyond their baseline capacity without the fear of credit depletion. This mode is useful for workloads with unpredictable or spiky CPU demands. When an instance operates in Unlimited mode, it incurs an additional charge for surplus credits beyond the maximum daily limit.

Knowing when to use Unlimited mode versus Fixed CPU mode is crucial. For applications with consistent and predictable workloads, Fixed CPU mode may be more cost-effective, as it avoids the additional charges associated with Unlimited mode.

## Standard Mode for Burstable Performance Instances

![Standard Mode for Burstable Performance Instances](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zeel1olfqmlinqd9jsng.gif)

In Standard mode, burstable performance instances operate within their baseline capacity, and users can control the burst behavior by managing the available launch credits. Launch credits are granted at the start of each instance and are spent during burst periods.

Understanding launch credit limits is essential for optimizing performance. Users should consider adjusting these limits based on the specific requirements of their workloads.

## Monitoring CPU Credits

Effectively monitoring CPU credits is vital to ensure optimal performance and cost management. AWS provides CloudWatch metrics specifically designed for burstable performance instances, updated every five minutes:

- **CPUCreditUsage**: The number of CPU credits spent during the measurement period.
- **CPUCreditBalance**: The number of CPU credits accrued by the instance.
- **CPUSurplusCreditBalance**: Surplus credits spent to sustain CPU utilization when `CPUCreditBalance` is zero.
- **CPUSurplusCreditsCharged**: Surplus credits exceeding the maximum daily limit, incurring additional charges.

Determine CPU credit utilization for Standard instances by assessing the movement in the CPU credit balance. An increase in the CPU credit balance occurs when CPU utilization falls below the baseline, signifying that the credits spent are less than those earned in the preceding five-minute interval.

Conversely, a decrease in the CPU credit balance is observed when CPU utilization surpasses the baseline, indicating that the credits spent exceed those earned in the prior five-minute interval. Mathematically, this relationship can be expressed through the following equation:

```
CPUCreditBalance= prior CPUCreditBalance+[Credits earned per hour×(60/5)−CPUCreditUsage]
```

These metrics provide a comprehensive view of an instance's credit utilization, helping users make informed decisions about their workloads.

## Instance Type Recommendations

Recommendations for Selecting Optimal Instance Types
Amazon Web Services (AWS) offers valuable tools to simplify the process of choosing the most suitable instance types for your workloads. With a diverse range of instance options available, finding the right balance between performance and cost can be challenging. AWS provides two key tools for making informed decisions based on your workload characteristics:

## New Workloads: Amazon Q EC2 Instance Type Selector
For new workloads, the Amazon Q EC2 Instance Type Selector proves invaluable. This tool considers your use case, workload type, CPU manufacturer preference, and your prioritization of price and performance. By leveraging this data, it provides guidance and suggestions for Amazon EC2 instance types that align best with your specific requirements.

Navigating through the Amazon EC2 console, you can access the Amazon Q EC2 instance type selector to stay updated on the latest instance types and ensure optimal price-performance for your workloads. Whether seeking advice directly from Amazon Q or using the console, this tool streamlines the process of selecting the right instance type. To utilize the Amazon Q EC2 instance type selector:

1. Follow the procedure to [launch an instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-instance-wizard.html#liw-quickly-launch-instance) 
2. Next to the Instance type, click on the `Get advice` link.
![ec2 Instance type Get advice](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ae65z8mkzxwumfonnh5x.png)

3. In the "Get advice on instance type selection from Amazon Q" window, specify your requirements by choosing options from the drop-down lists, including Use Case and Workload type. Click on `Get instance type advice` button.
![Amazon Q Window](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f49ip08uvfeebs0zmhm6.png)

4. The Amazon Q AI assistant opens with personalized suggestions for instance types based on your specified requirements.
![Amazon Q AI assistant opens with personalized suggestions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4k6ksvfbjuumyw478a90.png)

5. Once you've decided on an instance type, proceed to the launch instance wizard or launch template, and select the recommended instance type.


## Existing Workloads: AWS Compute Optimizer
For existing workloads, AWS Compute Optimizer steps in to provide recommendations aimed at enhancing performance, reducing costs, or achieving a balance of both. By analyzing your current instance specifications and utilization metrics, Compute Optimizer determines which Amazon EC2 instance types are most suitable for handling your existing workload. The recommendations come complete with per-hour instance pricing to aid in decision-making.  For a comprehensive guide on utilizing AWS Compute Optimizer, refer to the [AWS Compute Optimizer User Guide](https://docs.aws.amazon.com/compute-optimizer/latest/ug/viewing-dashboard.html).


## Conclusion 
In summary, gaining a deep understanding of AWS burstable performance instances empowers users to make informed decisions about their infrastructure. Proficiency in concepts like CPU credits, baseline utilization, and the monitoring of metrics through CloudWatch is crucial. Additionally, leveraging tools such as Amazon Q for selecting the right instance type further enhances users' ability to achieve cost-effective and efficient performance in the cloud.

Sources:

- [Burstable performance instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/burstable-performance-instances.html)
- [What is Amazon Q (for AWS builder use)](https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/what-is.html)