Home / AWS

AWSTroubleshootingAdvanced

EC2 burstable T instances at scale: CPU credit exhaustion, unlimited-mode surplus charges and when to leave T

T2, T3, T3a and T4g instances that suddenly slow to a crawl, or bills with surprise CPU credit charges. Read the credit metrics, find affected instances fleet-wide and choose standard, unlimited or a fixed-performance family.

Deepak Bhardwaj7 min read

Applies toAmazon EC2 burstable performance instances (T2, T3, T3a, T4g), EC2 Auto Scaling, CloudWatch Metrics Insights, AWS CLI v2

Symptoms

  • An instance that was fine for weeks becomes slow. CPUUtilization sits flat at a fixed value such as 20% and never goes higher.
  • top inside the instance shows high %st (steal time) while the application waits for CPU.
  • New Auto Scaling instances boot slowly, fail health checks and get replaced in a loop.
  • The bill has "CPU Credits" line items on T3/T4g instances nobody thought were busy.

All four come from the same mechanism: burstable instances earn CPU credits at a fixed baseline rate and spend them when they run above baseline.

How credits work

Mode When the credit balance reaches zero Cost risk
standard CPU is capped at the baseline percentage None, but performance collapses
unlimited Instance keeps bursting and spends surplus credits Surplus credits not paid back by earned credits are charged
  • T2 launches in standard by default. T3, T3a and T4g launch in unlimited by default, unless the account default or launch template says otherwise.
  • The baseline percentage and maximum earned balance depend on the instance size. Check the burstable instance tables in the EC2 documentation for your sizes. Don't assume a t3.large has the same baseline as a t3.micro.
  • In unlimited mode, surplus credits are billed when the instance stops or terminates, or when the surplus grows beyond what the instance could earn back in 24 hours.

Step 1: read the four credit metrics

Metric (AWS/EC2) Meaning Bad sign
CPUCreditBalance Earned credits available Falling steadily to zero (standard mode)
CPUCreditUsage Credits spent per period Consistently above the earn rate
CPUSurplusCreditBalance Surplus credits spent beyond the earned balance (unlimited) Stays above zero for hours
CPUSurplusCreditsCharged Surplus credits that were billed Any non-zero value

These metrics have 5-minute resolution.

ID=i-0123456789abcdef0
for m in CPUCreditBalance CPUSurplusCreditBalance CPUSurplusCreditsCharged; do
  echo "== $m"
  aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name $m \
    --dimensions Name=InstanceId,Value=$ID \
    --start-time $(date -u -d '-24 hours' +%FT%TZ) --end-time $(date -u +%FT%TZ) \
    --period 3600 --statistics Average Maximum \
    --query "sort_by(Datapoints,&Timestamp)[].[Timestamp,Average,Maximum]" --output text
done

aws ec2 describe-instance-credit-specifications --instance-ids $ID

Inside the instance, confirm that the cap, not the application, is the bottleneck:

vmstat 1 5        # 'st' column: steal time
mpstat -P ALL 1 3 # per-CPU %steal (sysstat package)

High steal time with CPUCreditBalance near zero on a standard instance means credit exhaustion.

Step 2: find every affected instance

CloudWatch Metrics Insights queries the whole Region in one call. Lowest credit balances:

aws cloudwatch get-metric-data \
  --start-time $(date -u -d '-3 hours' +%FT%TZ) --end-time $(date -u +%FT%TZ) \
  --metric-data-queries '[{"Id":"low","Period":300,"Expression":"SELECT MIN(CPUCreditBalance) FROM SCHEMA(\"AWS/EC2\", InstanceId) GROUP BY InstanceId ORDER BY MIN() ASC LIMIT 20"}]' \
  --query "MetricDataResults[].{id:Label,latest:Values[0]}" --output table

Instances that ran up surplus charges:

aws cloudwatch get-metric-data \
  --start-time $(date -u -d '-7 days' +%FT%TZ) --end-time $(date -u +%FT%TZ) \
  --metric-data-queries '[{"Id":"chg","Period":86400,"Expression":"SELECT SUM(CPUSurplusCreditsCharged) FROM SCHEMA(\"AWS/EC2\", InstanceId) GROUP BY InstanceId ORDER BY SUM() DESC LIMIT 20"}]' \
  --query "MetricDataResults[].{id:Label,charged:Values}" --output json

Credit mode for every running burstable instance:

aws ec2 describe-instances \
  --filters Name=instance-state-name,Values=running Name=instance-type,Values='t2.*','t3.*','t3a.*','t4g.*' \
  --query "Reservations[].Instances[].InstanceId" --output text \
| xargs -n 100 aws ec2 describe-instance-credit-specifications \
    --query "InstanceCreditSpecifications[].[InstanceId,CpuCredits]" --output text --instance-ids

Step 3: match the cause to the fix

Cause Evidence Fix
Workload grew past the baseline Average CPU above baseline for days, balance trending down Move up a size or to a fixed-performance family (M, C, R)
Standard-mode instance had a short spike that drained it Balance hits zero after a batch job, cron or deploy Switch to unlimited, or move the job elsewhere
ASG launches standard-mode T3/T4g with zero balance New instances slow at boot, health checks fail, scale-out loop Use unlimited in the launch template, or a larger size
Runaway process One process at 100% CPU in top Fix or kill it. In unlimited mode it costs money until you do
Unlimited fleet always bursting CPUSurplusCreditsCharged non-zero every day Price the fixed-performance equivalent. It is often cheaper

Warning

T2 standard instances get launch credits, but T3, T3a and T4g in standard mode don't. A T3 standard instance in an Auto Scaling group can start with little or no balance. If user data, agent installs and application warm-up need more CPU than the baseline, the instance is capped from its first minute. That is a common cause of "instances never become healthy" loops with small T3 sizes.

Changing the credit mode

Per instance, live, no restart:

aws ec2 modify-instance-credit-specification \
  --instance-credit-specifications '[{"InstanceId":"i-0123456789abcdef0","CpuCredits":"unlimited"}]'

In a launch template, so new ASG instances get it:

aws ec2 create-launch-template-version --launch-template-id lt-0123456789abcdef0 \
  --source-version '$Latest' --version-description "unlimited credits" \
  --launch-template-data '{"CreditSpecification":{"CpuCredits":"unlimited"}}'

Account-wide default per family and Region:

aws ec2 get-default-credit-specification --instance-family t3
aws ec2 modify-default-credit-specification --instance-family t3 --cpu-credits standard

Caution

Switching a fleet to unlimited stops the slowdowns, but it turns a performance problem into an open-ended cost. Before you change a large fleet, alarm on CPUSurplusCreditsCharged. Switching back to standard doesn't erase accrued surplus; check the EC2 docs for how surplus is billed when the mode changes.

Standard, unlimited or not T at all

  • Standard fits non-critical, spiky workloads where a slowdown is acceptable and cost must be fixed: dev boxes, jump hosts, low-traffic internal tools.
  • Unlimited fits production workloads that are mostly idle but must never be throttled, as long as you alarm on surplus charges.
  • Fixed performance (M, C, R families) fits anything whose average CPU stays near or above the T baseline. At that point you pay for bursting all the time, and the fixed instance gives you predictable performance for a known price. Compare current On-Demand and Savings Plans prices for both options. Don't rely on a rule of thumb.

AWS Compute Optimizer also flags T instances whose credit pattern suggests a different type or size. Check its findings before you resize by hand.

Alarms to add

# Standard mode: warn before the cap hits
aws cloudwatch put-metric-alarm --alarm-name "$ID-credit-balance-low" \
  --namespace AWS/EC2 --metric-name CPUCreditBalance --dimensions Name=InstanceId,Value=$ID \
  --statistic Minimum --period 300 --evaluation-periods 3 --threshold 20 \
  --comparison-operator LessThanThreshold --treat-missing-data notBreaching \
  --alarm-actions arn:aws:sns:eu-west-1:111122223333:ops-alerts

# Unlimited mode: tell someone when surplus is being billed
aws cloudwatch put-metric-alarm --alarm-name "$ID-surplus-charged" \
  --namespace AWS/EC2 --metric-name CPUSurplusCreditsCharged --dimensions Name=InstanceId,Value=$ID \
  --statistic Sum --period 3600 --evaluation-periods 1 --threshold 0 \
  --comparison-operator GreaterThanThreshold --treat-missing-data notBreaching \
  --alarm-actions arn:aws:sns:eu-west-1:111122223333:ops-alerts

Pick the balance threshold from the instance size's maximum earned balance. For large fleets, use a Metrics Insights query alarm instead of one alarm per instance.

Prevent it next time

  • Set CreditSpecification explicitly in every launch template so the behaviour doesn't depend on account defaults.
  • Review the weekly Metrics Insights report of surplus charges and lowest balances, and resize the top offenders.
  • Keep T sizes out of latency-sensitive production tiers unless you have measured their average CPU against the baseline.
  • Load-test new AMIs on the real instance size. Boot-time CPU on a small T3 is often the hidden cost.