Skip to main content
Version: v1.2.0

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_replicas wins. The active_window field reports which window won.
  • A window with desired_replicas set to 0 scales 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.

caution

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

  1. Click Real-time deployments on the left navigation menu.
  2. Click the name of the deployment you want to schedule.
  3. Click the Schedule tab. If the deployment has no schedule yet, the tab shows Scheduled scaling is not set up.
  4. Click Set up a schedule.
  5. Turn on Enable scheduled scaling.
  6. Click Add window.
  7. In Name, enter a name that is unique within the schedule, such as weekday-business.
  8. 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).
  9. Select a Timezone. The default is UTC.
  10. In Replicas, enter the replica count to run while the window is active. A value of 0 scales the deployment to zero.
  11. Click Add.
  12. Repeat steps 6 to 11 for each window you need.
  13. Review Weekly preview. It lays your windows out across a week against the deployment's configured replica count.
  14. 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.

note

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 options

deployment.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.

note

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 set enabled in 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=None clears 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 methodDescription
enabledWhether the schedule is in force. You cannot turn it on unless the schedule has at least one window.
presetName of the preset that populated the windows, or None. Informational only.
windowsThe list of ScheduledWindowOptions configured on the deployment.
active_windowName of the window currently governing the replica count, or None.
last_modified_timeWhen 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_cron and end_cron must both parse, and they must differ from each other.
  • desired_replicas must be 0 or greater, and must stay within the replica limit your administrator configures.
  • timezone must be a name the IANA database recognizes, such as Europe/Amsterdam. It defaults to UTC.

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_cron and end_cron must 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_replicas is 0.

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:

Windowstart_cronend_cron
overnight-evening0 22 * * 1-559 23 * * 1-5
overnight-morning0 0 * * 2-60 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(
preset
for preset in mlops.configs.deployment_schedule_presets
if 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.

note

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.


Feedback