This topic describes the background, scenarios, limits, and instructions of configuring the maximum number of pay-as-you-go instances, and how to calculate transactions per second (TPS).

Background

To prevent unexpected calls from generating unnecessary charges, you can configure the maximum number of pay-as-you-go instances in each region under your account. This limit applies to all functions. For example, the account 123456789 can have up to 300 pay-as-you-go instances in a region. The account has three functions: function-a, function-b, and function-c. In this case, the maximum number of pay-as-you-go instances that concurrently process requests is 300.

Function Compute also allows you to specify the maximum number of pay-as-you-go instances for a single function in the console or by calling API operations. This feature can prevent a large number of instances being occupied by a single function due to excessive calls, protecting backend resources and avoiding unexpected charges. For example, the account 123456789 has three functions: function-a, function-b, and function-c. You can specify a maximum of 10 pay-as-you-go instances for function-a. Then a maximum of 10 instances are used to process requests when you call 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 under an account, and function-a is a key business function. If function-b is excessively called, normal requests of function-a may be affected. In this case, you can specify the maximum number of pay-as-you-go instances for function-b to prevent it from overconsuming instances.

  • Protect downstream services.

    For example, if Function Compute makes a large number of access requests to ApsaraDB for RDS (RDS), you can specify the maximum number of pay-as-you-go instances for functions that access RDS. In this way, RDS stops responding requests that exceed its processing capacity.

  • Terminate calls to a function.

    If calls to a function are abnormal, you can terminate calls to the function by specifying the maximum number of pay-as-you-go instances for the function to 0.

  • Prevent unexpected calls from causing excessive costs.

    You can specify the maximum number of pay-as-you-go instances for a function to prevent unexpected calls caused by the browser or client.

  • Use with reserved instances.

    You can configure the maximum number of pay-as-you-go instances and reserved instances and use one or both types of instances as needed.

Request processing methods after setting the pay-as-you-go instance limit

Type Request processing method
Synchronous call When the required number of pay-as-you-go instances exceeds the specified limit, the exceeded requests are denied and the ResourceExhausted error is reported.
Asynchronous call When the number of required pay-as-you-go instances exceeds the specified limit, the requests are not denied but are queued up and processed in full load mode.

For more information, see Call the function.

Use pay-as-you-go and reserved instances in combination

If your function has reserved instances, the reserved instances are used first. When all reserved instances are processing requests, new requests are processed by pay-as-you-go instances. The following table shows how to use pay-as-you-go instances and reserved instances in combination.

Pay-as-you-go instance limit Reserved instance limit Instance usage
0 10 Only the 10 reserved instances can be used.

When reserved instances are insufficient to process concurrent requests, new requests are throttled and error 429 is returned.

20 0 Up to 20 pay-as-you-go instances are used, and no reserved instances can be used.
50 30 Up to 50 pay-as-you-go instances can be used after all 30 reserved instances are used. You can use a maximum of 80 instances.

Limits

  • You can configure up to 100 instance limit rules for functions under 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 specified 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 in one second. You can configure the maximum number of pay-as-you-go instances based on TPS and your business requirements.

TPS calculation formula: TPS = 1/DurationInSecond × InstanceConcurrency × MaxInstances

Assume that it takes 0.1 second to process a request (DurationInSecond = 0.1s), and the function contains 5 instances (MaxInstances = 5). 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).

References

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