Skip to content

How to model serverless / per-invocation workloads

Model a serverless invocation as a Job on a Server with Server.server_type set to serverless.

What "serverless" changes

The server type controls how provisioned instances are counted:

  • autoscaling rounds hourly demand up to whole instances, so a partially loaded instance still contributes its provisioned footprint;
  • serverless attributes fractional instance-hours to the work performed;
  • on-premise holds a fixed fleet sized to peak demand over the whole period.

Describe each invocation's Job.compute_needed, Job.ram_needed, Job.request_duration and data needs on the job. Selecting serverless does not estimate those resources for you.

Python sketch

function_server = Server.from_defaults(
    "Image-resize function",
    server_type=ServerTypes.serverless(),
    storage=Storage.ssd("Function storage"),
)

resize_image = Job.from_defaults(
    "Resize uploaded image",
    server=function_server,
    request_duration=SourceValue(120 * u.ms),
    compute_needed=SourceValue(0.5 * u.cpu_core),
    ram_needed=SourceValue(256 * u.MB_ram),
    data_transferred=SourceValue(800 * u.kB),
    data_stored=SourceValue(0 * u.kB),
)

Add resize_image to the UsageJourneyStep that triggers it (see server_to_server_interaction). Instance counts then follow hourly demand fractionally.

Granularity

Start with one Job per kind of invocation and refine the largest contributors (methodology). An hour without traffic contributes no instance-hours for a serverless server. An on-premise fleet keeps its provisioned footprint while idle.