Merge pull request #2159 from annando/1512-worker-processes

Better control for the number of workers
This commit is contained in:
fabrixxm 2015-12-07 23:20:02 +01:00
commit f359731fc1

View file

@ -38,6 +38,10 @@ function poller_run(&$argv, &$argc){
} }
} }
// Checking the number of workers
if (poller_too_much_workers(1))
return;
if(($argc <= 1) OR ($argv[1] != "no_cron")) { if(($argc <= 1) OR ($argv[1] != "no_cron")) {
// Run the cron job that calls all other jobs // Run the cron job that calls all other jobs
proc_run("php","include/cron.php"); proc_run("php","include/cron.php");
@ -57,11 +61,11 @@ function poller_run(&$argv, &$argc){
} }
} else } else
// Sleep two seconds before checking for running processes to avoid having too many workers // Sleep four seconds before checking for running processes again to avoid having too many workers
sleep(4); sleep(4);
// Checking number of workers // Checking number of workers
if (poller_too_much_workers()) if (poller_too_much_workers(2))
return; return;
$starttime = time(); $starttime = time();
@ -100,10 +104,10 @@ function poller_run(&$argv, &$argc){
$funcname=str_replace(".php", "", basename($argv[0]))."_run"; $funcname=str_replace(".php", "", basename($argv[0]))."_run";
if (function_exists($funcname)) { if (function_exists($funcname)) {
logger("Process ".getmypid().": ".$funcname." ".$r[0]["parameter"]); logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." ".$r[0]["parameter"]);
$funcname($argv, $argc); $funcname($argv, $argc);
logger("Process ".getmypid().": ".$funcname." - done"); logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." - done");
q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($r[0]["id"])); q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($r[0]["id"]));
} else } else
@ -114,13 +118,13 @@ function poller_run(&$argv, &$argc){
return; return;
// Count active workers and compare them with a maximum value that depends on the load // 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(3))
return; return;
} }
} }
function poller_too_much_workers() { function poller_too_much_workers($stage) {
$queues = get_config("system", "worker_queues"); $queues = get_config("system", "worker_queues");
@ -144,7 +148,7 @@ function poller_too_much_workers() {
$slope = $maxworkers / pow($maxsysload, $exponent); $slope = $maxworkers / pow($maxsysload, $exponent);
$queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent)); $queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
logger("Current load: ".$load." - maximum: ".$maxsysload." - current queues: ".$active." - maximum: ".$queues, LOGGER_DEBUG); logger("Current load stage ".$stage.": ".$load." - maximum: ".$maxsysload." - current queues: ".$active." - maximum: ".$queues, LOGGER_DEBUG);
} }