NAME
NBI::EcoScheduler - Find energy-efficient SLURM job start times
VERSION
version 0.17.0
SYNOPSIS
use NBI::EcoScheduler;
my $config = NBI::Slurm::load_config(); # or {}
my ($epoch, $tier) = NBI::EcoScheduler::find_eco_begin(4, $config);
if (defined $epoch) {
my $begin = NBI::EcoScheduler::epoch_to_slurm($epoch);
my $delay = NBI::EcoScheduler::format_delay($epoch);
print "Schedule job for $begin (in $delay) — tier $tier\n";
}
DESCRIPTION
NBI::EcoScheduler finds the next time window when running a SLURM job is likely to consume cheap or low-carbon energy. It walks forward from the current time in window-boundary steps, scoring each candidate slot:
Tier 1 — Job fits entirely inside an eco window and avoids peak hours.
Tier 2 — Job avoids peak hours but overruns the eco window.
Tier 3 — Job starts in an eco window but overlaps peak hours (last resort).
The first tier-1 slot is returned immediately. If the lookahead period is exhausted without finding one, the first tier-2 slot is returned, then tier-3. (undef, undef) is returned only if no eco window exists at all in the lookahead period.
NAME
NBI::EcoScheduler - Find energy-efficient start times for SLURM jobs
DEFAULT WINDOWS
Mon–Fri: 00:00–06:00
Sat–Sun: 00:00–07:00 and 11:00–16:00
Avoid: 17:00–20:00 (every day)
These are overridden by the corresponding keys in ~/.nbislurm.config.
CONFIGURATION
The following keys are read from the config hash (all optional):
eco_windows_weekday HH:MM-HH:MM (default: 00:00-06:00)
eco_windows_weekend HH:MM-HH:MM[,HH:MM-HH:MM] (default: 00:00-07:00,11:00-16:00)
eco_avoid HH:MM-HH:MM[,HH:MM-HH:MM] (default: 17:00-20:00)
eco_lookahead_days integer (default: 3)
eco_default 0 or 1 (default: 1)
FUNCTIONS
find_eco_begin($duration_h, $config, $now)
my ($epoch, $tier) = NBI::EcoScheduler::find_eco_begin($hours, $config);
Finds the best eco start time for a job of $duration_h hours. $config is a hashref (may be empty); $now is an optional epoch timestamp (defaults to time(); useful for testing).
Returns ($begin_epoch, $tier) or (undef, undef).
epoch_to_slurm($epoch)
my $str = NBI::EcoScheduler::epoch_to_slurm($epoch);
# "2026-03-17T00:00:00"
Converts a Unix epoch to the SLURM --begin format.
format_delay($epoch, $now)
my $str = NBI::EcoScheduler::format_delay($epoch);
# "6h 05m", "1d 2h 30m", "now"
Returns a human-readable string describing the delay until $epoch.
INTERNAL FUNCTIONS
_windows_for_day($midnight, $dow, $cfg)
Returns the eco windows for a given day as [$start_epoch, $end_epoch] pairs.
_avoid_for_day($midnight, $cfg)
Returns the avoid windows for a given day.
_parse_window_string($str, $midnight)
Parses a comma-separated list of HH:MM-HH:MM ranges anchored to $midnight.
_job_overlaps_avoid($start, $duration_h, \@avoid)
Returns 1 if a job of $duration_h hours starting at $start overlaps any avoid window.
AUTHOR
Andrea Telatin <proch@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2023-2025 by Andrea Telatin.
This is free software, licensed under:
The MIT (X11) License