Schedule the configuration of RCUs for a serverless instance
Serverless ApsaraDB RDS for MySQL automatically scales RDS Capacity Units (RCUs) based on CPU utilization and memory usage. In 99.8% of cases, scale-ups complete within seconds (intra-host). However, when the current host cannot supply enough resources, an inter-host scale-up is required — this takes 3 to 5 minutes and may affect your workloads. To prevent this from affecting a known busy window, use a scheduled task to raise the RCU minimum before traffic peaks.
How it works
Auto scaling triggers a scale-up when CPU utilization or memory usage reaches 60%–80%. Two types of scale-ups are possible:
| Scale-up type | Duration | Connection impact | Frequency |
|---|---|---|---|
| Intra-host | Seconds | None | 99.8% of cases |
| Inter-host | 3–5 minutes | May affect your workloads | When host cannot supply enough resources |
Setting MinCapacity and MaxCapacity to the same value pins the instance at a fixed capacity for a time window, eliminating scale-up risk during that period.
The scheduled task calls the ModifyDBInstanceSpec API to raise MinCapacity before a busy period starts, then restores the original values when it ends.
Use cases
-
Protect a known peak window: Reserve a fixed RCU range during a predictable busy period (for example, a batch job or business-hours peak) to eliminate inter-host scale-up risk.
Example scenario
Reserve 4–8 RCUs during a peak hour from 08:00 to 09:00. Because an inter-host scale-up can take up to 5 minutes, raise the minimum 10 minutes early — at 07:50. Restore the default range (0.5–8 RCUs) at 09:00.
The two scheduled jobs use the following parameters:
| Time | MinCapacity |
MaxCapacity |
Effect |
|---|---|---|---|
| 07:50 | 4 | 8 | Raises the minimum 10 min before peak; triggers inter-host scale-up if needed |
| 09:00 | 0.5 | 8 | Restores the default range after the peak window |
Prerequisites
Before you begin, ensure that you have:
-
A RAM user with permission to call
ModifyDBInstanceSpec. See Create a RAM user and grant permissions -
Environment variables
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETset on the machine that will run the scheduler. See Configure environment variables
What's next
-
ModifyDBInstanceSpec API reference — Full parameter list and response schema.
-
APScheduler user guide — Advanced scheduler configuration for Python.
-
Spring scheduling documentation — Thread pool configuration and advanced cron options for Java.