Compared with function code packages, container images provide better portability and a rich ecosystem of toolchains. However, the irrelevant built-in data contained makes the cold start of an image of gigabytes of data last several minutes. After the image pull acceleration is enabled on Function Compute, the image pull speed can be accelerated by two to five times and the pull time can be reduced from minutes to seconds. This topic describes the principles, precautions, and configuration method of image pull acceleration.

How image pull acceleration works

For a function whose runtime environment is custom container, every time the function is created or updated (CreateFunction or UpdateFunction) after the image pull acceleration feature is enabled, Function Compute assumes the role of a RAM user, pulls the image by using a temporary AccessKey pair, and transfers the image to the accelerated image cache of Function Compute. After the images are transferred, the pull speed of custom container images is significantly improved.

Limits

  • Image pull acceleration is supported only in the following regions: China (Beijing), China (Hangzhou), China (Shanghai), US (Silicon Valley), and US (Virginia).
  • If you agree to enable image pull acceleration, you agree to authorize Function Compute to pull images from your repository and transfer them to the image cache service of Function Compute. The image data is encrypted and provided with network isolation and identity authentication to ensure data security. 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 a function is created or updated, it takes some time to transfer the image. Therefore, cache miss may occur before the cached image is available. The cached image is usually available in five minutes after the function is created or updated.

Configuration methods

You can configure image pull acceleration in the following ways when you create or update a function:

View accelerated image availability

You can call the GetFunction operation and check the Status value of the AccelerationInfo to view the status of image pull acceleration. Valid values of the Status parameter:
  • Preparing: Image pull acceleration is being prepared. If you invoke the function now, the image pull speed is not accelerated.
  • Ready: Image pull acceleration is ready. If you invoke the function now, the image pull speed is accelerated.

View image pull acceleration results

Sample project puppeteer-pdf provides a complete example of combining Node.js Express and Puppeteer to convert a webpage into a PDF file. The image pull periods before and after image pull acceleration is enabled are 66.51s and 15.2s, down 77.1%. 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 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