In most cases, the RDS Capacity Unit (RCU) scaling for a serverless ApsaraDB RDS for MySQL instance can be complete within seconds. In some cases, the RCU scaling may require 3 to 5 minutes to complete due to inter-host scale-ups. If you have strict requirements on stability within a specific period of time, you can configure scheduled tasks to adjust the number of RCUs for your serverless RDS instance. This topic describes how to configure scheduled tasks to adjust the number of RCUs.
Scenarios
The system performs auto scaling on a serverless RDS instance based on the CPU utilization and memory usage. If the CPU utilization or memory usage falls into the range of 60% to 80%, automatic scale-ups are triggered. If you have high requirements on stability of the CPU or memory resources within a specific period of time, you must adjust the minimum number of RCUs in advance.
Intra-host scale-ups and inter-host scale-ups are supported. Intra-host scale-ups can be complete within seconds, and inter-host scale-ups can be complete within 3 to 5 minutes. In 99.8% of scenarios, intra-host scale-ups can meet your business requirements. If the host on which the serverless RDS instance resides cannot provide sufficient resources, you must scale up the RCUs across hosts. An inter-host scale-up requires a long period of time to complete, which may affect your workloads. We recommend that you set the maximum number and minimum number of RCUs to the same value for specific periods of time to prevent the impacts caused by the automatic scale-up failure.
Solutions
Create a scheduled task to call the ModifyDBInstanceSpec operation to modify the maximum number and minimum number of RCUs within a specific period of time. After the period of time elapses, the modification is rolled back.
Examples
If you want to increase the minimum number of RCUs for a specific period of time, we recommend that you create a scheduled task to increase the minimum number of RCUs 10 minutes before the period of time. If an inter-host scale-up is required, this allows the inter-host scale-up to complete and ensures the instance stability within the period of time.
For example, if you want to reserve 4 to 8 RCUs during the peak hour from 08:00 to 09:00, you can increase the minimum number of RCUs to 4 at 07:50 and restore the configuration to the default configuration of 0.5 to 8 RCUs at 09:00.
Sample code in Python
This section provides an example on how to use APScheduler to configure a scheduled task. For more information, see User guide.
Complete the following operations:
Open the CLI and run the following command to install APScheduler:
pip install apscheduler
Download the sample code.
Go to the Debugging page of ModifyDBInstanceSpec in OpenAPI Explorer.
On the Parameters tab, configure the following parameters.
On the SDK Sample Code tab, select Python for Languages and click Download Project to download the sample code package.
Decompress the package on your on-premises device and go to the alibabacloud_sample directory.
Parameter
Description
Value
DBInstanceId
The instance ID.
rm-bp1t8v93k6e15****
PayType
The billing method of the instance.
Serverless
Direction
The specification change type of the instance.
Serverless
MaxCapacity
The maximum number of RCUs.
8.0
MinCapacity
The minimum number of RCUs.
0.5
AutoPause
Specifies whether to enable the automatic start and stop feature for the serverless RDS instance.
false
SwitchForce
Specifies whether to enable the forced scaling feature for the serverless RDS instance.
true
NoteWe recommend that you download the sample project of SDK V2.0.
Modify the code to configure the scheduled task.
Add the content of the APScheduler scheduled task to the sample.py file and use a cron trigger to configure the execution time of the scheduled task. For example, the
scheduler.add_job(my_scheduled_job, 'cron', hour=8, minute=0)
setting indicates that the task is automatically executed at 08:00:00 every day. The following sample code shows how to set the RCU scaling range to [4, 8] at 07:50 every day and restore the RCU scaling range to [0.5, 8] at 09:00 every day:
Sample code in Java
This section provides an example on how to use Spring Schedule to configure a scheduled task.
In this example, you must install Java 1.8 or later.
Complete the following operations:
Download the sample package and decompress the package to your on-premises device.
For more information about the sample package, see demo.zip.
Modify the content of
ScheduleTask.java
and configure the scheduled task based on your business requirements.Configure a CRON expression to specify the execution time of the scheduled task.
cron = "Second Minute Hour Day Month Week"
is a CRON expression. For more information, see Cron.For example,
@Scheduled(cron = "0 0 8 * * ? ")
represents 08:00:00 every day. The following sample code shows how to set the RCU scaling range to [4, 8] at 07:50 every day and restore the RCU scaling range to [0.5, 8] at 09:00 every day:The following table describes some parameters. You can change the values of the parameters based on your business requirements.
Parameter
Description
Example
RegionId
The region ID of the instance.
cn-hangzhou
DBInstanceId
The instance ID.
rm-bp1t8v93k6e15****
PayType
The billing method of the instance.
Serverless
Direction
The specification change type of the instance.
Serverless
MaxCapacity
The maximum number of RCUs.
8.0
MinCapacity
The minimum number of RCUs.
0.5
AutoPause
Specifies whether to enable the automatic start and stop feature for the serverless RDS instance.
false
SwitchForce
Specifies whether to enable the forced scaling feature for the serverless RDS instance.
true