Lesson 5 of 5 ML Infrastructure and Containers

Choosing Auto Scaling Metrics for Endpoints

This lesson explains how SageMaker AI endpoints scale with Application Auto Scaling, and how choosing the right metric decides whether an endpoint keeps up with demand or wastes money.

Learning outcomes

After completing this lesson, you will be able to:

  • Configure scaling policies for variants and inference components.
  • Choose metrics for synchronous endpoints.
  • Scale asynchronous endpoints on backlog.
  • Tune targets, limits and cooldowns.

Scaling policies

Endpoint scaling uses Application Auto Scaling. A production variant or inference component is registered as a scalable target with minimum and maximum capacity. Target tracking keeps a metric near a target value, adding or removing capacity automatically, and is the default choice. Step scaling adds set amounts of capacity at alarm thresholds, for faster or more aggressive reactions to bursts.

Scheduled scaling changes capacity at known times, such as before business hours. Cooldown periods prevent rapid flapping between scaling out and scaling in, which would waste money and disrupt traffic.

Metrics for synchronous endpoints

SageMakerVariantInvocationsPerInstance (requests per minute per instance) is the standard metric for most models; the target comes from load testing, such as the rate at which latency starts to rise, with a safety margin. ConcurrentRequestsPerModel and ConcurrentRequestsPerCopy, available as high-resolution metrics, suit LLMs and other models whose request durations vary widely. CPUUtilization, MemoryUtilization, GPUUtilization and GPUMemoryUtilization suit compute-bound or memory-bound models.

The following diagram shows how a scaling target is chosen from a load test, against the measured limit of one instance, together with the endpoint's other scaling settings.

Choosing the scaling target from a load test. One ml.c6i.xlarge instance serves 900 requests per minute before p99 latency exceeds 100 ms, so target tracking aims at 630, 70% of the limit, leaving headroom while new instances start. Capacity runs from 2 to 12 instances; scale-out reacts after 60 seconds and scale-in waits 300.
The scenario is illustrative.
Fill in the value

Set the target

Exam skills 3.2.6

Calculate a target for invocations per instance.

Log in to try this activity Interactive activities are free with an account.

Metrics for asynchronous endpoints

Asynchronous endpoints queue requests, so they scale on the size of the queue rather than on request rate: target tracking on ApproximateBacklogSizePerInstance keeps the backlog per instance near a target. Asynchronous endpoints can also scale to zero instances when the queue is empty, which saves cost for intermittent work.

Scaling up from zero needs a separate trigger, because a target tracking policy has no instances to measure. A step scaling policy on the HasBacklogWithoutCapacity metric adds the first instance as soon as requests arrive. The following table summarises the metric choices.

WorkloadMetric
Typical real-time model with similar request durationsSageMakerVariantInvocationsPerInstance
LLMs, variable-duration requestsConcurrentRequestsPerModel (high resolution)
Compute-bound modelCPUUtilization or GPUUtilization
Asynchronous endpointApproximateBacklogSizePerInstance
Asynchronous endpoint scaling from zeroHasBacklogWithoutCapacity (step scaling)
Known daily peaksScheduled scaling plus target tracking

Tuning scaling behaviour

Choosing the metric is only half of the configuration; the target value, capacity limits and cooldowns decide how the endpoint behaves under real traffic. The target value should come from a load test and sit below the measured limit, often at about 70% of it, because new instances take several minutes to start and the existing ones must absorb growth in the meantime. A target at the limit breaches latency every time traffic rises quickly.

The minimum capacity sets the floor. For production real-time endpoints, at least two instances keep the endpoint available across Availability Zones, and a higher floor during known busy periods, set with scheduled actions, covers predictable spikes. The maximum capacity caps cost and must fit within the account's service quotas for the instance type.

Cooldowns balance responsiveness against stability. A short scale-out cooldown lets capacity grow quickly during a surge. A longer scale-in cooldown prevents flapping, where capacity is removed during a brief lull and has to be added back minutes later, which causes latency spikes while the new instances start. Target tracking also scales in more cautiously than it scales out by design. Monitoring the policy's activity history and the endpoint's latency after deployment shows whether the settings need adjustment.

Troubleshooting scenario

Scaling that misbehaves

Exam skills 3.2.6

Fix the auto scaling problems of an endpoint, one at a time.

Log in to try this activity Interactive activities are free with an account.
Worked example

Setting a target

Load testing with SageMaker Inference Recommender shows one ml.c6i.xlarge instance serves 900 requests per minute before p99 latency exceeds the 100 ms target.

aws application-autoscaling register-scalable-target --service-namespace sagemaker \
  --resource-id endpoint/churn/variant/AllTraffic \
  --scalable-dimension sagemaker:variant:DesiredInstanceCount --min-capacity 2 --max-capacity 12
aws application-autoscaling put-scaling-policy --policy-name inv-target --service-namespace sagemaker \
  --resource-id endpoint/churn/variant/AllTraffic \
  --scalable-dimension sagemaker:variant:DesiredInstanceCount --policy-type TargetTrackingScaling \
  --target-tracking-scaling-policy-configuration '{"TargetValue": 630,
    "PredefinedMetricSpecification": {"PredefinedMetricType": "SageMakerVariantInvocationsPerInstance"},
    "ScaleInCooldown": 300, "ScaleOutCooldown": 60}'

A target of 630 (70% of the measured 900) leaves headroom for bursts while new instances start. A minimum of two instances keeps the endpoint available across Availability Zones. A shorter scale-out cooldown than scale-in cooldown lets the endpoint grow quickly and shrink cautiously.

Check yourself

Which metric lets an asynchronous endpoint scale up from zero?

Show answer

HasBacklogWithoutCapacity.

Exam Tips

Remember for the exam

  • Default metric: SageMakerVariantInvocationsPerInstance with target tracking.
  • LLMs and variable request durations: ConcurrentRequestsPerModel.
  • Asynchronous endpoints: ApproximateBacklogSizePerInstance; from zero: HasBacklogWithoutCapacity.
  • Set targets from load tests with headroom.
  • Scale out quickly, scale in slowly.