All Products
Search
Document Center

Function Compute (2.0):Instance-level events

Last Updated:Jan 03, 2024

Function Compute provides instance-level events. You can use instance-level events to understand lifecycles of function instances, including the process of creating and destroying instances, and the points in time at which each step occurs. This topic describes the lifecycle of a function instance and the definition, change process, types, and query methods of instance-level events.

Lifecycle of a function instance

Function instances are dynamically created and destroyed based on the number of invocations. The lifecycle of each function instance includes Creating, Running, and Destroying phases. The following figure shows the lifecycle of a function instance.

image

Creating

Function Compute creates instances based on function configurations. The Creating phase involves code or layer loading (or image pulling), instance startup, and Initializer hook running. The following figure shows how Function Compute creates an instance.

image

Instances are created in the following scenarios:

  • Auto scaling: If the existing instances are fully loaded and cannot process new requests, Function Compute creates one or more instances. In this case, cold starts occur. For more information, see Best practice for reducing cold start latencies.

  • Adjustment of provisioned configurations: If you specify a specific number of provisioned instances in the auto scaling rule of a function, Function Compute creates provisioned instances before requests are submitted to help prevent cold starts of instances. For more information, see Configure provisioned instances and auto scaling rules.

Running

Function Compute invokes the handler of your function to process requests. You can configure the instance concurrency of a function to modify the policy for processing requests. You can also use the PreFreeze hook to extend the programming model. For more information, see Extensions. For more information about instance concurrency, see Configure instance concurrency.

You are charged only when instances process requests and execute hooks. If the instances no longer process requests, the instances are frozen.

Destroying

In this phase, instances are destroyed. You can use the PreStop hook to extend the programming model.

Instances are destroyed in the following scenarios:

  • Idle instances: If an on-demand instance does not receive requests for a specific period of time, Function Compute automatically reclaims the instance.

  • Adjustment of provisioned configurations: If you reduce the number of provisioned instances in an auto scaling rule of a function, Function Compute destroys excess provisioned instances.

  • Instance exception: If the instances encounter exceptions during the Creating or Running phase, Function Compute destroys the instances.

What are instance-level events?

An event is a data record that describes a change in the status of a resource. Instances are core resources that are allocated by Function Compute to execute requests. Function Compute dynamically creates and destroys instances to process your requests. In Function Compute, an event describes a key change in the status of an instance. You can view the events of an instance on the instance details page. Instance-level events allow you to observe the lifecycle of an instance and identify execution exceptions.

States and change processes of events

Events mark the points in time at which the status of resources change. Each event is associated with at least one definable pre-state and post-state.

The following figure shows the status changes of a function instance and related events.

image

The following items describe the states. For more information about status change events, see Event types.

  • Creating: The instance is being created. Function Compute dynamically creates instances based on the number of requests for the function. This state contains the following child states.

    • ImagePulling: Your image is being pulled. This state applies to a Custom Container runtime.

    • CodePreparing: Your code package is being pulled and mounted.

    • LayerPreparing: Your layer is being pulled and mounted.

    • RuntimeInitializing: Your instance is being started and under health check.

    • Initializing: The Initializer hook of the function is being executed.

    • Finished: Your instance is created.

    • Failed: Failed to create the instance.

  • Running: Your instance is running. The instance can process requests when the instance is in this state.

  • Destroyed: Your instance is destroyed. The instance is dynamically destroyed based on the number of requests that are sent to the function.

  • Error: Your instance cannot process requests as expected and is about to be destroyed.

Event types

Event

Severity

Description

Solution

Creating the instance

fc:Instance:Creating

Normal

Function Compute is creating instances to process requests.

N/A

The code is successfully loaded.

fc:Instance:PrepareCodeSuccess

Normal

Function Compute pulled your code package and mounted the package to the instance.

Note

Function Compute optimizes the loading processes of code packages. The loading process can be completed in a short period of time under specific conditions.

N/A

Failed to load code.

fc:Instance:PrepareCodeFailed

Warning

Function Compute failed to pull and mount your code package.

Join the DingTalk group (ID:11721331) for technical support.

The layer is successfully loaded.

fc:Instance:PrepareLayerSuccess

Normal

Function Compute pulled the layer and mounted the layer to the instance.

Note

Function Compute optimizes the loading processes of layers. The loading of layers can be completed in a short period of time under specific conditions and can be performed together with code loading.

N/A

Failed to load the layer.

fc:Instance:PrepareLayerFailed

Warning

Function Compute failed to pull and mount the layer.

Join the DingTalk group (ID:11721331) for technical support.

The image is successfully loaded.

fc:Instance:PullImageSuccess

Normal

Function Compute pulled the instance image of your Custom Container runtime.

N/A

Failed to load the image.

fc:Instance:PullImageFailed

Warning

Function Compute failed to pull the instance image of your custom container runtime.

Join the DingTalk group (ID:11721331) for technical support.

The instance is successfully started.

fc:Instance:RuntimeInitializationSuccess

Normal

Function Compute has launched your instance and completed the health check.

N/A

Failed to start the instance.

fc:Instance:RuntimeInitializationFailed

Warning

Function Compute detects that your instance failed the health check after the instance is started.

To resolve the issue, we recommend that you view the instance logs and use the error-handling methods for custom runtimes. For more information about how to troubleshoot custom runtime errors, see Error handling.

The Initializer hook is successfully executed.

fc:Instance:InitializationSuccess

Normal

The Initializer hook is successfully executed.

N/A

Failed to execute the Initializer hook.

fc:Instance:InitializationFailed

Warning

The Initializer hook failed to be executed.

We recommend that you adjust the logic of the Initializer hook based on the request logs.

The instance is successfully created.

fc:Instance:CreateSuccess

Normal

Your instance is created and is about to process requests.

N/A

Failed to create the instance.

fc:Instance:CreateFailed

Warning

Your instance failed to be created and will be destroyed.

N/A

The instance is destroyed.

fc:Instance:DestroySuccess

Normal

Your instance is destroyed.

N/A

Query instance-level events

After you enable instance-level metrics, Function Compute collects information about instance-level events. The information is sent to the Logstore that you selected when you configured the logging feature. The following section describes how to view information about instance-level events. For more information about how to enable instance-level metrics, see Configure instance-level metrics.

View instance-level events in the Function Compute console

  1. Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.

  2. In the top navigation bar, select a region. On the Services page, click the desired service.

  3. On the Functions page, click the name of the function that you want to manage. On the function details page, choose Logs > Requests.

    • View instance-level events in the Function Compute console

      Click the ID of the instance whose events you want to view. In the instance details panel, view the instance-level events.

      check-instance-event

    • View raw event logs in the Simple Log Service console

      Find the desired request and click Advanced Logs in the Actions column to go to the raw logs page in the Simple Log Service console. On this page, you can filter logs by topic name. The topic name is in the FCInstanceEvents:<your-service-name>/<your-function-name> format.

      check-instance-log