All Products
Document Center

Invoking a function

Last Updated: Jun 19, 2019

Function Compute supports synchronous calls and asynchronous calls of functions.

  • Synchronous call: The result is directly returned after an event is processed by a function. For example, if you use the console to call a function, the call is synchronous.
  • Asynchronous call: The result is returned after an event is written to Message Queue. Function Compute ensures that the message is reliably processed. For example, function calls triggered by an OSS event or a timer are asynchronous.
  • When using the fcli tool or an SDK to call a function, you can specify whether to use synchronous or asynchronous calling.
  • Synchronous and asynchronous calls impose different limits on incoming events. For more information, see Limits.

Concurrent execution

Concurrent execution indicates the number of concurrent function calls in a specified period of time. You can use the following formula to estimate the number of concurrent function calls.

Request rate × Function execution time

Request rate indicates the rate at which a function is called, in Requests per second (RPS) or Events per second (EPS). Function execution time is the time taken to complete a function, in seconds. For example, a function is used to process Alibaba Cloud OSS events. The function execution time is 3 seconds and OSS generates 10 events per second. In this case, 30 concurrent function calls exist.

Security restrictions

In some cases, errors may occur during function execution due to incorrect settings. For example, you have set an OSS trigger. When image files are uploaded to the foo bucket in OSS, a function is called. This function duplicates the source image into three images with different resolutions, and writes the result to the foo bucket. As a result, new functions will be called, resulting in an infinite loop. To prevent financial losses due to infinite function calls, Function Compute limits the maximum number of concurrent function calls on each account to 100. You can use the throttles metric of functions in CloudMonitor to observe throttling behaviors. To increase the allowed maximum number of concurrent function calls, submit a ticket.

Retry mechanism

The retry mechanism for functions that fail to be executed varies depending on the function call type.

  • Synchronous call: The system does not process a synchronous call if the call fails. You can retry the function call.

  • Asynchronous call: If an asynchronous call fails due to any of the following reasons, Function Compute automatically re-executes the call.

Reason of function call failures Status code Server behavior Charges
HandledError or UnhandledError. For more information, see Error message. UnhandledError is reported when a function call times out. 200 Retry for a maximum of two times and return the traceback Billed by number of calls
Function call concurrency exceeds the upper limit 429 Retry for 5 hours in exponential backoff mode No
System internal error 500 Retry for 5 hours in exponential backoff mode No
Insufficient Function Compute resources 503 Retry for 5 hours in exponential backoff mode No

Contact Alibaba Cloud technical support personnel if you require any assistance.