Prevent soon killings
This commit is contained in:
parent
99b86c9fd9
commit
7726353601
|
@ -113,6 +113,7 @@ function poller_run($argv, $argc){
|
|||
|
||||
// To avoid the quitting of multiple pollers only one poller at a time will execute the check
|
||||
if (Lock::set('poller_worker', 0)) {
|
||||
$stamp = (float)microtime(true);
|
||||
// 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);
|
||||
|
@ -125,6 +126,7 @@ function poller_run($argv, $argc){
|
|||
return;
|
||||
}
|
||||
Lock::remove('poller_worker');
|
||||
$poller_db_duration += (microtime(true) - $stamp);
|
||||
}
|
||||
|
||||
// Quit the poller once every 5 minutes
|
||||
|
@ -185,7 +187,7 @@ function poller_process_with_priority_active($priority) {
|
|||
* @return boolean "true" if further processing should be stopped
|
||||
*/
|
||||
function poller_execute($queue) {
|
||||
global $poller_db_duration;
|
||||
global $poller_db_duration, $poller_last_update;
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
@ -225,6 +227,19 @@ function poller_execute($queue) {
|
|||
$funcname = str_replace(".php", "", basename($argv[0]))."_run";
|
||||
|
||||
if (function_exists($funcname)) {
|
||||
|
||||
// We constantly update the "executed" date every minute to avoid being killed to soon
|
||||
if (!isset($poller_last_update)) {
|
||||
$poller_last_update = strtotime($queue["executed"]);
|
||||
}
|
||||
|
||||
$age = (time() - $poller_last_update) / 60;
|
||||
$poller_last_update = time();
|
||||
|
||||
if ($age > 1) {
|
||||
dba::update('workerqueue', array('executed' => datetime_convert()), array('pid' => $mypid, 'done' => false));
|
||||
}
|
||||
|
||||
poller_exec_function($queue, $funcname, $argv);
|
||||
|
||||
$stamp = (float)microtime(true);
|
||||
|
@ -650,18 +665,16 @@ function poller_passing_slow(&$highest_priority) {
|
|||
*
|
||||
* @return boolean Have we found something?
|
||||
*/
|
||||
function find_worker_processes($mypid = 0) {
|
||||
function find_worker_processes() {
|
||||
|
||||
if ($mypid == 0) {
|
||||
$mypid = getmypid();
|
||||
}
|
||||
$mypid = getmypid();
|
||||
|
||||
// Check if we should pass some low priority process
|
||||
$highest_priority = 0;
|
||||
$found = false;
|
||||
|
||||
// The higher the number of parallel workers, the more we prefetch to prevent concurring access
|
||||
$limit = Config::get("system", "worker_queues", 4) * 2;
|
||||
$limit = Config::get("system", "worker_queues", 4);
|
||||
$limit = Config::get('system', 'worker_fetch_limit', $limit);
|
||||
|
||||
if (poller_passing_slow($highest_priority)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user