Invoking a function

Invocation types

Function Compute supports synchronous and asynchronous invocation of a function.

Synchronous invocation: The event is processed by the function, and then the result is returned.

Asynchronous invocation: The event is queued in Message Queue, and then no result is returned. Function Compute will process event based on Message Queue At-Least-Once delivery guarantee.

Different limits apply for synchronous and asynchronous invocation. For more information, see Limits.

You can manually invoke your functions using the console or command line tool. For more information, see Relevant examples. You can also invoke your function calling the REST API. For more information, see API specification. SDKs of different languages are provided to further simplify your operations. The following is an example of calling the Java SDK:

Concurrent Execution

Concurrent Executions is the total concurrent function executions within a given time period. You can use the following formula to estimate the concurrent function execution number.

Request rate x Function execution time

The request rate is the function execution rate, with the unit of “Requests per second” or “Events per second”. The unit of Function execution time is “Second”. For example, given an OSS events processing function, assuming that the function execution time is 3s, and OSS generates 10 events per second. Therefore, your function has 30 concurrent executions.

Concurrent Execution Limits

In some cases, function execution may be out of control due to incorrect settings. For example, you have set an OSS trigger. When image files are uploaded to the foo bucket of OSS, the relevant function is called. This function adjusts the source image to three images with different resolutions and incorrectly writes the result back to the foo bucket. As a result, a new function is called, resulting in an infinite loop. To prevent financial loss caused by infinite function calls, Function Compute sets the maximum number of concurrent function executions (100 by default) for each account. You can check the throttles metrics of a function in CloudMonitor. To adjust the limit, open a ticket.

Throttling errors handling

Throttling errors are handled differently based on the different invocation type.

Synchronous invocation: It the function is invoked synchronously and is throttled, Function Compute retuens a 429 error and the invoking service is responsible for retries. For example, if you use API Gateway to invoke a function, please make sure that the response error of Function Compute is mapped to the error code of API Gateway. If you directly invoke the function through the SDK or CLI, you can decide whether to retry based on your requirement.

Asynchronous invocation: If your function is invoded asynchronously and is throttled, Function Compute automatically retries the throttled event for up to 5 hours, with exponential backoff. Asynchronous events are queued before they are used to invoke the function.