Snapshot-based Cold Start
Overview
The snapshot-based cold start solution is a performance optimization service. It requires only simple configurations and a few code changes.
After snapshot-based cold start 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. For subsequent invocations, it restores the execution environment from the snapshot instead of repeating the initialization process, significantly increasing the startup speed.
Notes and Constraints
- Only Java functions support snapshot-based cold start.
- 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 by submitting a service ticket to determine whether snapshot-based cold start is supported.
- When functions that depend on the hard-coded host environment (such as hostname or hostip) are migrated to other hosts, snapshot-based cold start may fail. Contact customer service for confirmation. Do not use such variables if possible.
- Currently, snapshot-based cold start supports only applications developed using x86 machines.
Configuring Snapshot-based Cold Start
- Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
- Click the name of a function. Choose Configuration > Advanced Settings.
- Enable Cold Start with Snapshot.
Figure 1 Enabling Snapshot-based Cold Start
- (Optional) If the function strongly depends on state, configure Restore Hook to update the state and implement the corresponding hook logic in the function code.
- Hook Timeout (s): timeout interval for executing the hook handler.
- Hook Handler: Enter the hook handler in the format of [Package name].[Class name].[Execution function name]. The value can contain a maximum of 128 characters.
Figure 2 Enabling Restore HookThe following is an example of Restore Hook.
- Click Save.
- Publish a function version by referring to Publishing a Version. Enable Cold Start with Snapshot to trigger snapshot creation.
Figure 3 Publishing a new version
- Wait until the snapshot is created (timeout: 5 minutes).
Figure 4 Creating snapshot...Figure 5 Snapshot created
- Invoke the Java function with snapshot cold start enabled and view the snapshot cold start information in the execution log, as shown in Figure 6.
Helpful Links
- Manage the function lifecycle using APIs. For details, see Function Lifecycle Management APIs.
- For details about how to optimize cold starts, see FunctionGraph Cold Start Optimization.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot