Fixings
- fixed test for semaphore - fixed some issues - changed namespace in Tests back to "src/" - changed namings
This commit is contained in:
parent
906bb25972
commit
e41e7d2edd
15 changed files with 67 additions and 65 deletions
|
@ -16,7 +16,7 @@ class MemcachedCacheDriver extends BaseObject implements IMemoryCacheDriver
|
|||
use TraitCompareDelete;
|
||||
|
||||
/**
|
||||
* @var Memcached
|
||||
* @var \Memcached
|
||||
*/
|
||||
private $memcached;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ use Friendica\Core\Cache;
|
|||
class RedisCacheDriver extends BaseObject implements IMemoryCacheDriver
|
||||
{
|
||||
/**
|
||||
* @var Redis
|
||||
* @var \Redis
|
||||
*/
|
||||
private $redis;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
* @file src/Util/Lock.php
|
||||
*/
|
||||
|
||||
namespace Friendica\Core;
|
||||
|
||||
/**
|
||||
|
@ -115,20 +113,20 @@ class Lock
|
|||
*
|
||||
* @return boolean Was the lock successful?
|
||||
*/
|
||||
public static function acquireLock($key, $timeout = 120)
|
||||
public static function acquire($key, $timeout = 120)
|
||||
{
|
||||
return self::getDriver()->acquire($key, $timeout);
|
||||
return self::getDriver()->acquireLock($key, $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Releases a lock if it was set by us
|
||||
*
|
||||
* @param string $key Name of the lock
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public static function releaseLock($key)
|
||||
public static function release($key)
|
||||
{
|
||||
return self::getDriver()->release($key);
|
||||
self::getDriver()->releaseLock($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,7 +52,7 @@ abstract class AbstractLockDriver extends BaseObject implements ILockDriver
|
|||
*/
|
||||
public function releaseAll() {
|
||||
foreach ($this->acquiredLocks as $acquiredLock => $hasLock) {
|
||||
$this->release($acquiredLock);
|
||||
$this->releaseLock($acquiredLock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class CacheLockDriver extends AbstractLockDriver
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquire($key, $timeout = 120)
|
||||
public function acquireLock($key, $timeout = 120)
|
||||
{
|
||||
$got_lock = false;
|
||||
$start = time();
|
||||
|
@ -60,7 +60,7 @@ class CacheLockDriver extends AbstractLockDriver
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function release($key)
|
||||
public function releaseLock($key)
|
||||
{
|
||||
$cachekey = self::getCacheKey($key);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class DatabaseLockDriver extends AbstractLockDriver
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquire($key, $timeout = 120)
|
||||
public function acquireLock($key, $timeout = 120)
|
||||
{
|
||||
$got_lock = false;
|
||||
$start = time();
|
||||
|
@ -55,7 +55,7 @@ class DatabaseLockDriver extends AbstractLockDriver
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function release($key)
|
||||
public function releaseLock($key)
|
||||
{
|
||||
dba::delete('locks', ['name' => $key, 'pid' => getmypid()]);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ interface ILockDriver
|
|||
*
|
||||
* @return boolean Was the lock successful?
|
||||
*/
|
||||
public function acquire($key, $timeout = 120);
|
||||
public function acquireLock($key, $timeout = 120);
|
||||
|
||||
/**
|
||||
* Releases a lock if it was set by us
|
||||
|
@ -35,7 +35,7 @@ interface ILockDriver
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function release($key);
|
||||
public function releaseLock($key);
|
||||
|
||||
/**
|
||||
* Releases all lock that were set by us
|
||||
|
|
|
@ -20,7 +20,7 @@ class SemaphoreLockDriver extends AbstractLockDriver
|
|||
{
|
||||
$temp = get_temppath();
|
||||
|
||||
$file = $temp.'/'.$key.'.sem';
|
||||
$file = $temp . '/' . $key . '.sem';
|
||||
|
||||
if (!file_exists($file)) {
|
||||
file_put_contents($file, $key);
|
||||
|
@ -33,7 +33,7 @@ class SemaphoreLockDriver extends AbstractLockDriver
|
|||
*
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquire($key, $timeout = 120)
|
||||
public function acquireLock($key, $timeout = 120)
|
||||
{
|
||||
self::$semaphore[$key] = sem_get(self::semaphoreKey($key));
|
||||
if (self::$semaphore[$key]) {
|
||||
|
@ -49,7 +49,7 @@ class SemaphoreLockDriver extends AbstractLockDriver
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function release($key)
|
||||
public function releaseLock($key)
|
||||
{
|
||||
if (empty(self::$semaphore[$key])) {
|
||||
return false;
|
||||
|
@ -66,6 +66,6 @@ class SemaphoreLockDriver extends AbstractLockDriver
|
|||
*/
|
||||
public function isLocked($key)
|
||||
{
|
||||
return @sem_get(self::$semaphore[$key]) !== false;
|
||||
return isset(self::$semaphore[$key]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*/
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Lock;
|
||||
use dba;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\Process;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Network;
|
||||
use dba;
|
||||
|
||||
require_once 'include/dba.php';
|
||||
|
||||
|
@ -108,16 +104,16 @@ class Worker
|
|||
}
|
||||
|
||||
// If possible we will fetch new jobs for this worker
|
||||
if (!$refetched && Lock::acquireLock('worker_process', 0)) {
|
||||
if (!$refetched && Lock::acquire('worker_process', 0)) {
|
||||
$stamp = (float)microtime(true);
|
||||
$refetched = self::findWorkerProcesses($passing_slow);
|
||||
self::$db_duration += (microtime(true) - $stamp);
|
||||
Lock::releaseLock('worker_process');
|
||||
Lock::release('worker_process');
|
||||
}
|
||||
}
|
||||
|
||||
// To avoid the quitting of multiple workers only one worker at a time will execute the check
|
||||
if (Lock::acquireLock('worker', 0)) {
|
||||
if (Lock::acquire('worker', 0)) {
|
||||
$stamp = (float)microtime(true);
|
||||
// Count active workers and compare them with a maximum value that depends on the load
|
||||
if (self::tooMuchWorkers()) {
|
||||
|
@ -130,7 +126,7 @@ class Worker
|
|||
logger('Memory limit reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
Lock::releaseLock('worker');
|
||||
Lock::release('worker');
|
||||
self::$db_duration += (microtime(true) - $stamp);
|
||||
}
|
||||
|
||||
|
@ -883,7 +879,7 @@ class Worker
|
|||
dba::close($r);
|
||||
|
||||
$stamp = (float)microtime(true);
|
||||
if (!Lock::acquireLock('worker_process')) {
|
||||
if (!Lock::acquire('worker_process')) {
|
||||
return false;
|
||||
}
|
||||
self::$lock_duration = (microtime(true) - $stamp);
|
||||
|
@ -892,7 +888,7 @@ class Worker
|
|||
$found = self::findWorkerProcesses($passing_slow);
|
||||
self::$db_duration += (microtime(true) - $stamp);
|
||||
|
||||
Lock::releaseLock('worker_process');
|
||||
Lock::release('worker_process');
|
||||
|
||||
if ($found) {
|
||||
$r = dba::select('workerqueue', [], ['pid' => getmypid(), 'done' => false]);
|
||||
|
@ -1097,13 +1093,13 @@ class Worker
|
|||
}
|
||||
|
||||
// If there is a lock then we don't have to check for too much worker
|
||||
if (!Lock::acquireLock('worker', 0)) {
|
||||
if (!Lock::acquire('worker', 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If there are already enough workers running, don't fork another one
|
||||
$quit = self::tooMuchWorkers();
|
||||
Lock::releaseLock('worker');
|
||||
Lock::release('worker');
|
||||
|
||||
if ($quit) {
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue