Understanding CPU Credits: The Lifeline of Burstable Instances
If you're using AWS's T-series instances like T2, T3, or T4g, you've opted for what AWS calls "burstable performance instances." These cost-effective options operate on a CPU credit system that can sometimes feel like managing a bank account—you earn credits when your usage is low and spend them during high-demand periods.
When your CPU credit balance runs low, it's not just a technical metric—it's a warning sign that your application's performance is about to hit a wall. Unlike traditional instances that maintain consistent performance, burstable instances will throttle down to their baseline performance (which can be as low as 5-10% of maximum capacity) when credits are exhausted.
How CPU Credits Work
Every burstable instance earns CPU credits continuously at a fixed rate determined by its size. For example, a t3.micro earns 12 credits per hour, while a t3.small earns 24. These credits accumulate when your instance operates below its baseline CPU utilization, and they're consumed when your instance needs to burst above baseline.
The critical points to understand:
- Credits accumulate up to a maximum (typically 24 hours' worth)
- Credits are consumed on a 1:1 basis (1 credit = 1 minute of full CPU core usage)
- Once depleted, your instance is limited to baseline performance
- Baseline performance varies by instance size (e.g., 10% for t3.micro, 20% for t3.small)
Detecting Low CPU Credit Balance Before It's Critical
The first step in addressing low CPU credit balance is knowing when it's happening. AWS provides several CloudWatch metrics to help you monitor your credit status:
- CPUCreditBalance: The number of earned CPU credits your instance has available
- CPUCreditUsage: How many CPU credits your instance has consumed
- CPUSurplusCreditBalance: Tracks surplus credits used (unlimited mode only)
- CPUSurplusCreditsCharged: Tracks surplus credits that resulted in additional charges
Setting Up Effective Alerts
Don't wait until your application slows down to discover you're out of credits. Set up CloudWatch alarms to notify you when your credit balance falls below a safe threshold:
aws cloudwatch put-metric-alarm \
--alarm-name LowCPUCreditBalance \
--alarm-description "Alarm when CPU credit balance falls below 20% of maximum" \
--metric-name CPUCreditBalance \
--namespace AWS/EC2 \
--statistic Average \
--period 300 \
--threshold 72 \
--comparison-operator LessThanThreshold \
--dimensions Name=InstanceId,Value=i-1234567890abcdef0 \
--evaluation-periods 3 \
--alarm-actions arn:aws:sns:region:account-id:topic-name
For a t3.small instance with a maximum credit balance of 576 (24 × 24), setting a threshold at 72 (about 12.5%) gives you adequate warning before performance issues arise.
Immediate Actions When CPU Credits Run Low
When you receive an alert about low CPU credits, time is of the essence. Here are immediate steps to take:
1. Identify and Reduce CPU-Intensive Processes
Log into your instance and use tools like top
, htop
, or the AWS CloudWatch agent to identify what's consuming CPU:
# Sort processes by CPU usage
top -o %CPU
# Or for a snapshot view
ps aux --sort=-%cpu | head -10
Temporarily stop or throttle non-critical processes to allow your credit balance to recover.
2. Leverage Temporary Scaling Options
If your workload can't be reduced, consider these quick alternatives:
- Horizontal scaling: Add more instances and distribute the load
- Temporary instance upgrade: Stop your instance, change the instance type to a larger T-series, and restart (this preserves your EBS volumes and instance configuration)
3. Enable Unlimited Mode (With Caution)
AWS offers an "unlimited" mode for T2, T3, and T4g instances that allows them to burst beyond their credit balance at an additional cost:
aws ec2 modify-instance-credit-specification \
--region us-east-1 \
--instance-credit-specification "InstanceId=i-1234567890abcdef0,CpuCredits=unlimited"
Remember that while unlimited mode prevents performance throttling, it can lead to unexpected costs if high CPU usage persists for extended periods.
Long-Term Strategies to Maintain Healthy Credit Balance
Repeatedly running into low CPU credit issues suggests a need for more permanent solutions:
1. Right-Size Your Instance Type
The simplest solution is often to select an instance type that better matches your workload:
- Upgrade within T-series: Moving from t3.micro to t3.small doubles your credit earn rate
- Shift to compute-optimized: For CPU-bound applications, consider C-series instances
- Consider Graviton-based instances: T4g instances offer better price-performance ratio
2. Implement Intelligent Workload Management
Optimize how and when you consume CPU resources:
- Schedule batch jobs during low-usage periods to avoid depleting credits during peak times
- Implement caching solutions to reduce redundant processing
- Distribute CPU-intensive tasks across multiple instances
- Refactor inefficient code that may be consuming excessive CPU
3. Create a Hybrid Architecture
Not all components of your application have the same CPU requirements:
Frontend (T-series) → Application Logic (M-series) → Data Processing (C-series)
By matching instance families to specific workloads, you can optimize both performance and cost.
When to Consider Unlimited Mode vs. Fixed Performance Instances
Understanding Unlimited Mode in Depth
In unlimited mode, your instance can use "surplus" credits when it exhausts its earned credits. These surplus credits are essentially a line of credit from AWS with specific terms:
- If your average CPU utilization over 24 hours is at or below baseline, these surplus credits are free
- If usage remains high, you'll be charged for surplus credits at a rate of approximately $0.05 per vCPU-hour (varies by region)
The decision to use unlimited mode should consider:
- The predictability of your workload
- How long your high-CPU periods typically last
- Your tolerance for variable costs versus potential performance issues
Signs You Should Abandon Burstable Instances
Consider moving to fixed-performance instances (like M-series, C-series, or R-series) when:
- Your CloudWatch metrics consistently show high CPU utilization above baseline
- You're regularly exhausting your CPU credit balance despite optimization efforts
- The cost of running in unlimited mode is approaching or exceeding the cost of a similarly sized fixed-performance instance
- Your application requires predictable performance without throttling risks
Practical Example: Solving a Real Low Credit Balance Scenario
Let's walk through a practical example: You're running a t3.medium instance hosting a web application that suddenly shows declining CPU credit balance.
Step 1: Diagnosis
Checking CloudWatch, you notice:
- CPU utilization averaging 40% over the past week (above the 20% baseline)
- Credit balance steadily declining, now at 15% of maximum
- Spike in traffic during business hours
Step 2: Immediate Action
- Enable unlimited mode temporarily to prevent throttling
- Identify a database query that's running inefficiently during peak hours
- Apply query optimization and add indexing to reduce CPU load
Step 3: Long-Term Solution
- Implement a read replica for the database to offload queries
- Set up Auto Scaling to add instances during predictable peak hours
- Schedule resource-intensive batch jobs to run during off-peak hours
Conclusion: Balancing Performance and Cost
Managing CPU credits effectively requires a combination of proactive monitoring, rapid response to low balances, and strategic capacity planning. The right approach depends on your specific workload patterns:
- Predictable, low-intensity workloads: Optimize within T-series and leverage credit accrual
- Variable workloads with occasional spikes: Use unlimited mode and Auto Scaling
- Consistently high CPU utilization: Migrate to fixed-performance instances
By implementing the strategies outlined in this guide, you can ensure your AWS instances deliver consistent performance while keeping costs under control. Remember that the most cost-effective solution is often a combination of right-sized instances, optimized workloads, and appropriate scaling strategies.
For more expert AWS optimization strategies and DevOps best practices, visit DevOps Horizon and explore our specialized training programs designed to help you master cloud infrastructure management.