Comparing Serverless Performance for CPU Bound Tasks

Zack Bloom
6 min readadvanced
--
View Original

Overview

This article compares the performance of Cloudflare Workers against AWS Lambda for CPU-bound tasks, particularly focusing on cryptography workloads. It highlights that Cloudflare Workers are significantly faster and more cost-effective than AWS Lambda, especially when handling intensive CPU tasks.

What You'll Learn

1

How to evaluate serverless performance for CPU-bound tasks

2

Why Cloudflare Workers outperform AWS Lambda for cryptographic workloads

3

When to choose higher memory allocation for AWS Lambda functions

Prerequisites & Requirements

  • Understanding of serverless architectures and CPU performance metrics

Key Questions Answered

How do Cloudflare Workers compare to AWS Lambda for CPU-bound tasks?
Cloudflare Workers are seven times faster than a default AWS Lambda function for CPU-bound workloads. For Lambda@Edge, Workers are six times faster globally, demonstrating superior performance in cryptographic tasks.
What is the performance impact of memory allocation on AWS Lambda?
The performance of AWS Lambda is directly related to the memory allocated. Increasing memory from 128MB to 1024MB improves performance, but even at 1024MB, it remains roughly half as fast as Cloudflare Workers.
What are the cost implications of using AWS Lambda versus Cloudflare Workers?
AWS Lambda costs $1.86 per million requests for a function consuming 800ms of compute, while Cloudflare Workers cost $0.50 per million requests. This significant difference highlights the cost-effectiveness of Workers.
Does using native code in AWS Lambda improve performance?
No, executing native code in AWS Lambda does not yield better performance than using JavaScript. The tests showed that both native and JavaScript executions had similar slow performance.

Key Statistics & Figures

95th percentile speed of Cloudflare Workers
242ms
This speed is significantly faster than AWS Lambda@Edge at 842ms and AWS Lambda at 1346ms.
Cost per million requests for AWS Lambda
$1.86
This is compared to $0.50 per million requests for Cloudflare Workers.
Performance difference in CPU speed
6-7x slower
AWS Lambda processors appear to be 6-7x slower than mid-range server cores.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Serverless Platform
Cloudflare Workers
Used for executing CPU-bound tasks with superior performance.
Serverless Platform
AWS Lambda
Competing serverless platform for executing functions with varying performance based on memory allocation.
Cryptographic Algorithm
Pbkdf2
Used as a benchmark for testing CPU performance in the article.

Key Actionable Insights

1
Consider using Cloudflare Workers for CPU-intensive tasks to leverage their superior performance.
If your application involves cryptographic functions or other CPU-bound tasks, deploying on Cloudflare Workers can significantly enhance response times and user experience.
2
Evaluate memory allocation carefully when using AWS Lambda to optimize performance and cost.
Understanding the relationship between memory allocation and CPU performance can help you make informed decisions about resource allocation, potentially saving costs while improving execution speed.
3
Test serverless functions from multiple geographic locations to assess performance accurately.
Using services like Catchpoint to benchmark performance globally can reveal insights about latency and speed that are crucial for optimizing serverless applications.

Common Pitfalls

1
Assuming that increasing memory allocation in AWS Lambda will always lead to better performance.
While more memory can improve performance, it does not guarantee that AWS Lambda will match the speed of Cloudflare Workers, which can lead to unexpected costs and slower response times.

Related Concepts

Serverless Architectures
Cryptographic Performance Benchmarks
Cost Optimization In Cloud Services