PHYSICAL SERVERHYPERVISORYOUR VM2 vCPU · 4 GiBANOTHER VMsomeone elseSERVERLESS PLATFORMINSTANCE 1INSTANCE 2INSTANCE 3USERSTIME COUNTEDVM SWITCHED ON0 sFUNCTION RAN0 s1def handler(event, context):2 name = event["name"]3 return "Hello, " + name
Left: a physical server, its hypervisor and two VMsRight: the serverless platform; violet blocks are running instancesEnvelopes: requests from the users (and one reply)Two ways to rent compute. Left: a hypervisor splits one physical server into virtual machines; your VM is always on and billed for every second, busy or idle. Right: serverless runs only your function. The first request starts an instance (a cold start), more requests at once start more instances (scaling out), and when the requests stop the instances go away (scale to zero). The meters count seconds for the same four requests: the VM was switched on (and billed) for 3600; the function ran for 0.48, and its three cold starts are billed on top. Counted seconds are not dollars: a second of function time usually costs more than a second of a small VM, so steady, busy traffic can be cheaper on VMs. The meters show time counted, not the bill: the VM is billed for every second it is on, while the function meter shows run time only and leaves out the billed cold-start time.

Virtual machines

  1. Compute means processing power: a CPU and memory that run your code. In the cloud that power sits in physical servers in a provider's data centre. You never touch the machine; you rent a slice of it.

Serverless functions

Choosing

What happens

;; step 1/10 · server
compute = CPU + memory that run your code

cloud: real servers in a data centre
you rent a slice, on demand
the provider owns and fixes the hardware

Counted seconds are not dollars: a second of function time usually costs more than a second of a small VM, so steady, busy traffic can be cheaper on VMs. The meters show time counted, not the bill: the VM is billed for every second it is on, while the function meter shows run time only and leaves out the billed cold-start time. The 0.12 s run time is an assumed example, not a measurement. Real run times depend on the code and the memory setting.