Upgrade to Pro — share decks privately, control downloads, hide ads and more …

7 ways to solve Lambda cold starts

Yan Cui
April 30, 2024

7 ways to solve Lambda cold starts

Cold starts can significantly affect your application's user experience. They occur when the AWS Lambda service needs to spin up a new execution environment before handling a new request. Initializing a new execution environment adds to the overall latency of the Lambda invocation. AWS has continuously improved the cold start performance of Lambda, including the introduction of proactive initialization. But cold starts are still a problem in many applications.

Join Yan Cui, AWS Serverless Hero, to learn more about common mistakes leading to cold-start performance issues and guide you through practical steps to enhance performance. This webinar is for developers interested in improving the efficiency and responsiveness of their serverless applications.

This webinar will teach you how to tackle cold starts by reducing their frequency and duration, including how to measure cold start durations correctly.

Yan Cui

April 30, 2024
Tweet

More Decks by Yan Cui

Other Decks in Technology

Transcript

  1. AWS region Invoke frontend load balancer availability zone 1 availability

    zone 2 availability zone 3 cold start invoke Synchronous
  2. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service cold start invoke Invoke Synchronous
  3. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service cold start invoke Invoke Synchronous
  4. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service cold start invoke Invoke Synchronous
  5. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker cold start invoke worker worker Invoke Synchronous
  6. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker cold start invoke worker worker Invoke Synchronous
  7. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Synchronous
  8. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Synchronous
  9. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Init Invoke Synchronous
  10. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous
  11. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker worker worker cold start invoke Invoke Invoke Synchronous
  12. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous
  13. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous Find space in worker fl eet
  14. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous Find space in worker fl eet Create Firecracker microVM
  15. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous Find space in worker fl eet Create Firecracker microVM Fetch env vars
  16. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous Find space in worker fl eet Create Firecracker microVM Fetch env vars Decrypt env vars
  17. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous Find space in worker fl eet Create Firecracker microVM Fetch env vars Decrypt env vars Initialise runtime
  18. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous Find space in worker fl eet Create Firecracker microVM Fetch env vars Decrypt env vars Initialise runtime Initialise function module
  19. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Invoke Init Invoke Synchronous Find space in worker fl eet Create Firecracker microVM Fetch env vars Decrypt env vars Initialise runtime Initialise function module “InitDuration”
  20. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime
  21. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Initialise function module
  22. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Initialise function module handler function
  23. Find space in worker fl Create Firecracker microVM Fetch env

    vars Decrypt env vars Initialise runtime Initialise function module handler function “InitDuration”
  24. Find space in worker fl Create Firecracker microVM Fetch env

    vars Decrypt env vars Initialise runtime Initialise function module handler function “InitDuration” “Duration”
  25. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Initialise function module handler function User experiences all this
  26. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Init Invoke Synchronous
  27. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Init Invoke Synchronous
  28. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Init Invoke Synchronous
  29. AWS region frontend load balancer availability zone 1 availability zone

    2 availability zone 3 frontend invoke service counting service assignment service worker worker placement service cold start invoke worker worker Init Invoke Synchronous Invoke
  30. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Initialise function module handler function
  31. Not a scalable solution But not everything runs at scale

    ¯\_(ツ)_/¯ And everyone (should) cares about cost
  32. use Provisioned Concurrency when: - optimization alone can’t help you

    reach performance target - cold starts would likely stack - tra ffi c is spiky
  33. Find space in worker fl Create Firecracker microVM Fetch env

    vars Decrypt env vars Initialise runtime Initialise function module handler function
  34. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Initialise function module handler function
  35. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Initialise function module handler function
  36. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Take snapshot of memory and disk
  37. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Take snapshot of memory and disk Cache it
  38. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Take snapshot of memory and disk Cache it Deploy time
  39. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Take snapshot of memory and disk Cache it Deploy time Create new environment from cache Runtime
  40. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Initialise function module handler function
  41. Divide fi lesystem into 512KB chunks Encrypt each chunk Cache

    the chunks and share across all customers Serialize container layers onto fi lesystem
  42. Divide fi lesystem into 512KB chunks Encrypt each chunk Cache

    the chunks and share across all customers Serialize container layers onto fi lesystem Many customers have the same dependencies
  43. Multi-tier caching L1: on the worker L2: distributed in AZ

    L3: backing store 67% of chunks are served from on-worker cache!
  44. Application Runtime OS Virtualisation Server Storage Network Application Runtime OS

    Virtualisation Server Storage Network You manage Platform manages Container Image Managed Runtime
  45. Find space in worker fl eet Create Firecracker microVM Fetch

    env vars Decrypt env vars Initialise runtime Initialise function module handler function
  46. 1. Lambda Warmers 2. Provisioned Concurrency 3. Trim your dependencies

    4. AOT compilation 5. SnapStart 6. Package Lambda as container images 7. Prefer light-weight runtimes