SlideShare a Scribd company logo
How to avoid common mistakes
and misconceptions when
working with Java on AWS Lambda
•Andrzej Dębski
Technicalities
• Disclaimer
• Q&A
• url: sli.do
• code: #geecon2022
• Code:
• https://github.com/Adebski/LambdaJavaGeecon
Andrzej Dębski
About me
• A decade of experience with JVM languages, mostly Java
and Scala
• Working with server-based environments since the beginning
• Pratical experience with AWS Lambda since February 2021
• Maitanance and development of 2 existing services
• Development of additional two services from scratch
Andrzej Dębski
Agenda
1. Cold starts (generic and those specific to JVM)
2. AWS Lambda Pricing
3. In-memory caching on Lambda
Andrzej Dębski
Cold starts
Speaker’s Name
Lambda instance lifecycle
Andrzej Dębski
Cold start type 1 (container recycle)
1. 18:16:32 Duration: 85.24 ms Max Memory Used: 109
MB Init Duration: 1821.08 ms
2. 18:18:50 Duration: 1.95 ms Max Memory Used: 109
MB
3. 18:24:05 Duration: 1.74 ms Max Memory Used: 109
MB
4. 18:30:40 Duration: 72.91 ms Max Memory Used: 109
MB Init Duration: 1870.40 ms
Andrzej Dębski
Cold start type 2 (JVM JIT and lazy load)
1. Code path 1: Duration: 731.32 ms
2. Code path 1: Duration: 19.86 ms
3. Code path 1: Duration: 4.31 ms
4. Code path 2: Duration: 1261.40 ms (new code path
executed for the first time)
5. Code path 2: Duration: 2.12 ms
Andrzej Dębski
Reducing cold starts
1.Provisioned concurrency (best but costly)
1.Keeps a set of instances ready to respond to requests
2."Background" traffic (best effort)
3.Use a different language (e.g. Go) or use AOT
compilation through GraalVM
1.https://shinesolutions.com/2021/08/30/improving-cold-start-
times-of-java-aws-lambda-functions-using-graalvm-and-
native-images/
Andrzej Dębski
Cold start for provisioned concurrency
1. Code path 1: Duration: 33.12 ms
2. Code path 1: Duration: 2.09 ms
3. Code path 1: Duration: 2.34 ms
4. Code path 2: Duration: 2.03 ms (new code path
executed for the first time)
5. Code path 2: Duration: 2.40 ms
Andrzej Dębski
Provisioned concurrency best practices
1.Make sure the function is invoked using the alias.
2.Monitor (and alarm) on metrics
1. ProvisionedConcurrencySpilloverInvocations
2. ProvisionedConcurrencyUtilization
3. Pre-warm the code paths in the constructor
4. Use code deploy policies to gradually deploy
new function revisions.
Andrzej Dębski
Recap
1.Cold starts are real and they affect the JVM
Lambdas even more
2.Either accept them or pay for provisioned
concurrency (and use it well)
3. Monitor and instrument your functions to
understand the bottlenecks in your code
Andrzej Dębski
$$$
Speaker’s Name
Lambda pricing
1. Lambda price (https://aws.amazon.com/lambda/pricing/):
1. On demand: billed for every GB-second
(sum(duration ) * allocated memory) + number of
invocations
2. Provisioned concurrency is more complicated. We
pay for keeping the containers "warm"
2. Free-tier
Andrzej Dębski
How to calculate AWS costs
1. AWS pricing calculator
1. https://calculator.aws/#/
2. Cost estimates for the following examples:
1. https://tinyurl.com/yk7v3wek
Andrzej Dębski
Andrzej Dębski
Assumptions
1. "Average" request time: 200 ms
2. Monthly costs
3. Region: us-east-1
4. Focus on compute cost, ignore everything else
Andrzej Dębski
Scenarios considered
1. "Hello world": on-demand vs provisioned capacity
2. Smallest Fargate vs Lambda
3. StackExchange on Lambda vs Fargate
Andrzej Dębski
"Hello world", 1 request per second
Andrzej Dębski
256 MB RAM
On demand Provisioned
capacity of 1
0.33 $ 4.55 $
Fargate, 1 request per second
Andrzej Dębski
1769 MB RAM 1vCPU
2GB RAM
On demand Provisioned
capacity of 1
Fargate
8.8 $ 28.28 $ 36.04 $
Simulating Stack Exchange
1. https://stackexchange.com/performance
1. 1.3* 10^9 monthly page views means ~495
requests per second
2. For Fargate we assume 9 tasks to protect from AZ
outage, 82.5 RPS per task.
3. For Lambda provisioned concurrency try to handle
every request with prov capacity.
1. 495 (RPS) / 5 (requests per second per container) = 99
Andrzej Dębski
SE, 495 requests per second
Andrzej Dębski
1769 MB RAM 1vCPU
2GB RAM
On demand Provisioned
capacity of 99
Fargate,
9 tasks
7,744.27 $ 6,502.63 $ 324.36 $
Recap
1. Free-tier
2. Use the AWS Pricing Calculator
3. With more traffic Lambda gets really costly
4. Take advantage of the "free" compute during init phase for
on-demand lambdas
5. For consistent workloads provisioned concurrency may be
cheaper
6. Always consider factors other than $$$ when evaluating
technologies
Andrzej Dębski
https://hichaelmart.medium.com/shave-99-93-off-your-
lambda-bill-with-this-one-weird-trick-33c0acebb2ea
Caching
Speaker’s Name
Caching in Lambda – challenges
1. No hard guarantees when the container will be
recycled
2. Best effort async updates
3. No control over the routing algorithm (no sticky
sessions)
Andrzej Dębski
Caching in Lambda – approaches
1. (Mostly) rely on out of process cache
2. Use different compute platform if L1 cache is critical
3. Use Lambda extensions
1.That's how AWS AppConfig does it
Andrzej Dębski
Caching in Lambda – extensions
1. Code that can execute alongside your Lambda
2. Extension continues to execute AFTER the Lambda
handler returned a response.
3. Implementing cache in extension
1.Save the data on Lambda FS
2.Expose local HTTP server and serve the data
Andrzej Dębski
Lambda extension overview
Andrzej Dębski
Extensions for caching
1. (+) "Asynchronous" cache updates
2. (-) Overhead (in ms):
1.Avg (no ext/ext): 1.88 ms/14.1 ms
2.Tm99.9 (no ext/ext): 1.88 ms/14.2 ms
3. (-) Lambda instance can't handle new requests until
extension is done
4. (-) Extension instances are not shared between
containers
Andrzej Dębski
Recap
1. In memory caching in Lambda is not straightforward
1. Small window of time where the cache is "warm"
2. Asynchronous updates are best effort only
2. Extensions improve the situation but have their own
downsides
1. Runtime overhead
2. Complicate the flow
3. L2 cache or different compute platform
Andrzej Dębski
Q&A
url: sli.do
code: #geecon20202
Andrzej Dębski

More Related Content

Similar to Geecon2022: How to avoid common mistakes and misconceptions when working with Java on AWS Lambda

Build optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and DockerBuild optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and Docker
Dmytro Patkovskyi
 
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
Derek Ashmore
 
K8s best practices from the field!
K8s best practices from the field!K8s best practices from the field!
K8s best practices from the field!
DoiT International
 
Lambda and serverless - DevOps North East Jan 2017
Lambda and serverless - DevOps North East Jan 2017Lambda and serverless - DevOps North East Jan 2017
Lambda and serverless - DevOps North East Jan 2017
Mike Shutlar
 
Functional Programming in Serverless World (Serveless UG Poland)
Functional Programming in Serverless World (Serveless UG Poland)Functional Programming in Serverless World (Serveless UG Poland)
Functional Programming in Serverless World (Serveless UG Poland)
Serverless User Group Poland
 
Monitoring, Hold the Infrastructure - Getting the Most out of AWS Lambda – Da...
Monitoring, Hold the Infrastructure - Getting the Most out of AWS Lambda – Da...Monitoring, Hold the Infrastructure - Getting the Most out of AWS Lambda – Da...
Monitoring, Hold the Infrastructure - Getting the Most out of AWS Lambda – Da...
Amazon Web Services
 
Us 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimesUs 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimes
Ravishankar Somasundaram
 
Adopting Java for the Serverless world at AWS User Group Pretoria
Adopting Java for the Serverless world at AWS User Group PretoriaAdopting Java for the Serverless world at AWS User Group Pretoria
Adopting Java for the Serverless world at AWS User Group Pretoria
Vadym Kazulkin
 
AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...
AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...
AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...
AWS Chicago
 
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UKStorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS
 
JClouds at San Francisco Java User Group
JClouds at San Francisco Java User GroupJClouds at San Francisco Java User Group
JClouds at San Francisco Java User Group
Marakana Inc.
 
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Derek Ashmore
 
Dock ir incident response in a containerized, immutable, continually deploy...
Dock ir   incident response in a containerized, immutable, continually deploy...Dock ir   incident response in a containerized, immutable, continually deploy...
Dock ir incident response in a containerized, immutable, continually deploy...
Shakacon
 
Containers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. KubernetesContainers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. Kubernetes
Dmitry Lazarenko
 
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
Vadym Kazulkin
 
Fast Deployments to Multiple Golang Lambda Functions
Fast Deployments to Multiple Golang Lambda FunctionsFast Deployments to Multiple Golang Lambda Functions
Fast Deployments to Multiple Golang Lambda Functions
Kp Krishnamoorthy
 
aws lambda & api gateway
aws lambda & api gatewayaws lambda & api gateway
aws lambda & api gateway
fumihiko hata
 
Migrating Data Pipeline from MongoDB to Cassandra
Migrating Data Pipeline from MongoDB to CassandraMigrating Data Pipeline from MongoDB to Cassandra
Migrating Data Pipeline from MongoDB to Cassandra
Demi Ben-Ari
 
Functional Programming in Serverless World
Functional Programming in Serverless WorldFunctional Programming in Serverless World
Functional Programming in Serverless World
Wojciech Gawroński
 
Adopting Java for the Serverless world at Serverless Meetup Singapore
Adopting Java for the Serverless world at Serverless Meetup SingaporeAdopting Java for the Serverless world at Serverless Meetup Singapore
Adopting Java for the Serverless world at Serverless Meetup Singapore
Vadym Kazulkin
 

Similar to Geecon2022: How to avoid common mistakes and misconceptions when working with Java on AWS Lambda (20)

Build optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and DockerBuild optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and Docker
 
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2019
 
K8s best practices from the field!
K8s best practices from the field!K8s best practices from the field!
K8s best practices from the field!
 
Lambda and serverless - DevOps North East Jan 2017
Lambda and serverless - DevOps North East Jan 2017Lambda and serverless - DevOps North East Jan 2017
Lambda and serverless - DevOps North East Jan 2017
 
Functional Programming in Serverless World (Serveless UG Poland)
Functional Programming in Serverless World (Serveless UG Poland)Functional Programming in Serverless World (Serveless UG Poland)
Functional Programming in Serverless World (Serveless UG Poland)
 
Monitoring, Hold the Infrastructure - Getting the Most out of AWS Lambda – Da...
Monitoring, Hold the Infrastructure - Getting the Most out of AWS Lambda – Da...Monitoring, Hold the Infrastructure - Getting the Most out of AWS Lambda – Da...
Monitoring, Hold the Infrastructure - Getting the Most out of AWS Lambda – Da...
 
Us 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimesUs 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimes
 
Adopting Java for the Serverless world at AWS User Group Pretoria
Adopting Java for the Serverless world at AWS User Group PretoriaAdopting Java for the Serverless world at AWS User Group Pretoria
Adopting Java for the Serverless world at AWS User Group Pretoria
 
AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...
AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...
AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...
 
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UKStorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
 
JClouds at San Francisco Java User Group
JClouds at San Francisco Java User GroupJClouds at San Francisco Java User Group
JClouds at San Francisco Java User Group
 
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
 
Dock ir incident response in a containerized, immutable, continually deploy...
Dock ir   incident response in a containerized, immutable, continually deploy...Dock ir   incident response in a containerized, immutable, continually deploy...
Dock ir incident response in a containerized, immutable, continually deploy...
 
Containers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. KubernetesContainers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. Kubernetes
 
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
 
Fast Deployments to Multiple Golang Lambda Functions
Fast Deployments to Multiple Golang Lambda FunctionsFast Deployments to Multiple Golang Lambda Functions
Fast Deployments to Multiple Golang Lambda Functions
 
aws lambda & api gateway
aws lambda & api gatewayaws lambda & api gateway
aws lambda & api gateway
 
Migrating Data Pipeline from MongoDB to Cassandra
Migrating Data Pipeline from MongoDB to CassandraMigrating Data Pipeline from MongoDB to Cassandra
Migrating Data Pipeline from MongoDB to Cassandra
 
Functional Programming in Serverless World
Functional Programming in Serverless WorldFunctional Programming in Serverless World
Functional Programming in Serverless World
 
Adopting Java for the Serverless world at Serverless Meetup Singapore
Adopting Java for the Serverless world at Serverless Meetup SingaporeAdopting Java for the Serverless world at Serverless Meetup Singapore
Adopting Java for the Serverless world at Serverless Meetup Singapore
 

Recently uploaded

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 

Recently uploaded (20)

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 

Geecon2022: How to avoid common mistakes and misconceptions when working with Java on AWS Lambda

  • 1. How to avoid common mistakes and misconceptions when working with Java on AWS Lambda •Andrzej Dębski
  • 2. Technicalities • Disclaimer • Q&A • url: sli.do • code: #geecon2022 • Code: • https://github.com/Adebski/LambdaJavaGeecon Andrzej Dębski
  • 3. About me • A decade of experience with JVM languages, mostly Java and Scala • Working with server-based environments since the beginning • Pratical experience with AWS Lambda since February 2021 • Maitanance and development of 2 existing services • Development of additional two services from scratch Andrzej Dębski
  • 4. Agenda 1. Cold starts (generic and those specific to JVM) 2. AWS Lambda Pricing 3. In-memory caching on Lambda Andrzej Dębski
  • 7.
  • 8.
  • 9.
  • 10. Cold start type 1 (container recycle) 1. 18:16:32 Duration: 85.24 ms Max Memory Used: 109 MB Init Duration: 1821.08 ms 2. 18:18:50 Duration: 1.95 ms Max Memory Used: 109 MB 3. 18:24:05 Duration: 1.74 ms Max Memory Used: 109 MB 4. 18:30:40 Duration: 72.91 ms Max Memory Used: 109 MB Init Duration: 1870.40 ms Andrzej Dębski
  • 11.
  • 12. Cold start type 2 (JVM JIT and lazy load) 1. Code path 1: Duration: 731.32 ms 2. Code path 1: Duration: 19.86 ms 3. Code path 1: Duration: 4.31 ms 4. Code path 2: Duration: 1261.40 ms (new code path executed for the first time) 5. Code path 2: Duration: 2.12 ms Andrzej Dębski
  • 13. Reducing cold starts 1.Provisioned concurrency (best but costly) 1.Keeps a set of instances ready to respond to requests 2."Background" traffic (best effort) 3.Use a different language (e.g. Go) or use AOT compilation through GraalVM 1.https://shinesolutions.com/2021/08/30/improving-cold-start- times-of-java-aws-lambda-functions-using-graalvm-and- native-images/ Andrzej Dębski
  • 14.
  • 15. Cold start for provisioned concurrency 1. Code path 1: Duration: 33.12 ms 2. Code path 1: Duration: 2.09 ms 3. Code path 1: Duration: 2.34 ms 4. Code path 2: Duration: 2.03 ms (new code path executed for the first time) 5. Code path 2: Duration: 2.40 ms Andrzej Dębski
  • 16. Provisioned concurrency best practices 1.Make sure the function is invoked using the alias. 2.Monitor (and alarm) on metrics 1. ProvisionedConcurrencySpilloverInvocations 2. ProvisionedConcurrencyUtilization 3. Pre-warm the code paths in the constructor 4. Use code deploy policies to gradually deploy new function revisions. Andrzej Dębski
  • 17. Recap 1.Cold starts are real and they affect the JVM Lambdas even more 2.Either accept them or pay for provisioned concurrency (and use it well) 3. Monitor and instrument your functions to understand the bottlenecks in your code Andrzej Dębski
  • 19. Lambda pricing 1. Lambda price (https://aws.amazon.com/lambda/pricing/): 1. On demand: billed for every GB-second (sum(duration ) * allocated memory) + number of invocations 2. Provisioned concurrency is more complicated. We pay for keeping the containers "warm" 2. Free-tier Andrzej Dębski
  • 20. How to calculate AWS costs 1. AWS pricing calculator 1. https://calculator.aws/#/ 2. Cost estimates for the following examples: 1. https://tinyurl.com/yk7v3wek Andrzej Dębski
  • 22. Assumptions 1. "Average" request time: 200 ms 2. Monthly costs 3. Region: us-east-1 4. Focus on compute cost, ignore everything else Andrzej Dębski
  • 23. Scenarios considered 1. "Hello world": on-demand vs provisioned capacity 2. Smallest Fargate vs Lambda 3. StackExchange on Lambda vs Fargate Andrzej Dębski
  • 24. "Hello world", 1 request per second Andrzej Dębski 256 MB RAM On demand Provisioned capacity of 1 0.33 $ 4.55 $
  • 25. Fargate, 1 request per second Andrzej Dębski 1769 MB RAM 1vCPU 2GB RAM On demand Provisioned capacity of 1 Fargate 8.8 $ 28.28 $ 36.04 $
  • 26.
  • 27. Simulating Stack Exchange 1. https://stackexchange.com/performance 1. 1.3* 10^9 monthly page views means ~495 requests per second 2. For Fargate we assume 9 tasks to protect from AZ outage, 82.5 RPS per task. 3. For Lambda provisioned concurrency try to handle every request with prov capacity. 1. 495 (RPS) / 5 (requests per second per container) = 99 Andrzej Dębski
  • 28. SE, 495 requests per second Andrzej Dębski 1769 MB RAM 1vCPU 2GB RAM On demand Provisioned capacity of 99 Fargate, 9 tasks 7,744.27 $ 6,502.63 $ 324.36 $
  • 29.
  • 30. Recap 1. Free-tier 2. Use the AWS Pricing Calculator 3. With more traffic Lambda gets really costly 4. Take advantage of the "free" compute during init phase for on-demand lambdas 5. For consistent workloads provisioned concurrency may be cheaper 6. Always consider factors other than $$$ when evaluating technologies Andrzej Dębski
  • 33.
  • 34.
  • 35.
  • 36. Caching in Lambda – challenges 1. No hard guarantees when the container will be recycled 2. Best effort async updates 3. No control over the routing algorithm (no sticky sessions) Andrzej Dębski
  • 37. Caching in Lambda – approaches 1. (Mostly) rely on out of process cache 2. Use different compute platform if L1 cache is critical 3. Use Lambda extensions 1.That's how AWS AppConfig does it Andrzej Dębski
  • 38. Caching in Lambda – extensions 1. Code that can execute alongside your Lambda 2. Extension continues to execute AFTER the Lambda handler returned a response. 3. Implementing cache in extension 1.Save the data on Lambda FS 2.Expose local HTTP server and serve the data Andrzej Dębski
  • 40. Extensions for caching 1. (+) "Asynchronous" cache updates 2. (-) Overhead (in ms): 1.Avg (no ext/ext): 1.88 ms/14.1 ms 2.Tm99.9 (no ext/ext): 1.88 ms/14.2 ms 3. (-) Lambda instance can't handle new requests until extension is done 4. (-) Extension instances are not shared between containers Andrzej Dębski
  • 41. Recap 1. In memory caching in Lambda is not straightforward 1. Small window of time where the cache is "warm" 2. Asynchronous updates are best effort only 2. Extensions improve the situation but have their own downsides 1. Runtime overhead 2. Complicate the flow 3. L2 cache or different compute platform Andrzej Dębski