Compared with function code packages, container images provide better portability and a more diverse ecosystem of toolchains. However, the irrelevant data contained makes the cold start of an image that is gigabytes in size last several minutes. When you enable the image pull acceleration feature, the cold start speed can be increased in two phases by approximately 90%, and the period of time that is required to pull an image can be decreased from a few minutes to a few seconds. This topic describes how does image pull acceleration for Container Registry Personal Edition works and how to configure image pull acceleration.

Principles

If you enable the image pull acceleration feature when you create or update a container image in Container Registry Personal Edition for a function that runs in a custom container, Function Compute assumes a RAM role, uses a temporary AccessKey pair to pull the image, and then transfers the image to the image cache service of Function Compute. After the image is cached, the speed for pulling the image is improved.

Usage notes

  • The image pull acceleration feature is supported in the following regions: China (Beijing), China (Zhangjiakou), China (Hangzhou), China (Shanghai), China (Shenzhen), China (Hong Kong), Singapore (Singapore), US (Silicon Valley), and US (Virginia).
  • If you enable the image pull acceleration feature, Function Compute is authorized to pull images from your image repository and transfer the images to the image cache service of Function Compute. To ensure data security, Container Registry Personal Edition supports network isolation and identity authentication to allow all users to encrypt the data and restrict access to the image. Before you enable this feature, make sure that the operation of transferring images to the image cache service of Function Compute complies with the security regulations and guidelines of your organization.
  • After you create or update a function that uses a container image in Container Registry Personal Edition, a period of time is required to transfer the image. Therefore, a cache miss may occur before the cached image becomes available. The cached image becomes available approximately 5 minutes after you create or update the function.

Configuration methods

You can configure image pull acceleration by using one of the following methods when you create or update a function:

  • Use the Function Compute console. For more information, see Create a function in the console.
    The following figure shows how to configure the image pull acceleration feature when you update a function.container_acceleration
  • Use Serverless Devs. For more information, see YAML syntax.
    Add the accelerationType parameter to the CustomContainerConfig structure. Valid values:
    • Default: enables the image pull acceleration feature.
    • None: disables the image pull acceleration feature.
    The following sample code shows how to enable the image pull acceleration feature:
    customContainerConfig:
      image: registry-vpc.<regionId>.aliyuncs.com/fc-demo/python-flask:[Image version]
      accelerationType: Default

    For more information about the complete procedure, see Sample project puppeteer-pdf.

  • Use SDKs.

View the status of image pull acceleration

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

  • On the Configurations tab of the function details page in the Function Compute console, view the value of the Image Acceleration Preparation Status parameter in the Environment Information section. Valid values:
    • Preparing: Image pull acceleration is being prepared.
    • Available: Image pull acceleration is ready.
    • Failed: Failed to accelerate the image pull.
    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 pull acceleration. Valid values:
    • Preparing: Image pull acceleration is being prepared. If you invoke the function now, the original image is pulled, and the image pull is not accelerated.
    • Ready: Image pull acceleration is ready. If you invoke the function now, the image pull is accelerated.
    • Failed: Failed to accelerate the image pull.

Best practices for versioning

If you use Container Registry Personal Edition and enable the image pull acceleration feature, the transfer of the new image is triggered when you update the image for the function. When you invoke the function before the cached image is available, the original image is pulled and the image pull is not accelerated. You can systematically publish the function by managing the function and managing versions:

  1. Update the function. When you update this function, the LATEST version of the service is also updated.
  2. After the status of image pull acceleration changes from Preparing to Available, publish a new service version.
  3. Switch the service alias to the new service version.

View the results of image pull acceleration

After you enable the image pull acceleration feature, the cold start speed is increased in two phases.

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 pull acceleration feature is enabled, the process takes 66.51s. After you enable the image pull acceleration feature, the process takes only 15.2s for the first phase and the cold start speed is increased by 77.1%. The process takes only 4.3s for the second phase and the cold start speed is increased by 71.6%. The cold start speed is increased by 93.5% in total. 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

# First image cold start after the image pull acceleration feature is enabled
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 15.200 total time

# Cold start after a period of time
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 Errors may occur during testing. The period of time that is required for an actual scenario may be different.