Amazon Web Services (AWS) is the most important thing that happened in computer technology since the microprocessor. Over 83% of workloads have been in the cloud as of 2020.
Two AWS servicesare consistently ranked as the most used: Lambda and EC2. Both offer elastic computing resources, but it may not be immediately clear which one suits your needs the best.
The purpose of this research is to define use cases for EC2 instances and Lambda function.
For our experiment, we picked five different EC2 instances and a simple Lambda function. Gatling was used for load testing. The test scenario was configured for 0 to 3,000 concurrent requests per second growing over 30 seconds, the load was generated by factorial calculation for 10,000.
We chose Europe (Ireland) as a testing region because it offers the highest concurrency limit for Lambda functions in Europe out of the box (3,000 vs 500).
AWS Lambda function
AWS Lambda lets you run code without provisioning or managing servers. You pay only for the computer time you consume.
AWS Lambda automatically scales your application by running code in response to each trigger. Your code is executed in parallel and triggers are processed individually, scaling precisely with the size of the workload.
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure and resizeable compute capacity in the cloud.
T is an instance family that offers a balance of compute, memory, and network resources—it is a very cost-effective way to run a broad spectrum of general-purpose workloads. The main advantage of this instance type is burstable CPU performance.
C is an instance family that is ideal for compute-bound applications that benefit from high-performance processors. Instances are well suited for high-performance computing.
P is an accelerated computing instance that uses hardware accelerators, to perform functions, such as floating-point calculations, graphics processing, or data pattern matching.
M is the latest generation of General Purpose Instances. This family provides a balance of compute, memory, and network resources.
Runtime: Java 11 (Corretto)
Memory amount: 512 MB
First errors appeared when the number of concurrent requests reached 2,000, meaning that we reached the top point of lambda performance with current parameters.
Monthly price: based on this calculation month price of the lambda function work will be around 104 USD (0.04×60×60×24×30)
T3.micro is one of the “weakest” instances, and it’s available for free tier usage.
From the 3,626 received requests, 1,697 requests were handled successfully, and 1,929 failed. In the case of an EC2 instance, the exceptions were due to hardware limitations, because it had only 1 GB RAM and two cores, with which only around 25 requests could be handled per second.
Total monthly cost: USD 8.39
T3 instances are designed to run most general purpose workloads at a much lower cost. This instance type can handle around 35 requests per second but with burst points. As a result, it handled 2,222 requests from the 3,769 received.
Having run out of points, we saw a reduction in performance—the instance was able to handle 1,500 requests from 3,200 at about 21 requests per second.
Total monthly cost: USD 34.67
Amazon’s documentation describes C type instances as created for running advanced compute-intensive workloads such as high-performance web servers, HPC. Results paint a somewhat different picture: of the 3,560 received requests, it handled only 1,806.
Total monthly cost: USD 62.85
This one showed the best performance against all previously tested instances, handling 52 requests per second, only 180 of 4,304 requests failing.
Total monthly cost: USD 140.96
The most expensive of the instances we tested, as it is designed to run machine learning and high-performance databases. So, we decided to use a figurative scalpel to cut steel wire…
Of the 4,177 received requests, this instance handled 4,049 successfully and only 128 requests failed.
Total monthly cost: USD 657.80
Aws lambda vs ec2 cost comparison
Processing of a high number of parallel requests is not exactly Lambda’s forte—EC2 instances are much better suited for this purpose.
However, if you don’t need to process frequent requests, Lambda is an excellent choice since you get 1,600,000 requests per month for the cost of a micro instance.