All Products
Search
Document Center

Function Compute (2.0):Accelerate startup of images for Container Registry Personal Edition

Last Updated:Aug 22, 2023

Compared with function code packages, container images provide better portability and you can benefit from a more diverse toolchain ecosystem. However, container images may contain bloatware. Bloatware causes the image size to exceed one gigabyte, and prolongs the cold start of a container image to several minutes. After image acceleration is enabled, the image startup speed is increased by about 90% from minutes to seconds. This topic describes the working mechanism of the image startup acceleration feature for Container Registry Personal Edition.

Principles

By default, Function Compute enables image startup acceleration for functions that run in Custom Container runtimes and use images of Alibaba Cloud Container Registry Personal Edition. Each time you create or update a function of this type, Function Compute assumes the role of the service, uses the temporary AccessKey pair to pull images, and then cache the images to the image cache service of Function Compute. After the image is cached, the image startup can be accelerated.

Usage notes

  • The image startup acceleration feature is supported in the following regions: China (Beijing), China (Zhangjiakou), China (Hangzhou), China (Shanghai), China (Shenzhen), China (Hong Kong), Singapore, US (Silicon Valley), US (Virginia), and Japan (Tokyo).

  • If you agree to use the image acceleration feature, you agree and authorize Function Compute to pull images from your repository and cache the images to the acceleration cache service of Function Compute. To ensure data security, Container Registry Personal Edition provides network isolation and identity authentication to help you implement access control and encrypt data. Make sure that the caching of images to the internal storage of Function Compute complies with the security specifications and guidelines of your institution.

  • After you create or update a function that uses a Container Registry Personal Edition image, the image is cached to the image cache service. You must wait until the accelerated image is available before you call the function in the Function Compute console. The accelerated image becomes available in about 5 minutes after you create or update the function.

View the status of image startup acceleration

You can view the status of image startup acceleration by using one of the following methods to determine whether the accelerated image is available:

  • Log on to the Function Compute console. On the Configurations tab of the function details page, view the value of the Image Acceleration Preparation Status parameter in the Environment Information section. Possible values:

    • Preparing: Image startup acceleration is in progress.

    • Available: Image startup acceleration is complete, and the accelerated image is available.

    • Failed: Image startup acceleration failed.

    The following figure shows an example.get_accelerated_image_status

  • Call the GetFunction operation and check the value of the status parameter in the accelerationInfo structure to view the status of image startup acceleration. Possible values:

    • Preparing: Image startup acceleration is ongoing. If you invoke the function now, the unaccelerated image is pulled, and the image startup is not accelerated.

    • Ready: Image startup acceleration is complete and the accelerated image is available. If you invoke the function now, the image startup is accelerated.

    • Failed: Image startup acceleration failed.

Best practices for versioning

If you use an image of Container Registry Personal Edition, image caching is triggered again when you update the function image. If you invoke the function before the accelerated image is available, the original image is pulled and acceleration is not implemented. You can publish your function by referring to Manage functions and Manage versions. Follow the following procedure:

  1. Update the function. When you update the function, the LATEST version of the service is also updated.

  2. After the status of image startup acceleration changes from Preparing to Available, publish a new service version.

  3. Point the service alias to the new service version.

View the results of image startup acceleration

Sample project puppeteer-pdf provides an example on how to combine Node.js Express and Puppeteer to convert a web page into a PDF file.

Before the image startup acceleration feature is enabled, a cold start requires 66.51s. It only takes 4.3s to complete the cold start after acceleration is enabled, which increases the speed by about 93.5%. Sample code:

time curl -H "x-fc-invocation-target: 2016-08-15/proxy/CustomContainerDemo/puppeteer-pdf-no-accl" https://$ACCOUNT_ID.$REGION.fc.aliyuncs.com/generate-pdf\?url\=http://example.com -o /tmp/fc-demo-puppeteer-pdf-no-accl.pdf

# Time spent: 0.06s user 0.09s system 0% cpu 1:06.51 total time

# Cold start after image acceleration
curl -H "x-fc-invocation-target: 2016-08-15/proxy/CustomContainerDemo/puppeteer-pdf-accl" https://$ACCOUNT_ID.$REGION.fc.aliyuncs.com/generate-pdf\?url\=http://example.com -o /tmp/fc-demo-puppeteer-pdf-accl.pdf

# Time spent: 0.05s user 0.06s system 0% cpu 4.300 total time
Note

The test results of the cold start speed may have deviations. The actual time required may be different in actual scenarios.