From a480bc54fd63c6f4588fc4f44288cfe631d9176a Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 25 Aug 2011 01:45:54 -0700 Subject: [PATCH] Support --load-triggers on non-Linux platforms via uptime command --- jobd/jobd.pl | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/jobd/jobd.pl b/jobd/jobd.pl index 0c78057..e170e26 100755 --- a/jobd/jobd.pl +++ b/jobd/jobd.pl @@ -251,12 +251,29 @@ sub ts { "[". scalar(localtime) ."] "; } +sub get_load_info { + if ($^O eq "linux") { + # Read /proc/loadavg on Linux + open(LOADAV, '<', '/proc/loadavg') or return undef; + my $loadinfo = ; + close LOADAV; + return (split(/\s/, $loadinfo, 4))[0..2]; + } else { + # Read the output of uptime everywhere else (works on Linux too) + open(LOADAV, '-|', 'uptime') or return undef; + my $loadinfo = ; + close LOADAV; + $loadinfo =~ /load average[^0-9.]*([0-9.]+)[^0-9.]+([0-9.]+)[^0-9.]+([0-9.]+)/iso or return undef; + return ($1, $2, $3); + } +} + sub run_queue { my $last_progress = time; my $last_checkload = time - 5; my $current_load = $load_trig; my $overloaded = 0; - my $load_info = ''; + my $load_info = ''; $jobs_executed = 0; $jobs_skipped = 0; @jobs_killed = (); @@ -269,10 +286,7 @@ sub run_queue { reap_hanging_jobs(); my $proceed_immediately = reap_finished_jobs(); # Check current system load - if ($load_trig && (time - $last_checkload) >= 5 && open(LOADAV, '<', '/proc/loadavg')) { - my $loadinfo = ; - close LOADAV; - my @loadinfo = split(/\s/, $loadinfo); + if ($load_trig && (time - $last_checkload) >= 5 && defined((my @loadinfo = get_load_info())[0])) { my $current_load = $loadinfo[0]; if ($current_load > $load_trig && !$overloaded) { $overloaded = 1; @@ -448,7 +462,8 @@ this refers to repacking jobs. If the first system load average (1 minute average) exceeds TRIG, don't queue any more jobs until it goes below UNTRIG. This is currently only supported on -Linux. +Linux and any other platforms that provide an uptime command with load average +output. If both values are zero, load checks are disabled. Note that this is not the default. -- 2.11.4.GIT