Function Compute supports two types of instances: reserved instances and 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 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.
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.
Wait for Function Compute to create the reserved instances.
client = fc2.Client(
serviceName = "ProvisionSerrvice"
functionName = "hello-world"
handler='main.my_handler', runtime='python2.7', codeDir='test/hello_world')
r = client.publish_version(serviceName, "test service v1")
v1 = r.data['versionId']
self.client.create_alias(serviceName, "test", v1, "test alias")
client.put_provision_config(serviceName, "test", functionName, 10)
print(client.get_provision_config(serviceName, "test", functionName).data)
# Cancel the provision
# client.put_provision_config(serviceName, "test", functionName, 0)