This topic describes invocation methods, concurrency, limits, and retry mechanism for functions.
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 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. For more information about asynchronous invocation, see Manage asynchronous invocation configuration.
- When you use the fcli tool or an SDK to invoke a function, you can specify whether to use synchronous or asynchronous invocation.
- The limits on inbound events are different for synchronous and asynchronous invocation. For more information, see Limits on resource usage.
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:
- The request rate is the number of requests or events per second for a function.
- The function duration is the time period for which a function is executed, in seconds.
For example, assume that you have a function that processes OSS events. The average duration for the function is 3 seconds, and 10 OSS events are generated each second. By using the formula, you can determine that the execution concurrency for your function is 30.
If functions are configured incorrectly, unexpected results may occur during function execution. For example, assume that you have set an OSS trigger that invokes an image processing function when an image file is uploaded to an OSS bucket. If this function writes the processed files back to the same bucket, the function will continuously invoke itself, resulting in an infinite loop.
To prevent such an infinite loop from causing financial losses, Function Compute limits execution concurrency to 100 per account. In theCloud Monitor console, you can check the throttles metric to see whether such behavior has occurred. To increase the execution concurrency limit,submit a ticket.
If a function fails, the invocation method determines whether Function Compute automatically retries the function:
- Synchronous invocation: Function Compute does not automatically retry a failed function. You can manually invoke the function again.
- Asynchronous invocation: In the following situations, Function Compute automatically
retries the function.
Cause of failure Status code Server behavior Billable An error of the HandledError or UnhandledError type occurs. For more information, see Handle errors. 200 Function Compute retries the function three times by default. You can change this setting as needed. Billed by 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, Contact us.