Help Center/ FunctionGraph/ User Guide/ Configuring Functions/ Configuring Snapshot-based Cold Start
Updated on 2024-11-12 GMT+08:00

Configuring Snapshot-based Cold Start

Introduction

Huawei Cloud's snapshot-based cold start solution is a performance optimization service. It is free of charge and requires only simple configurations and a few code changes.

After cold start acceleration is enabled for a Java function, FunctionGraph executes the initialization code of the function, captures a snapshot of the context, and caches the snapshot after encryption. When the function scales with cold start, it restores the execution environment from the snapshot instead of repeating the initialization process, significantly increasing the startup speed.

Constraints

  • Only Java functions are supported.
  • For functions that strongly depend on states, consider using Restore Hook to refresh their states.
  • For functions that strongly depend on CPU instruction sets, contact customer service.
  • When functions that depend on hard-coded host environment variables (such as hostname and hostip) are migrated to other hosts, problems may occur. Do not use such variables if possible. Contact customer service.
  • Currently, only applications developed using x86 machines are supported.

This feature is supported only in TR-Istanbul.

Prerequisites

  • A Java function has been created.

Procedure

  1. Log in to the FunctionGraph console, configure a Java function, and enable Cold Start with Snapshot.
    Figure 1 Enabling Snapshot-based Cold Start
  2. (Optional) Configure Restore Hook and implement the hook logic in the function code.
    Figure 2 Enabling Restore Hook

    The following is an example of Restore Hook.

  3. Publish a new version to trigger snapshot creation.
    Figure 3 Publishing a new version
  4. Wait until the snapshot is created (about 5 minutes).
    Figure 4 Creating snapshot...
    Figure 5 Snapshot created
  5. Invoke the Java function to enjoy higher performance.