It's faster without locks, gnarl ...
This commit is contained in:
parent
16df7715b9
commit
1301a29505
2 changed files with 3 additions and 15 deletions
|
@ -88,6 +88,7 @@ function poller_run($argv, $argc){
|
||||||
// If we got that queue entry we claim it for us
|
// If we got that queue entry we claim it for us
|
||||||
if (!poller_claim_process($r[0])) {
|
if (!poller_claim_process($r[0])) {
|
||||||
Lock::remove('poller_fetch_worker');
|
Lock::remove('poller_fetch_worker');
|
||||||
|
usleep(rand(0, 200000));
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// Fetch all workerqueue data while the table is still locked
|
// Fetch all workerqueue data while the table is still locked
|
||||||
|
@ -95,7 +96,6 @@ function poller_run($argv, $argc){
|
||||||
$entries = poller_total_entries();
|
$entries = poller_total_entries();
|
||||||
$top_priority = poller_highest_priority();
|
$top_priority = poller_highest_priority();
|
||||||
$high_running = poller_process_with_priority_active($top_priority);
|
$high_running = poller_process_with_priority_active($top_priority);
|
||||||
Lock::remove('poller_fetch_worker');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// To avoid the quitting of multiple pollers only one poller at a time will execute the check
|
// To avoid the quitting of multiple pollers only one poller at a time will execute the check
|
||||||
|
@ -616,10 +616,6 @@ function poller_worker_process() {
|
||||||
// Check if we should pass some low priority process
|
// Check if we should pass some low priority process
|
||||||
$highest_priority = 0;
|
$highest_priority = 0;
|
||||||
|
|
||||||
if (!Lock::set('poller_fetch_worker')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (poller_passing_slow($highest_priority)) {
|
if (poller_passing_slow($highest_priority)) {
|
||||||
// Are there waiting processes with a higher priority than the currently highest?
|
// Are there waiting processes with a higher priority than the currently highest?
|
||||||
$r = q("SELECT * FROM `workerqueue`
|
$r = q("SELECT * FROM `workerqueue`
|
||||||
|
@ -647,11 +643,6 @@ function poller_worker_process() {
|
||||||
$r = q("SELECT * FROM `workerqueue` WHERE `executed` <= '%s' ORDER BY `priority`, `created` LIMIT 1", dbesc(NULL_DATE));
|
$r = q("SELECT * FROM `workerqueue` WHERE `executed` <= '%s' ORDER BY `priority`, `created` LIMIT 1", dbesc(NULL_DATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We only unlock the tables here, when we got no data
|
|
||||||
if (!dbm::is_result($r)) {
|
|
||||||
Lock::remove('poller_fetch_worker');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,6 @@ class Lock {
|
||||||
|
|
||||||
$memcache = self::connectMemcache();
|
$memcache = self::connectMemcache();
|
||||||
if (is_object($memcache)) {
|
if (is_object($memcache)) {
|
||||||
$wait_sec = 0.2;
|
|
||||||
$cachekey = get_app()->get_hostname().";lock:".$fn_name;
|
$cachekey = get_app()->get_hostname().";lock:".$fn_name;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -82,15 +81,13 @@ class Lock {
|
||||||
dba::unlock();
|
dba::unlock();
|
||||||
|
|
||||||
if (!$got_lock && ($timeout > 0)) {
|
if (!$got_lock && ($timeout > 0)) {
|
||||||
usleep($wait_sec * 1000000);
|
usleep(rand(10000, 200000));
|
||||||
}
|
}
|
||||||
} while (!$got_lock && ((time() - $start) < $timeout));
|
} while (!$got_lock && ((time() - $start) < $timeout));
|
||||||
|
|
||||||
return $got_lock;
|
return $got_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
$wait_sec = 2;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
dba::lock('locks');
|
dba::lock('locks');
|
||||||
$lock = dba::select('locks', array('locked', 'pid'), array('name' => $fn_name), array('limit' => 1));
|
$lock = dba::select('locks', array('locked', 'pid'), array('name' => $fn_name), array('limit' => 1));
|
||||||
|
@ -118,7 +115,7 @@ class Lock {
|
||||||
dba::unlock();
|
dba::unlock();
|
||||||
|
|
||||||
if (!$got_lock && ($timeout > 0)) {
|
if (!$got_lock && ($timeout > 0)) {
|
||||||
sleep($wait_sec);
|
usleep(rand(100000, 2000000));
|
||||||
}
|
}
|
||||||
} while (!$got_lock && ((time() - $start) < $timeout));
|
} while (!$got_lock && ((time() - $start) < $timeout));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue