CPU vs. memory cost calculation

Google Cloud Platform (GCP) is the only one of the three major cloud providers that divides compute pricing into CPU and memory costs. Amazon Web Services (AWS) and Microsoft Azure don’t provide this information at the moment.

CAST AI’s cost monitoring module uses a formula to calculate the separate CPU and memory costs for AWS and Azure. The implementation lets you:

  • get more precise cost monitoring data,
  • understand what you’re paying for better,
  • see cost breakdown into workloads, namespaces, and allocation groups (the latter to be released).

This is especially important if you use a lot of memory optimized virtual machines.

The formula is based on the public data from GCP that was extrapolated to estimate the prices of memory and CPU for providers like AWS and Azure.

📘

Some cloud instances have GPU and that resource pricing breakdown needs to be calculated including GPU ratio. We’re currently investigating this and will share the results soon!

Calculating CPU vs. memory pricing

AWS and GCP instances were mapped to calculate the CPU/memory costs based on the memory-to-CPU price ratio in GCP.

The following virtual machines across AWS and GCP were compared:

Resource familyGCP Compute EngineAWS EC2
General purposeE2, N2, N2D, N1A1, M4, M5, M5a, M5n, M5zn, M6g, T2, T3, T3a, T4g, Mac
Compute optimizedC2C4, C5, C5a, C5n, C6g, Cgn
Memory optimizedM1, M2R4, R5, R5a, R5b, R5n, R6g, X1, X1e, High Memory, z1d

CPU vs. memory in general purpose machines

The process started with a calculation of the memory-to-CPU ratio for general purpose machines that have predefined memory and vCPUs.

Machine typePredefinedOn-demandSpot
E2In $ termsPercentageIn $ termsPercentage
Total price$0.0247340$0.0074200
vCPU price$0.021811088.18%$0.006543088.18%
Memory price$0.002923011.82%$0.000877011.82
N2In $ termsPercentageIn $ termsPercentage
Total price$0.0358480$0.0086800
vCPU price$0.031611088.18$0.007650088.13%
Memory price$0.004237011.82%$0.001030011.87%

CPU vs. memory in memory optimized machines

Next, the same was done for memory optimized machines with predefined memory and vCPUs.

Machine typePredefinedOn-demandSpot
M2In $ termsPercentageIn $ termsPercentage
Total price$0.0399000$0.0084100
vCPU price$0.034800087.22%$0.007330087.16%
Memory price$0.005100012.78%$0.001080012.84%

Estimating CPU vs. memory costs in AWS

Based on GCP pricing, the CPU vs. RAM ratio is around 88% to 12%.

The formula used for the calculation is as follows:

instancePricePerHour / ((cpu_count X cpu_ratio) + (ram_gib X ram_ratio)) X resource_ratio

Here is how it works on the example of an r5.large instance:

CPU: 0.126 / ( (2 X 88) + (16 X 12) ) X 88 == 0.0301
RAM: 0.126 / ( (2 X 88) + (16 X 12) ) X 12 == 0.0041

The result was estimated based on the price distribution between CPU and memory prices. Using these ratios, AWS compute costs divided into CPU and memory could be estimated

Here are two tables depicting estimated prices for AWS general purpose and memory optimized machines.

General purpose (on-demand)

InstanceHourly pricevCPUsMemoryvCPU price based on GCP (per vCPU hour)Memory price based on GCP (per GB hour)
c5.large$0.0850024$0.03352$0.00449
c5.xlarge$0.1700048$0.03352$0.00449
c5.2xlarge$0.34000816$0.03352$0.00449
c4.large$0.1000023.75$0.03996$0.00536
c4.xlarge$0.1990047.5$0.03976$0.00533
c4.8xlarge$1.591003660$0.03613$0.00484

Memory-optimized (on-demand)

InstanceHourly pricevCPUsMemoryvCPU price based on GCP (per vCPU hour)Memory price based on GCP (per GB hour)
r5.large$0.12600216$0.02900$0.00425
r5.xlarge$0.25200432$0.02900$0.00425
r5.2xlarge$0.50400864$0.02900$0.00425
r5.4xlarge$1.0080016128$0.02900$0.00425
r5.8xlarge$2.0160032256$0.02900$0.00425

Eventually, the CPU/memory ratio of 88-12 was implemented into CAST AI.

Where to check CPU vs. memory cost in the CAST AI cost monitoring dashboard

To see the breakdown of compute cost into CPU and memory, head over to the the cost monitoring module and click on the cluster or workloads report.

Here is an example of the Workloads report stating the average requests and costs per resource:

Summary

To increase the accuracy of the CAST AI cost monitoring tool, CAST AI shows compute costs divided into CPU and memory for AWS and Azure. You can get more accurate cost monitoring data, understand what you're paying for, and see costs broken down by workloads, namespaces, and labels.


What’s Next

To learn more about how CAST AI does cost monitoring, head over to: