Friday, 29 September 2017

Calculating requirements based on requests per day, cost implications

Lets assume we have the following requirements:
- 1 million requests per day
- assume that all the expected requests in a day are going to be done in 4 hours
- one request takes 100ms of compute
- one request takes 40MB of memory
- stateless application, state stored in database

Please note: 100ms for one request is very heavy computationally, modern CPUs typically perform 5-10 instructions per clock cycle,  Assuming only 1 instructions per 2GHz CPU core clock cycle, then one core can perform 2,000,000,000 instructions/second (or 2,000 MIPS). Let us assume 1000:1 ratio between  high level programming language and machine instructions, then 2GHz CPU core for 100ms is very computationally intensive at 2,000,000 high level instructions.

RPS (Requests Per Second) = 1,000,000 / (4 hours x 3600) = 69.4 
CPU Cores = RPS / (1 / function time for 1 RPS) 
                    = 70 / (1 / 100ms) = 7 
Memory = RPS x (function memory for 1 RPS) / (1 / function time for 1 RPS) 
               = 70 x 40 MB / ( 1 / 100ms) = 280 MB 

Hence, to meet 70 RPS lets round up and we need 8 CPU cores and 512 MB.

See spreadsheet here comparing EC2 Autoscaling, EC2 Spotfleet, Lambda and Docker on EC2 for small, medium and large workloads, please note Lambda is sized 1536MB as due to poor performance of small memory functions::
Small
Requests/day1,000,000
CPU Cores
6.9
Assume all requets over hours
4
Memory MB
277.8
RPS69.4
One RPM CPU time to execute function(s) - ms100.0
One RPM memory to execute function(s) - MB40.0
ArchitectureEC2 AutoscalingEC2 Spotfleet AutoscalingLambdaDocker
Scaling
Scales up/down on demand
Scales up/down on demand
Internal to Lambda (automatic)
Docker Orachestration
Instance type
m3.medium (1 vCPU, 3.75GB)
m3.medium (1 vCPU, 3.75GB)
Internal to Lambda (automatic)
m3.medium (1 vCPU, 3.75GB)
Cost/Hr/Instance
$0.093$0.019$0.00000250$0.093
Daily Cost
$4.84$0.97$2.50$4.84
Yearly Cost
$1,765.14$353.03$912.87$1,765.14
Medium
Requests/day1,000,000
CPU Cores
34.7
Assume all requets over hours
4
Memory MB
17,361.1
RPS69.4
One RPM CPU time to execute function(s) - ms500.0
One RPM memory to execute function(s) - MB500.0
ArchitectureEC2 AutoscalingEC2 Spotfleet AutoscalingLambdaDocker
Scaling
Scales up/down on demand
Scales up/down on demand
Internal to Lambda (automatic)
Docker Orachestration
Instance typec4.large(2 vCPU, 8GB)c4.large(2 vCPU, 8GB)
Internal to Lambda (automatic)
c4.large(2 vCPU, 8GB)
Cost/Hr/Instance
$0.130$0.03$0.00000250$0.130
Daily Cost
$11.96$2.39$12.51$11.96
Yearly Cost
$4,365.40$873.08$4,564.33$4,365.40
Large
Requests/day10,000,000
CPU Cores
138.9
Assume aall requets over hours
4
Memory MB
208,333.3
RPS694.4
One RPM CPU time to execute function(s) - ms200.0
One RPM memory to execute function(s) - MB1,500.0
ArchitectureEC2 AutoscalingEC2 Spotfleet AutoscalingLambdaDocker
Scaling
Scales up/down on demand
Scales up/down on demand
Internal to Lambda (automatic)
Docker Orachestration
Instance typec4.large(2 vCPU, 8GB)c4.large(2 vCPU, 8GB)
Internal to Lambda (automatic)
c4.large(2 vCPU, 8GB)
Cost/Hr/Instance
$0.130$0.03$0.00000250$0.130
Daily Cost
$39.00$7.80$50.02$39.00
Yearly Cost
$14,235.00$2,847.00$18,257.30$14,235.00

No comments:

Post a Comment