Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What vCPUs in Fargate really mean?

I was trying to get answers on my question here and here, but I understood that I need to know specifically Fargate implementation of vCPUs. So my question is:

  1. If I allocate 4 vCPUs to my task does that mean that my single-threaded app running on a container in this task will be able to fully use all this vCPUs as they are essentially only a portion of time of the processor's core that I can use?
  2. Let's say, I assigned 4vCPUs to my task, but on a technical level I assigned 4vCPUs to a physical core that can freely process one thread (or even more with hyperthreading). Is my logic correct for the Fargate case?

p.s. It's a node.js app that runs session with multiple players interacting with each other so I do want to provide a single node.js process with a maximum capacity.

like image 294
Ruslan Plastun Avatar asked Aug 30 '18 07:08

Ruslan Plastun


People also ask

What does 1 vCPU mean AWS?

An AWS vCPU is a single hyperthread of a two-thread Intel Xeon core for M5, M4, C5, C4, R4, and R4 instances. A simple way to think about this is that an AWS vCPU is equal to half a physical core.

What does 0.25 vCPU mean?

It means that you're using a shared CPU where you will get only the amount you have selected as dedicated just like in virtual environments and virtual machines. So, 0.25 vCPU means that you will get dedicated 25% of 1 vCPU.

What is vCPUs?

A vCPU stands for virtual central processing unit. One or more vCPUs are assigned to every Virtual Machine (VM) within a cloud environment. Each vCPU is seen as a single physical CPU core by the VM's operating system.

Does a vCPU equal a core?

A VCPU is a core. Your CPU, if Hyperthreaded, doubles your amount of physical cores. Example: You a Quad Core Xeon Processor Socket. It has 4 cores, but it is presented as 8 cores because of hyperthreading.


2 Answers

Fargate uses ECS (Elastic Container Service) in the background to orchestrate Fargate containers. ECS in turn relies on the compute resources provided by EC2 to host containers. According to AWS Fargate FAQ's:

Amazon Elastic Container Service (ECS) is a highly scalable, high performance container management service that supports Docker containers and allows you to easily run applications on a managed cluster of Amazon EC2 instances ...

ECS uses containers provisioned by Fargate to automatically scale, load balance, and manage scheduling of your containers

This means that a vCPU is essentially the same as an EC2 instance vCPU. From the docs:

Amazon EC2 instances support Intel Hyper-Threading Technology, which enables multiple threads to run concurrently on a single Intel Xeon CPU core. Each vCPU is a hyperthread of an Intel Xeon CPU core, except for T2 instances.

So to answer your questions:

  1. If you allocate 4 vCPUs to a single threaded application - it will only ever use one vCPU, since a vCPU is simply a hyperthread of a single core.

  2. When you select 4 vCPUs you are essentially assigning 4 hyperthreads to a single physical core. So your single threaded application will still only use a single core.

If you want more fine grained control of CPU resources - such as allocating multiple cores (which can be used by a single threaded app) - you will probably have to use the EC2 Launch Type (and manage your own servers) rather than use Fargate.


Edit 2021: It has been pointed out in the comments that most EC2 instances in fact have 2 hyperthreads per CPU core. Some specialised instances such as the c6g and m6g have 1 thread per core, but the majority of EC2 instances have 2 threads/core. It is therefore likely that the instances used by ECS/Fargate also have 2 threads per core. For more details see doco

like image 61
moebius Avatar answered Oct 19 '22 05:10

moebius


You can inspect what physical CPU your ECS runs on, by inspecting the /proc/cpuinfo for model name field. You can just cat this file in your ENTRYPOINT / CMD script or use ECS Exec to open a terminal session with your container.

I've actually done this recently, because we've been observing some weird performance drops on some of our ECS Services. Out of 84 ECS Tasks we ran, this was the distribution:

Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz      (10 tasks)
Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz  (22 tasks)
Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz  (10 tasks)
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz (25 tasks)
Intel(R) Xeon(R) Platinum 8275CL CPU @ 3.00GHz (17 tasks)

Interesting that it's 2022 and AWS is still running CPUs from 2016 (the E5-2686 v4). All these tasks are fully-paid On-Demand ECS Fargate. When running some tasks on SPOT, I even got an E5-2666 v3 which is 2015, I think.

While assigning random CPUs for our ECS Tasks was somewhat expected, the differences in these are so significant that I observed one of my services to report 25% or 45% CPU Utilization in idle, depending on which CPU it hits on the "ECS Instance Type Lottery".

like image 3
npe Avatar answered Oct 19 '22 05:10

npe