SlideShare a Scribd company logo
1 of 42
Download to read offline
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 DockerDmytro 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 2019Derek 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 2017Mike 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
 
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 PretoriaVadym 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 UKStorageOS
 
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 GroupMarakana 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-02Derek 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. KubernetesDmitry 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 FunctionsKp Krishnamoorthy
 
aws lambda & api gateway
aws lambda & api gatewayaws lambda & api gateway
aws lambda & api gatewayfumihiko 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 CassandraDemi Ben-Ari
 
Functional Programming in Serverless World
Functional Programming in Serverless WorldFunctional Programming in Serverless World
Functional Programming in Serverless WorldWojciech 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 SingaporeVadym 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

Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfOverkill Security
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهMohamed Sweelam
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistandanishmna97
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxjbellis
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiRaviKumarDaparthi
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdfMuhammad Subhan
 

Recently uploaded (20)

Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi Daparthi
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 

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