This topic describes the background information, scenarios, limits, and instructions of configuring the maximum number of on-demand instances. This topic also describes how to calculate transactions per second (TPS).

Background information

To prevent unexpected invocations from generating unnecessary charges, you can set the maximum number of on-demand instances in each region within your account. This limit applies to all functions. For example, the account 123456789 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 123456789 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.

Scenarios

  • Set a limit for a function to ensure the concurrency of another function.

    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 invocations of a function.

    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 invocations from generating unnecessary charges.

    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 and provisioned instances and use one or both types of instances as needed.

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 ResourceExhausted error is returned.
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 Overview.

Use on-demand and provisioned instances in combination

If your function has provisioned instances, the provisioned instances are used first. When all provisioned instances are processing requests, new requests are processed by on-demand instances. The following table describes how to use on-demand instances 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.

Limits

  • You can configure up to 100 instance limit rules for functions within an account in each region.
  • The instance limit rules for functions must be applied to aliases or the latest version of a function.
  • The maximum number of instances that is set in a rule cannot exceed the limit of the account, which is 300.
  • Different limits can be set for different aliases of the function.

Calculate TPS

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

Assume that 0.1 second is taken to process a request, and a maximum of five instances can be used to execute the function. If a single instance can concurrently process two requests, the number of requests that the five instances can process per second is calculated based on the following formula: 1/0.1 × 2 × 5 = 100. In this case, TPS = 100.

References

Configure the maximum number of pay-as-you-go instances