Understanding why AWS t2 instances are cheap and their limitations (CPU credit balance)
In AWS t2 instances are about half to a third of the price of dedicated servers or c2 instances. There are good reasons for that, and failing to understand this might put you in situations where your application crashes unexpectedly. In this article we’ll go through the concept of CPU credit, and explain how their consumption is impacting your available processing power, ie your ability to deliver your application.
CPU Credits
Unlike c2 instances, t2 instances are bound by CPU credits. At any point in time, AWS is monitoring your CPU consumption. AWS assign a threshold to t instances which determine if you collect or consume CPU credits.
If for example we take a t2.medium instance, AWS tells us that any utilization below 20% of CPU capacity is building credits, while any utilization above is consuming these credits.
These credits can be monitored on the CPU Credit Balance view. This balance is capped to 576 on a t2.medium.
You can find threshold, balance cap and accrual rate for each instance on the following page: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/burstable-credits-baseline-concepts.html
In the example above, since my CPU credit usage is below 1, I am collecting credits, which means that my CPU usage is below 20%.
AWS summarize it very well in this picture:
What happens to these credits when my instance is used?
The example above shows us how a high CPU utilization, ie 100% is driving CPU credit usage up, mechanically lowering steadily our credit balance.
So any usage of CPU above the threshold for my instance (20% in the case of a t2.medium) will drive consumption of my CPU credits.
What happens if my CPU Credit balance reaches 0?
Well, very simple, your instance available CPU gets capped at the credit threashold, ie for a t2 medium, until your usage does not allow build up of credits (20% or more usage), your CPU performance will never go above 20%.
This is a quite tricky situation, because at a moment where you need CPU resources the most (ie you consume CPU credits), you suddenly get capped at 20%, which will very likely increase the bottleneck and lead to a total blockage of your instance. If you run a DB on that instance for example, it is very likely that you will have to restart the instance, even if the requests stop coming in.
How to determine if a t2 instance will fit my application then?
You have 3 scenarios here.
- my application uses steadily CPU equal or above the baseline of my instance:
T instance is not for you. Your CPU needs are too steady and high, you should instead look for a compute optimized instance (C instances).
- my application uses steadily CPU below the baseline of my instance
T instances are ok for your use case.
- my application uses CPU between the baseline and 100% , less than (baseline)% of the day and non continuously:
T instances are for you. As long as your peak above the baseline is not too long, you will not exhaust your credits and therefore will be able to enjoy the CPU bursts anytime.
Conclusion
You now understand the concept of burstable instance, ie having a baseline and being able to go above this baseline during a limited time determined by your CPU credits. All depend on your use case, but don’t expect to be able to do sustained CPU intensive tasks on a T instance, or run a webshop with good amount of traffic. You’ll definitely prefer C instances or M (depending on your memory needs).
Need help with your IT strategy or performance roadmap, I am also providing consulting and implementation services. Contact me by email v.teyssier@gmail.com