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 services are 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.
EC2 vs Lambda history
To deeply understand the difference between Ec2 vs Lambda we have to take a closer look at the evolution of cloud services.
First there were a bare metal installed in the office. Roughly speaking you have a server installed in the room. You pay for the electricity, amortization of costs, you have to hire a dedicated expert who maintains it. A lot of headache, isn’t it?
Then there were rented servers. Way better. You don’t have to rent a space to install servers in your office and pay for the electricity. Still you rent the bare metail and you have to install everything by your own.
Then the EC2 comes in the game. No dedicated space, no electricity, OS is installed, network is ready to go. Don’t have to worry about failed hard drives or overheated CPU’s. Still you need a developer who installs the software, take care about the security updates.
And then the Lambda arises. Or just serverless approach. Of course it’s only a hype name. Server is still there, owned by the cloud provider. It’s just you who doesn’t care.
No more renting space, no more electricity bills, no payrolls for the dedicated team maintaining it. Only pure piece of code running in the thing air. Belissimo. No, it is not.
Being such a beautiful tool cannot be at no cost. And the cost is:
Time to warm up.
Lambda cannot start “immediately”. It took some time to launch.
Absence of state.
There are cases when it would be better to store intermediate calculations in memory, rather than saving into database and then retrieve wasting precious time.
It’s vastly scalable but till the 3,000 requests per second (and it may be different depending on the region)
In case you have short running job, that running several times per day and you don’t care about latency, then use Lambda otherwise use EC2.
What if you are somewhere in the middle? Then choice is not so obvious and here we conducted the experiment.
For our experiment, we picked five different EC2 instances and a simple Lambda function. To write the test scenario we used Gatling which was used for load testing. In Broscorp we use this tool to test that our software can handle designed amount of requests. 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).
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.
Reason for exceptions in Lambda quotas.
In general, Lambda successfully handled 4,601 requests from 5,420, and only 819 failed
Total experiment costs:
4,601 requests × 600 ms × 0.001 ms to sec conversion factor = 2,760.60 total compute (seconds)
Monthly price: based on this calculation month price of the lambda function work will be around 104 USD (0.04×60×60×24×30)
For EC2 we have selected several instance types such as:
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.
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
Conclusion about 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.
Aws lambda vs ec2 cost comparison
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.
If you have additional questions about the AWS platform, contact custom software development company Broscorp.
Get your free project assessment
Leave us your email and we will contact you shortly