Scheduled scaling for deployments
Scheduled scaling runs a deployment at a different replica count during recurring time windows. Use it to add capacity for business hours, or to scale a deployment to zero overnight and on weekends.
A scaling window is a named interval defined by two five-field cron expressions and an IANA time zone, and it carries its own replica count. For how scheduled scaling relates to scheduled target switching and on-demand mode, see Scheduling overview. For the permissions this needs, and for the presets and workspace defaults an administrator sets, see Configure scheduling and on-demand mode.
How windows resolve to a replica count
A window is active from the moment its start expression fires until its end expression fires.
- While a window is active, the deployment runs at that window's
desired_replicas. - Outside every window, the deployment returns to its configured replica count, which is the replica count set on the deployment itself. See Create a deployment.
- When two or more windows are active at the same time, the highest
desired_replicaswins. Theactive_windowfield reports which window won. - A window with
desired_replicasset to0scales the deployment to zero for the duration of the window. - Turning the schedule off restores the configured replica count. H2O MLOps keeps your windows but stops enforcing them until you turn the schedule back on. Clearing the schedule removes the windows as well.
- While a window is active, you cannot change the deployment's configured replica count. H2O MLOps rejects the update, because the schedule rather than your request decides the count until the window closes. Retry once it closes, or turn the schedule off first.
Window boundaries are not instantaneous. Expect up to a minute between a window opening or closing and the replica count changing, whichever scaling engine your administrator runs. If your administrator has not enabled KEDA, H2O MLOps re-evaluates deployment schedules every 60 seconds. If your administrator has enabled KEDA, KEDA applies your windows as cron triggers and owns the replica count instead.
If the deployment also uses on-demand mode, every window's desired_replicas must be greater than or equal to the deployment's configured replica count. For more information, see On-demand mode.
Configure a schedule in the UI
- Click Real-time deployments on the left navigation menu.
- Click the name of the deployment you want to schedule.
- Click the Schedule tab. If the deployment has no schedule yet, the tab shows Scheduled scaling is not set up.
- Click Set up a schedule.
- Turn on Enable scheduled scaling.
- Click Add window.
- In Name, enter a name that is unique within the schedule, such as
weekday-business. - Set when the window opens and closes. Switch between Simple and Cron:
- Simple: Select the Days the window runs on, then set Opens at and Closes at.
- Cron: Enter a five-field cron expression in Opens (cron) and Closes (cron).
- Select a Timezone. The default is
UTC. - In Replicas, enter the replica count to run while the window is active. A value of
0scales the deployment to zero. - Click Add.
- Repeat steps 6 to 11 for each window you need.
- Review Weekly preview. It lays your windows out across a week against the deployment's configured replica count.
- Click Save schedule.
To start from a preset rather than building each window by hand, click Use template. See Presets.
To change a window later, point to its row and click the Edit icon. To delete one, click the Remove icon and confirm at Remove window?. To delete the whole schedule, click Remove schedule.
The Simple editor cannot represent every window. When a window opens more than once a day, restricts the day of month or the month, or uses a different set of days on its opening and closing expressions, Simple becomes unavailable and a tooltip explains why. Edit those windows in Cron mode.
While a window governs the replica count, the Scheduled scaling section shows an Active window: <name> badge, and the window's own row shows an Active now badge. Point to the information icon next to the badge to see when the schedule was last updated.
Configure a schedule with the Python client
Pass a list of ScheduledWindowOptions to deployment.schedule.update(). The following schedule runs three replicas during weekday business hours and shuts the deployment down on weekends:
from h2o_mlops import optionsdeployment.schedule.update(enabled=True,windows=[options.ScheduledWindowOptions(name="weekday-business",start_cron="0 8 * * 1-5",end_cron="0 18 * * 1-5",desired_replicas=3,timezone="Europe/Amsterdam",),options.ScheduledWindowOptions(name="weekend-shutdown",start_cron="0 0 * * 6,0",end_cron="59 23 * * 6,0",desired_replicas=0,timezone="Europe/Amsterdam",),],)
On weekday nights, when neither window is active, the deployment returns to its configured replica count.
Because a window cannot cross midnight, weekend-shutdown closes at 23:59 on Saturday and reopens at 00:00 on Sunday. The deployment comes back to its configured replica count for up to a minute in that gap.
update() applies a partial update. Any argument you omit keeps its current value:
deployment.schedule.update(enabled=False)turns the schedule off without touching the windows.windows=[]removes every window. The call succeeds even while the schedule stays enabled, because H2O MLOps checks for windows only when you setenabledin the same call. The schedule stays enabled with nothing to enforce, and the deployment runs at its configured replica count until you add a window.preset=Noneclears the recorded preset name.
Pass every argument by keyword, because the positional order is windows, enabled, preset.
A deployment has at most one schedule, reached through deployment.schedule. It exposes the following properties and methods:
| Property or method | Description |
|---|---|
enabled | Whether the schedule is in force. You cannot turn it on unless the schedule has at least one window. |
preset | Name of the preset that populated the windows, or None. Informational only. |
windows | The list of ScheduledWindowOptions configured on the deployment. |
active_window | Name of the window currently governing the replica count, or None. |
last_modified_time | When the schedule was last updated. Maps to update_time in the API. |
refresh() | Re-reads the schedule from the server. |
clear() | Removes every window and turns the schedule off. |
Read properties fetch the schedule the first time you access one and then serve it from cache. Call refresh() to pick up a change made elsewhere, such as an edit in the UI:
deployment.schedule.refresh()deployment.schedule.active_window
Cron expression rules and limits
Both expressions in a window use the five-field format minute hour day-of-month month day-of-week, with no seconds field. H2O MLOps rejects an invalid window at save time and returns the reason.
- Every window needs a
name, and names must be unique within the schedule. start_cronandend_cronmust both parse, and they must differ from each other.desired_replicasmust be0or greater, and must stay within the replica limit your administrator configures.timezonemust be a name the IANA database recognizes, such asEurope/Amsterdam. It defaults toUTC.
Four further rules account for most rejections:
- Both expressions must fire within the next 31 days. This rules out impractically sparse schedules. H2O MLOps measures the horizon from the moment you save, so it rejects an expression such as
0 0 29 2 *, which fires only on 29 February, unless you save the schedule within 31 days of that date. - The closing time of day must be later than the opening time of day. H2O MLOps compares only the time-of-day part of the two expressions, so it rejects a window that would run past midnight with the error
active period crosses a day boundary. Split it into two windows, as shown in the next section. - The day fields of
start_cronandend_cronmust be identical. Day-of-month, month, and day-of-week all have to match. Only the time of day may differ. - A scale-to-zero window must not restrict day-of-month or month. Day-of-week still works, so you can shut a deployment down on weekends, but you cannot shut it down on the first of the month. This rule applies only when
desired_replicasis0.
Split a window that crosses midnight
Suppose you want to hold a deployment at zero replicas from 22:00 to 06:00 on weeknights. Written as one window, 0 22 * * 1-5 to 0 6 * * 1-5 fails validation, because 06:00 is earlier in the day than 22:00.
Split it into an evening half and a morning half, and give both the same desired_replicas:
| Window | start_cron | end_cron |
|---|---|---|
overnight-evening | 0 22 * * 1-5 | 59 23 * * 1-5 |
overnight-morning | 0 0 * * 2-6 | 0 6 * * 2-6 |
The day-of-week field shifts by one day on the morning half. Monday evening runs into Tuesday morning, so a Monday-to-Friday evening window pairs with a Tuesday-to-Saturday morning window. Getting this wrong is the most common mistake with split windows: reusing 1-5 on both halves scales the deployment down on Monday morning and leaves it at the configured replica count on Saturday morning.
The two halves do not join cleanly. The deployment can return to its configured replica count for up to a minute between one half closing and the next opening.
Presets
A preset is a named bundle of scaling windows that your administrator defines in server configuration. Applying one copies its windows into your schedule and records its name in preset.
The copy is not a link. Later changes to the preset definition never reach a schedule that already used it, and you can edit the copied windows freely.
To list the presets available on your server:
mlops.configs.deployment_schedule_presets
To apply one by name:
office_hours = next(presetfor preset in mlops.configs.deployment_schedule_presetsif preset.name == "pst-office-hrs")deployment.schedule.update(enabled=True,windows=office_hours.windows,preset=office_hours.name,)
In the UI, click Use template on the Schedule tab, pick a preset from the Template dropdown, and click Apply. The dialog previews the week that the preset produces before you commit to it. Applying a preset replaces the windows already in the editor.
Use template appears only when your administrator has defined at least one preset. For how to define presets, see Configure scheduling and on-demand mode.
To schedule which deployment an endpoint routes to, rather than how many replicas a deployment runs, see Scheduled target switching for endpoints.
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai