INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

Topic lessonTopic: Designing event-driven processing

Lambda execution environments: initialization, reuse, and concurrency

Lambda Event Functions run in execution environments that can serve later invocations once they are free. Follow an image-processing example to see what can be reused and how slower requests change the number of invocations running at once.

What you will learn

Distinguish initialization from handler execution, identify data that needs durable storage, and estimate average concurrency from arrival rate and mean execution time.

Prerequisite

A Lambda handler receives an event. This lesson covers standard on-demand Event Functions and uses fictional requests and load.

An initialized environment can serve another invocation

During initialization, Lambda starts the runtime and runs code outside the handler, among other tasks. The handler then processes each invocation. Reused environments may retain initialized objects. An environment can be shut down or reset.

Fictional requests A and B overlap, then C arrives
Fictional requests A and B overlap, then C arrives1: Image requests — Handles A — Environment 1. 2: Image requests — Handles overlapping request B separately — Environment 2. 3: Environment 1 — This example reuses the free environment for C — C arrives after A123Image requestsEnvironment 1Environment 2C arrives after AFictional requests A and B overlap, then C arrives1: Image requests — Handles A — Environment 1. 2: Image requests — Handles overlapping request B separately — Environment 2. 3: Environment 1 — This example reuses the free environment for C — C arrives after A123Image requestsEnvironment 1Environment 2C arrives afterA
  1. Image requests → Environment 1Handles A
  2. Image requests → Environment 2Handles overlapping request B separately
  3. Environment 1 → C arrives after AThis example reuses the free environment for C
Image requests
B arrives while A is running
Environment 1
Initializes and handles A
Environment 2
Handles B separately
C arrives after A
May reuse environment 1

Initialization can add latency when a new environment is needed. Compare first-use and reused environments with comparable inputs and memory settings. Also look for differences in time spent waiting on dependencies.

Keep durable results outside the execution environment

Three kinds of state in the image-processing example
ItemExample placementOn invocation
Image library or clientInitialize outside the handlerCheck whether you can reuse it and reconnect if needed.
Shared settings that can be rebuiltCache in /tmpReload from the original source on a cache miss.
Committed result for a request IDDurable storageKeep it accessible from another execution environment.

Memory and /tmp belong to a single environment. Data from a previous invocation can persist when the environment is reused. Scope variables and temporary files so request-specific state cannot leak into another invocation.

Longer processing raises concurrency even at a steady arrival rate

When arrival and completion rates are stable, average concurrency is approximately the number of invocations per second multiplied by mean execution time in seconds. In this example there is one invocation per request. At 40 per second and a mean of 0.25 seconds, average concurrency is about 10. At 0.75 seconds it rises to about 30.

Estimate the effect of changing rate or execution time
SituationInvocations per secondMean execution time (seconds)Estimated average concurrency
Typical400.2510
Slow storage response400.7530
Typical duration, higher arrival rate800.2520

Decide what the execution environment can tell you

Choose an option to see the result and explanation.

B starts while A is still processing. How can standard Event Functions handle that overlap?
Read the answer and reason

Answer: Run B in a different environment · Overlapping invocations run in separate execution environments.

C’s environment has no cached conversion settings. How should the handler respond?
Read the answer and reason

Answer: Reload the settings from the original source · Keep a way to rebuild the cache from the original settings.

The rate stays at 40 per second. Mean execution time grows from 0.25 to 0.75 seconds. What is the average concurrency estimate?
Read the answer and reason

Answer: About 30 · Multiply 40 by 0.75 to get 30.

A different environment gets the same request ID. Where should it look for a committed result?
Read the answer and reason

Answer: Durable storage keyed by request ID · Use durable storage that all relevant environments can consult.

Check, then explain in your own words

  1. Trace initialization, overlapping requests A and B, and possible reuse for request C.
  2. Separate state that can be rebuilt from evidence that work committed.
  3. Estimate concurrency when execution time increases while arrivals stay steady.
Check your understanding: Request volume is steady but concurrency rose. What do you compare first?

Compare the invocation rate and execution time over the same observation window.

Each longer invocation keeps its environment busy for more time. Check initialization, handler work, and dependency latency separately.

Sources and conditions checked

The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.