All Products
Document Center

Introduction to supplementary examples

Last Updated: Apr 06, 2020

Function Compute supports two types of instances: reserved instances and pay-as-you-go instances.

Pay-as-you-go instances

Pay-as-you-go instances are allocated and released by Function Compute. When Function Compute receives function invocation requests, it adds pay-as-you-go instances to handle the requests. After the requests are processed, Function Compute releases the instances. Pay-as-you-go instances are scalable and reliable. Using pay-as-you-go instances can simplify your resource management work.

However, using pay-as-you-go instances means that you cannot avoid cold start, which has negative impacts on your online applications if they are sensitive to the response latency.

Reserved instances

Reserved instances are allocated and released by users. Reserved instances are charged based on the uptime of the instances.

A reserved instance is ready for use after it is created. This completely eliminates the negative impacts caused by cold start.

By default, reserved instance are prioritized over pay-as-you-go instances. When Function Compute receives function invocation requests, it preferentially uses reserved instances to handle the requests. If the reserved instances are insufficient to handle all the requests, Function Compute adds pay-as-you-go instances as an addition, and sends the remaining requests to the pay-as-you-go instances.

As shown in the following figure, the execution duration starts from the time when the reserved instance is created and ends at the time when the instance completes the requested task.

Note: Before you call the Function Compute API to release a reserved instance, make sure that no new requests are sent to the instance.

For more information about pricing details, see Pricing.



1. Log on to the Function Compute console and create a function named hello. For more information, see Use the Function Compute console.


2. Assign an alias to the service released based on the function. For more information, see Version management.

You must release the function as a service and assign an alias to the service before you can create reserved instances.Version

Assign an alias


3. Click the Reserved Resources tab to create reserved instances for the function.

Note: To release the reserved instances, change the number of instances to 0.

Create reserved instances

Wait for Function Compute to create the reserved instances.

Reserved instances


  1. import fc2
  2. client = fc2.Client(
  3. endpoint=<your endpoint>,
  4. accessKeyID=<your access_key_id>,
  5. accessKeySecret=<your access_key_secret>,
  6. )
  7. serviceName = "ProvisionSerrvice"
  8. functionName = "hello-world"
  9. client.create_service(serviceName)
  10. client.create_function(
  11. serviceName, functionName,
  12. handler='main.my_handler', runtime='python2.7', codeDir='test/hello_world')
  13. r = client.publish_version(serviceName, "test service v1")
  14. v1 =['versionId']
  15. self.client.create_alias(serviceName, "test", v1, "test alias")
  16. client.put_provision_config(serviceName, "test", functionName, 10)
  17. print(client.get_provision_config(serviceName, "test", functionName).data)
  18. # Cancel the provision
  19. # client.put_provision_config(serviceName, "test", functionName, 0)