Function Compute scales instances automatically to handle incoming traffic. Two modes are available — on-demand and provisioned — each with its own scaling behavior and limits. For provisioned instances, you can also configure scheduled scaling and threshold-based scaling to adjust capacity based on traffic patterns.
How instance scaling works
Function Compute always routes incoming requests to existing idle instances first. When all instances are busy, it creates new ones. Scaling continues until either the request load is absorbed or the instance count reaches the regional limit.
Two constraints govern scaling speed:
-
Maximum burstable instances — the maximum number of new instances that can be created in a single burst
-
Maximum instance growth rate — how quickly instances can be added over time, measured in instances per minute
Both limits apply equally to on-demand and provisioned instances within the same region.
On-demand instance scaling
When scaling speed or instance count exceeds the regional limit, Function Compute returns HTTP 429 to indicate throttling. The following figure shows the three phases during a traffic surge.
-
Phase 1 — Instances spin up immediately to absorb the surge. Cold starts occur, but no throttling — the burstable limit has not been reached yet.
-
Phase 2 — The burstable limit is reached. New instances are now constrained by the growth rate. Some requests are throttled.
-
Phase 3 — The total instance count hits the regional ceiling. Throttling continues for requests that cannot be served.
Provisioned instance scaling
Provisioned instances are pre-initialized and held in reserve before any invocation arrives. This eliminates cold starts for the reserved capacity and reduces the likelihood of throttling during traffic surges.
The following figure shows the same surge scenario with provisioned instances in place.
-
Phase 1 — All incoming requests are routed to provisioned instances. No cold starts, no throttling — until provisioned capacity is full.
-
Phase 2 — Provisioned instances are saturated. Function Compute starts creating on-demand instances to handle the overflow. Cold starts occur, but throttling is still avoided until the burstable limit is reached.
Scaling speed limits by region
|
Region |
Maximum burstable instances |
Maximum instance growth rate |
|
China (Hangzhou), China (Shanghai), China (Beijing), China (Zhangjiakou), and China (Shenzhen) |
300 |
300 per minute |
|
Other regions |
100 |
100 per minute |
-
The limits are shared across all functions in the same account within a region — on-demand and provisioned instances are counted together.
-
GPU-accelerated instances scale more slowly than CPU instances. Use provisioned mode to pre-allocate GPU-accelerated instances and avoid scaling delays.
To request faster scaling speeds, join the DingTalk group (group ID: 64970014484) for technical support.
Auto scaling for provisioned instances
Beyond a fixed provisioned instance count, you can configure automatic adjustments with scheduled scaling and threshold-based scaling. These policies help match capacity to actual traffic and improve instance utilization.
-
While an elastic policy is active, it overrides the initial Minimum Instances that you configured for the function. During periods when no elastic policy is in effect, the system falls back to the initially configured Minimum Instances.
-
If you configure multiple elastic policies, the system calculates the Minimum Instances that each policy would trigger, and uses the maximum value among the policies currently in effect as the actual Minimum Instances.
For more information, see How is the current minimum number of instances calculated?.
Scheduled scaling
Use scheduled scaling when traffic follows a predictable pattern — for example, peak hours during business hours or traffic spikes tied to specific events. When concurrent invocations exceed the scheduled capacity, the overflow is routed to on-demand instances.
Configure scheduled scaling
The following figure shows a typical scale-out/scale-in cycle around a traffic peak.
The following snippet configures two scheduled policies via the PutProvisionConfig API for a function named function_1. The time zone is Asia/Shanghai (UTC+8). During August 1–30, 2024, the provisioned instance count increases to 50 at 20:00 and drops back to 10 at 22:00 each day.
"scheduledActions": [
{
"name": "scale_up_action",
"startTime": "2024-08-01T10:00:00",
"endTime": "2024-08-30T10:00:00",
"target": 50,
"scheduleExpression": "cron(0 0 20 * * *)",
"timeZone": "Asia/Shanghai"
},
{
"name": "scale_down_action",
"startTime": "2024-08-01T10:00:00",
"endTime": "2024-08-30T10:00:00",
"target": 10,
"scheduleExpression": "cron(0 0 22 * * *)",
"timeZone": "Asia/Shanghai"
}
]
Schedule expression formats
Two formats are supported:
-
At expression —
at(yyyy-mm-ddThh:mm:ss): runs once at the specified date and time. For example,at(2024-04-01T20:00:00)withtimeZone: Asia/Shanghaifires at 20:00 on April 1, 2024 (UTC+8). -
Cron expression —
cron(0 0 4 * * *): runs on a recurring schedule in standard crontab format. For example,cron(0 0 20 * * *)withtimeZone: Asia/Shanghaifires at 20:00 every day (UTC+8).
Threshold-based scaling
Use threshold-based scaling when traffic is harder to predict. Function Compute periodically collects concurrency or resource utilization metrics from provisioned instances and adjusts the instance count to stay within the minCapacity–maxCapacity range you define.
Threshold-based scaling requires instance-level metrics collection to be enabled first. Without it, you will get a 400 InstanceMetricsRequired error. See Enable collection of instance-level metrics.
The ProvisionedConcurrencyUtilization metric tracks only provisioned instances — on-demand instance concurrency is excluded.
Concurrency utilization is the ratio of the number of concurrent requests currently handled by the Minimum Instances to the maximum number of concurrent requests that the Minimum Instances can support. The value ranges from 0 to 1.
Configure threshold-based scaling
The following figure illustrates how Function Compute scales out when the concurrency utilization threshold is exceeded and scales in when utilization drops.
The following snippet configures a threshold-based scaling policy via the PutProvisionConfig API for function_1. The time zone is Asia/Shanghai (UTC+8), and the policy is active from August 1, 2024 to August 30, 2024. The policy tracks the Provisioned concurrency utilization metric ProvisionedConcurrencyUtilization, with a target value of 60% for the Provisioned concurrency utilization. When the utilization exceeds 60%, scaling out starts, up to a maximum of 100 instances. When the utilization falls below 60%, scaling in starts, down to a minimum of 10 instances.
"targetTrackingPolicies": [
{
"name": "action_1",
"startTime": "2024-08-01T10:00:00",
"endTime": "2024-08-30T10:00:00",
"metricType": "ProvisionedConcurrencyUtilization",
"metricTarget": 0.6,
"minCapacity": 10,
"maxCapacity": 100,
"timeZone": "Asia/Shanghai"
}
]
Scaling calculations
Function Compute scales out aggressively and scales in gradually. The target instance count is the smallest integer greater than or equal to the calculated result.
-
Scale-out target = Current instances × (Current metric value /
metricTarget) -
Scale-in target = Current instances × Scale-in coefficient × (1 − Current metric value /
metricTarget)
The scale-in coefficient is a system parameter between 0 (exclusive) and 1 that slows down scale-in to prevent oscillation. It does not require manual configuration.
Example: If the current metric value is 80%, the configured Provisioned concurrency utilization target is 40%, and the current minimum number of instances is 100:
Scale-out target = 100 × (80% / 40%) = 200 instances
Function Compute increases the count to 200 (capped at maxCapacity) to bring utilization back to the 40% target.
How is the current minimum number of instances calculated?
The following example shows how the current minimum number of instances is determined jointly by the initially configured minimum number of instances and the target values set in scheduled scaling policies.
Configuration:
-
defaultTarget: 5 -
Two scheduled policies, time zone
Asia/Shanghai(UTC+8), active from January 9 to January 11, 2025-
Scale out to 20 at 10:00 each day
-
Scale in to 10 at 22:00 each day
-
{
"defaultTarget": 5,
"scheduledActions": [
{
"name": "scale_up_action",
"startTime": "2025-01-09T10:00:00",
"endTime": "2025-01-11T00:00:00",
"target": 20,
"scheduleExpression": "cron(0 0 10 * * *)",
"timeZone": "Asia/Shanghai"
},
{
"name": "scale_down_action",
"startTime": "2025-01-09T10:00:00",
"endTime": "2025-01-11T00:00:00",
"target": 10,
"scheduleExpression": "cron(0 0 22 * * *)",
"timeZone": "Asia/Shanghai"
}
]
}
The following figure shows how the provisioned instance count changes over time under this configuration.
Maximum concurrency
Maximum concurrency is the total number of concurrent requests that all provisioned instances can handle at once. It depends on the instance concurrency setting for your function.
-
Single-request instances (each instance handles one request at a time): Maximum concurrency = Number of instances
-
Multi-request instances (each instance handles multiple requests concurrently): Maximum concurrency = Number of instances × Instance concurrency
For details on configuring instance concurrency and its impact on scaling behavior, see Configure instance concurrency.
What's next
-
For basic concepts and billing details for on-demand and provisioned instances, see Instance types and usage modes.
-
To limit the maximum number of instances for a function, see Configure function quotas. After the configuration, when the total number of running instances of the function exceeds the limit, Function Compute returns a throttling error.
-
For details about how the current minimum number of instances is calculated, see How is the current minimum number of instances calculated?.