The Bodaciously Excellent Blog of Doctorwhen

How To Run High Use Apps During Off-Peak Hours

How To Run High Use Apps During Off-Peak Hours

Most electricity utilities charge higher rates during “peak” hours, times and/or days of the week during which the public typically uses a lot of energy. If you run energy intensive applications during peak or near peak hours then you may run up your energy bill unexpectedly high. What follows is a way to schedule these energy intensive tasks so they run during off-peak hours only.

Sample Rate Schedule

Here is my energy provider’s rate schedule for my plan:

Summer weekdays (May – October)

Off-Peak 9PM – 10AM

Part-Peak 10AM – 1PM and 7PM – 9PM

Peak 1PM – 7PM

Weekends
Part-Peak5PM – 8PM
Off-Peak8PM – 5PM
Holidays – Standard Tiered Rates (Tier 2)
Off-PeakAll day

Winter weekdays (November – April)

Off-Peak 8PM – 5PM

Part-Peak 5PM – 8PM

Weekends
Off-PeakAll day
Holidays – Standard Tiered Rates (Tier 2)
Off-PeakAll day

Saving Energy & Saving Money

Seasons: During summer, prices are lowest in the morning, late evenings, and weekends from May through October. During winter months from November through April, prices are lowest at all times outside of 5 p.m. – 8 p.m. on weekdays (excluding holidays).

You can lower your energy costs by staying within the lowest priced level or tier. I’ve written a crontab entry that runs my energy intensive cryptocurrency miners during off-peak hours only. This saves quite a bit in energy costs while simultaneously allowing me to mine cryptocurrency during much of the day/week.

Your plan may vary from the above schedule. The first step in scheduling your energy intensive jobs is to determine your rate schedule. This is typically available via the website of your energy provider. Once you have determined your rate schedule you can then utilize the cron facility on a Unix or Linux based computer to control the time of execution of your application(s).

The Cron Utility on Unix & Linux Systems

The software utility cron is a time-based job scheduler in Unix-like computer operating systems. People who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals. It typically automates system maintenance or administration—though its general-purpose nature makes it useful for things like downloading files from the Internet and downloading email at regular intervals. The origin of the name cron is from the Greek word for time, χρόνος (chronos).

Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule. The crontab files are stored where the lists of jobs and other instructions to the cron daemon are kept. Users can have their own individual crontab files and often there is a system-wide crontab file (usually in /etc or a subdirectory of /etc) that only system administrators can edit.

Each line of a crontab file represents a job, and looks like this:

# ┌───────────── minute (0-59)
# │ ┌───────────── hour (0-23)
# │ │ ┌───────────── day of the month (1-31)
# │ │ │ ┌───────────── month (1-12)
# │ │ │ │ ┌───────────── day of the week (0-6) (Sunday to Saturday;
# │ │ │ │ │ 7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command to execute

My Energy/Money Saving Crontab Entry

The syntax of each line expects a cron expression made of five fields, followed by a shell command to execute. Here is a crontab entry I wrote to run my cryptocurrency miners only during my off-peak hours:

# Crontab entries to run a cryptocurrency miner only during 2019
# PG&E Off-Peak hours
#
# You may have to adjust the hours/days/months for your energy
# provider.
#
# By default these entries run every 15 minutes.
# This provides a keepalive function and relies on the
# start_miner script checking to see if it is already running.
# You may prefer to change the '0,15,30,45' entries to simply
# '0' or '15' to only
# start/stop once and not every 15 minutes. Or, you may prefer
# to increase the "keepalive" frequency from 15 to 5 minutes
#   '0,5,10,15,20,25,30,35,40,45,50,55'
#
# Written October 24, 2018 by Ron Record
# (gitlab at ronrecord dot com)
#
# TODO: Figure out how to add Holidays to start times and
# remove them from stop times
#
# Set SHELL to run my custom cron script when running commands
SHELL=/usr/local/bin/cron.bash
#
# minutes hours days-of-month months days-of-week  command
#
# Start miner during off-peak hours (Summer)
# ------------------------------------------
# Weekdays
0,15,30,45 0-9,21-23 * 5-10 1-5 /usr/local/bin/start_miner
# Weekends
0,15,30,45 0-12,20-23 * 5-10 0,6 /usr/local/bin/start_miner
#
# Start miner during off-peak hours (Winter)
# ------------------------------------------
# Weekdays
0,15,30,45 0-16,20-23 * 1-4,11,12 1-5 /usr/local/bin/start_miner
# Weekends
0,15,30,45 * * 1-4,11,12 0,6 /usr/local/bin/start_miner
#
# Stop miner during peak/near-peak hours (Summer)
# -----------------------------------------------
# Weekdays
0,15,30,45 10-20 * 5-10 1-5 /usr/local/bin/stop_miner
# Weekends
0,15,30,45 13-19 * 5-10 0,6 /usr/local/bin/stop_miner
#
# Stop miner during peak/near-peak hours (Winter)
# -----------------------------------------------
0,15,30,45 17-19 * 1-4,11,12 1-5 /usr/local/bin/stop_miner


Let me know what you think