Load depending number of worker queues.
This commit is contained in:
parent
ae21c40f21
commit
9767801be4
1 changed files with 21 additions and 27 deletions
|
@ -26,10 +26,11 @@ function poller_run(&$argv, &$argc){
|
||||||
unset($db_host, $db_user, $db_pass, $db_data);
|
unset($db_host, $db_user, $db_pass, $db_data);
|
||||||
};
|
};
|
||||||
|
|
||||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
|
||||||
if($maxsysload < 1)
|
|
||||||
$maxsysload = 50;
|
|
||||||
if(function_exists('sys_getloadavg')) {
|
if(function_exists('sys_getloadavg')) {
|
||||||
|
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||||
|
if($maxsysload < 1)
|
||||||
|
$maxsysload = 50;
|
||||||
|
|
||||||
$load = sys_getloadavg();
|
$load = sys_getloadavg();
|
||||||
if(intval($load[0]) > $maxsysload) {
|
if(intval($load[0]) > $maxsysload) {
|
||||||
logger('system: load ' . $load[0] . ' too high. poller deferred to next scheduled run.');
|
logger('system: load ' . $load[0] . ' too high. poller deferred to next scheduled run.');
|
||||||
|
@ -63,18 +64,11 @@ function poller_run(&$argv, &$argc){
|
||||||
|
|
||||||
while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) {
|
while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) {
|
||||||
|
|
||||||
if(function_exists('sys_getloadavg')) {
|
|
||||||
$load = sys_getloadavg();
|
|
||||||
if(intval($load[0]) > $maxsysload) {
|
|
||||||
logger('system: load ' . $load[0] . ' too high. poller deferred to next scheduled run.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quit the poller once every hour
|
// Quit the poller once every hour
|
||||||
if (time() > ($starttime + 3600))
|
if (time() > ($starttime + 3600))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Count active workers and compare them with a maximum value that depends on the load
|
||||||
if (poller_too_much_workers())
|
if (poller_too_much_workers())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -115,28 +109,28 @@ function poller_run(&$argv, &$argc){
|
||||||
|
|
||||||
function poller_too_much_workers() {
|
function poller_too_much_workers() {
|
||||||
|
|
||||||
|
$queues = get_config("system", "worker_queues");
|
||||||
|
|
||||||
|
if ($queues == 0)
|
||||||
|
$queues = 4;
|
||||||
|
|
||||||
|
$active = poller_active_workers();
|
||||||
|
|
||||||
|
// Decrease the number of workers at higher load
|
||||||
if(function_exists('sys_getloadavg')) {
|
if(function_exists('sys_getloadavg')) {
|
||||||
$load = sys_getloadavg();
|
$load = max(sys_getloadavg());
|
||||||
|
|
||||||
// To-Do
|
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||||
if ($load < 1)
|
if($maxsysload < 1)
|
||||||
$queues = 10;
|
$maxsysload = 50;
|
||||||
elseif ($load < 5)
|
|
||||||
$queues = 4;
|
|
||||||
elseif ($load < 10)
|
|
||||||
$queues = 2;
|
|
||||||
else
|
|
||||||
$queues = 1;
|
|
||||||
|
|
||||||
} else {
|
$queues = max(0, ceil($queues * (($maxsysload - $load) / $maxsysload)));
|
||||||
$queues = intval(get_config("system", "worker_queues"));
|
|
||||||
|
logger("Current load: ".$load." - maximum: ".$maxsysload." - current queues: ".$active." - maximum: ".$queues, LOGGER_DEBUG);
|
||||||
|
|
||||||
if ($queues == 0)
|
|
||||||
$queues = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poller_active_workers() >= $queues)
|
return($active >= $queues);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function poller_active_workers() {
|
function poller_active_workers() {
|
||||||
|
|
Loading…
Reference in a new issue