batchRun a job when the system is idle enough
batch queues a command like at, but instead of a time it waits until the system load average drops below a threshold (1.5 by default), then runs it at lower priority. It suits heavy one-off work like re-indexing or compressing archives on a busy server.
batch [-f FILE] [-m] (same as: at -q b now)Compress last week's logs on a busy app server without competing with production traffic.
echo 'nice -n 19 gzip -9 /var/log/app/*.log.1'The job text, read from stdin like at. The glob expands when the job runs, not now.
batch is a mode of the at program: it queues the job in queue 'b' with a run time of now, and atd stores it in /var/spool/cron/atjobs with the same environment-capturing script as at. The difference is in how atd starts it. Before launching a batch job, atd reads the 1-minute load average (getloadavg, the first number in /proc/loadavg) and only runs the job if it's below the limit: 1.5 by default, configurable with atd -l. It also starts at most one batch job per interval (atd -b, default 60 seconds), so a queue of heavy jobs trickles out one by one instead of all at once. Jobs in higher-lettered queues run with a higher nice value, so they get less CPU when the box is busy. While a job runs, atq shows it in the '=' queue. On a host whose load never drops below the limit, for example one with many cores, batch jobs can wait forever.
-f FILERead the job from FILE instead of stdin-mMail when finished-q LETTERUse another queue (default b)atq / atq -q bList pending jobs (only the batch queue)atrm JOBCancel a jobatd -l LOADDaemon option: load limit for batch jobs (default 1.5)atd -b SECONDSDaemon option: minimum gap between batch job startsExpecting batch to run 'tonight'batch has no time argument; it runs as soon as the load is low, which may be right now.
echo cmd | at 02:00 # or at -q b 02:00 for a timed batch-queue jobUsing batch on a many-core server with the default settingsThe 1.5 limit is absolute, not per core, so normal load on a big box keeps jobs waiting forever.
Run atd with -l <cores x 0.75>, or use nice/ionice from at or systemd-runAssuming batch makes a job 'low priority' in every wayIt only delays the start and adds a small nice value. Once running, a disk-heavy job still hurts I/O.
echo 'nice -n 19 ionice -c3 /opt/heavy.sh' | batchTry these on a Linux machine of your own. Each task has a hint and a solution.
Queue 'sleep 30; date > /tmp/batch-done.txt' with batch and check which queue it's in.
Check the current 1-minute load average and decide whether atd will start a batch job now.
Queue a CPU-heavy job through batch that also runs at the lowest CPU priority.
batchRun a job when the system is idle enough
batch queues a command like at, but instead of a time it waits until the system load average drops below a threshold (1.5 by default), then runs it at lower priority. It suits heavy one-off work like re-indexing or compressing archives on a busy server.
batch [-f FILE] [-m] (same as: at -q b now)Compress last week's logs on a busy app server without competing with production traffic.
echo 'nice -n 19 gzip -9 /var/log/app/*.log.1'The job text, read from stdin like at. The glob expands when the job runs, not now.
batch is a mode of the at program: it queues the job in queue 'b' with a run time of now, and atd stores it in /var/spool/cron/atjobs with the same environment-capturing script as at. The difference is in how atd starts it. Before launching a batch job, atd reads the 1-minute load average (getloadavg, the first number in /proc/loadavg) and only runs the job if it's below the limit: 1.5 by default, configurable with atd -l. It also starts at most one batch job per interval (atd -b, default 60 seconds), so a queue of heavy jobs trickles out one by one instead of all at once. Jobs in higher-lettered queues run with a higher nice value, so they get less CPU when the box is busy. While a job runs, atq shows it in the '=' queue. On a host whose load never drops below the limit, for example one with many cores, batch jobs can wait forever.
-f FILERead the job from FILE instead of stdin-mMail when finished-q LETTERUse another queue (default b)atq / atq -q bList pending jobs (only the batch queue)atrm JOBCancel a jobatd -l LOADDaemon option: load limit for batch jobs (default 1.5)atd -b SECONDSDaemon option: minimum gap between batch job startsExpecting batch to run 'tonight'batch has no time argument; it runs as soon as the load is low, which may be right now.
echo cmd | at 02:00 # or at -q b 02:00 for a timed batch-queue jobUsing batch on a many-core server with the default settingsThe 1.5 limit is absolute, not per core, so normal load on a big box keeps jobs waiting forever.
Run atd with -l <cores x 0.75>, or use nice/ionice from at or systemd-runAssuming batch makes a job 'low priority' in every wayIt only delays the start and adds a small nice value. Once running, a disk-heavy job still hurts I/O.
echo 'nice -n 19 ionice -c3 /opt/heavy.sh' | batchTry these on a Linux machine of your own. Each task has a hint and a solution.
Queue 'sleep 30; date > /tmp/batch-done.txt' with batch and check which queue it's in.
Check the current 1-minute load average and decide whether atd will start a batch job now.
Queue a CPU-heavy job through batch that also runs at the lowest CPU priority.