This topic describes the background information, scenarios, usage limits, and instructions for configuring the maximum number of on-demand function instances. This topic also describes how to calculate transactions per second (TPS).
To prevent unexpected charges caused by excessive invocations, you can set the maximum number of on-demand instances in each region within your Alibaba Cloud account. This limit applies to all the functions. For example, the account 164901546557**** can have up to 300 on-demand instances in a specific region. The account has three functions: function-a, function-b, and function-c. In this case, the maximum number of on-demand instances that concurrently process requests is 300.
Function Compute also allows you to set the maximum number of on-demand instances for a single function in the Function Compute console or by calling API operations. This prevents a large number of instances being occupied by a single function due to excessive invocations, protects backend resources, and prevents unexpected charges. For example, the account 164901546557**** has three functions: function-a, function-b, and function-c. You can set a maximum of 10 on-demand instances for function-a. In this case, a maximum of 10 instances can be used to process requests when you invoke function-a.
- Ensure the concurrency of functions.
For example, function-a and function-b share the maximum number of instances within an account, and function-a is a key business function. If function-b is excessively invoked, normal requests of function-a may be affected. In this case, you can set the maximum number of on-demand instances for function-b to prevent it from consuming excessive instances.
- Protect downstream services.
For example, if Function Compute makes a large number of access requests to ApsaraDB RDS, you can set the maximum number of on-demand instances for functions that are invoked to access ApsaraDB RDS. This way, ApsaraDB RDS stops responding requests that exceed its processing capacity.
- Terminate abnormal function invocations.
If invocations of a function are abnormal, you can terminate invocations of the function by setting the maximum number of on-demand instances for the function to 0.
- Prevent unexpected function invocations.
You can set the maximum number of on-demand instances for a function to prevent unexpected invocations caused by the browser or client.
- Use with provisioned instances.
You can set the maximum number of on-demand instances together with the number of provisioned instances for a function. This way, the function invocation requests can be processed only by provisioned instances, only by on-demand instances, or by a combination of provisioned and on-demand instances.
Request processing methods after setting the on-demand instance limit
|Type||Request processing method|
|Synchronous invocation||When the required number of on-demand instances exceeds the specified limit, the exceeded
requests are denied, and the
|Asynchronous invocation||When the number of required on-demand instances exceeds the specified limit, the requests are not denied but are queued up and processed in full load mode.|
For more information, see topics in Invoke Functions.
Use on-demand and provisioned instances in combination
If your function has provisioned instances, the provisioned instances are used first. If all the provisioned instances are processing requests, new requests are processed by on-demand instances. The following table describes how to use on-demand and provisioned instances in combination.
|On-demand instance limit||Provisioned instance limit||Instance usage|
|0||10||Up to 10 provisioned instances can be used, and no on-demand instances can be used.
When provisioned instances are insufficient to process concurrent requests, new requests are throttled and error 429 is returned.
|20||0||Up to 20 on-demand instances can be used, and no provisioned instances can be used.|
|50||30||Up to 50 on-demand instances can be used after all 30 provisioned instances are used. You can use a maximum of 80 instances.|
- You can configure up to 100 instance limit rules for functions within an account in each region. The maximum number of instances that is set in a rule cannot exceed 300. The limit of the account is 300.
- The instance limit rules for functions must be applied to aliases or the latest version of a function. You can set different limits for different aliases of a function.
TPS indicates the number of requests that a function can process per second. You can set the maximum number of on-demand instances based on TPS and your business requirements.
TPS calculation formula: TPS = 1/DurationInSecond × InstanceConcurrency × MaxInstances
In the following example, 0.1 seconds is taken to process a request, and a maximum of five instances can be used to execute the function. If an instance can concurrently process up to two requests (InstanceConcurrency = 2), the five instances can process 100 (1/0.1× 2 × 5) requests per second (TPS = 100).
For more information about how to manage on-demand instances, see Configure auto scaling instances (including provisioned instances).