Fetching new queue tasks in a bulk to increase speed

This commit is contained in:
Michael 2017-06-13 13:51:25 +00:00
parent e232c683b6
commit 21e84e4d25

View file

@ -96,26 +96,26 @@ function poller_run($argv, $argc){
logger('Process execution failed, quitting.', LOGGER_DEBUG); logger('Process execution failed, quitting.', LOGGER_DEBUG);
return; return;
} }
// To avoid the quitting of multiple pollers only one poller at a time will execute the check
if (Lock::set('poller_worker', 0)) {
// Count active workers and compare them with a maximum value that depends on the load
if (poller_too_much_workers()) {
logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
return;
}
// Check free memory
if ($a->min_memory_reached()) {
logger('Memory limit reached, quitting.', LOGGER_DEBUG);
return;
}
Lock::remove('poller_worker');
}
} }
// Quit the poller once every hour // To avoid the quitting of multiple pollers only one poller at a time will execute the check
if (time() > ($starttime + 3600)) { if (Lock::set('poller_worker', 0)) {
// Count active workers and compare them with a maximum value that depends on the load
if (poller_too_much_workers()) {
logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
return;
}
// Check free memory
if ($a->min_memory_reached()) {
logger('Memory limit reached, quitting.', LOGGER_DEBUG);
return;
}
Lock::remove('poller_worker');
}
// Quit the poller once every 5 minutes
if (time() > ($starttime + 300)) {
logger('Process lifetime reached, quitting.', LOGGER_DEBUG); logger('Process lifetime reached, quitting.', LOGGER_DEBUG);
return; return;
} }
@ -610,7 +610,7 @@ function find_worker_processes() {
// Are there waiting processes with a higher priority than the currently highest? // Are there waiting processes with a higher priority than the currently highest?
$result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ? $result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
WHERE `executed` <= ? AND `priority` < ? WHERE `executed` <= ? AND `priority` < ?
ORDER BY `priority`, `created` LIMIT 1", ORDER BY `priority`, `created` LIMIT 5",
datetime_convert(), getmypid(), NULL_DATE, $highest_priority); datetime_convert(), getmypid(), NULL_DATE, $highest_priority);
if (dbm::is_result($result)) { if (dbm::is_result($result)) {
$found = (dba::num_rows($result) > 0); $found = (dba::num_rows($result) > 0);
@ -632,7 +632,7 @@ function find_worker_processes() {
// If there is no result (or we shouldn't pass lower processes) we check without priority limit // If there is no result (or we shouldn't pass lower processes) we check without priority limit
if (!$found) { if (!$found) {
$result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `executed` <= ? ORDER BY `priority`, `created` LIMIT 1", $result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `executed` <= ? ORDER BY `priority`, `created` LIMIT 5",
datetime_convert(), getmypid(), NULL_DATE); datetime_convert(), getmypid(), NULL_DATE);
if (dbm::is_result($result)) { if (dbm::is_result($result)) {
$found = (dba::num_rows($result) > 0); $found = (dba::num_rows($result) > 0);