This topic describes the invocation methods, concurrency, limits, and retry mechanism for functions.

Invocation methods

You can invoke a function in the following ways:

  • Synchronous invocation: After an event is processed by a function, the result is directly returned. For example, invoking a function in the Function Compute console is a synchronous invocation.
  • Asynchronous invocation: After an event is added to the internal queue of Function Compute, the request ID is returned. Function Compute ensures that events in the queue are reliably processed later. For example, invoking a function by using an Object Storage Service (OSS) event trigger is an asynchronous invocation.
    Asynchronous invocations include the following two types:
    • Stateless asynchronous invocation: ensures that a function is executed at least once. In some special cases such as system hardware errors and system upgrades, a function may be executed multiple times to ensure that each message is processed.
      Note By default, stateless asynchronous invocation is enabled.
    • Stateful asynchronous invocation: saves status transition information during the invocation to improve the reliability of the invocation. Only hardware failures except for failures of function execution instances can interrupt the execution of a function or cause a function to be repeatedly executed.

    For more information about asynchronous invocations, see Manage asynchronous invocation configurations.

Figure 1. Relationship between synchronous invocations and asynchronous invocations
Relationship between synchronous invocations and asynchronous invocations
Note
  • When you use Function Compute Command Line Interface (fcli) or an SDK to invoke a function, you can specify whether to synchronously or asynchronously invoke the function.
  • The limits on inbound events are different for synchronous and asynchronous invocations. For more information, see Limits on resource usage.

Execution concurrency

Execution concurrency is the number of concurrent invocations of a function in a specified period of time. You can use the following formula to estimate the execution concurrency:

Execution concurrency = Request rate × Function execution duration
  • The request rate is the number of requests or events per second for a function.
  • The function execution duration is the time used to execute a function, in seconds.

For example, you have a function that processes OSS events. The average execution duration for the function is 3 seconds, and 10 OSS events are generated per second. You can use the formula to calculate that the execution concurrency for your function is 30.

Note Execution concurrency affects billing for your functions. For more information, see Billing.

Invocation limits

If functions are incorrectly configured, unexpected results may occur when the functions are executed. For example, you have configured an OSS event trigger that invokes an image processing function when an image file is uploaded to an OSS bucket. If this function writes the processed file back to the same bucket, the function continuously invokes itself, which results in an infinite loop.

To prevent such an infinite loop from causing financial losses, Function Compute limits execution concurrency to 100 per account. In the CloudMonitor console, you can use the throttles metric of functions to observe throttling behaviors. To increase the execution concurrency limit, submit a ticket.

Retry mechanism

If a function fails to be executed, its invocation method determines whether Function Compute automatically retries the function.

  • Synchronous invocation: Function Compute does not automatically retry a failed function. You can manually retry the function.
  • Asynchronous invocation: In the following situations, Function Compute automatically retries the function.
    Failure cause HTTP status code Server behavior Billable
    An error of the HandledInvocationError or UnhandledInvocationError type occurs. For more information, see Handle errors. 200 By default, Function Compute retries the function three times. You can change this setting as needed. Billed based on the number of invocations. For more information, see Billing.
    Execution concurrency exceeds the upper limit. 429 Function Compute retries the function for 5 hours in exponential backoff mode. No
    An internal system error occurs. 500 Function Compute retries the function for 5 hours in exponential backoff mode. No
    Function Compute resources are insufficient. 503 Function Compute retries the function for 5 hours in exponential backoff mode. No

If you encounter problems, you can contact Function Compute engineers.