Sync: Implement Benchmark for the Sync process
Note: This disables redirect-on-success for the forms, so you can see the benchmark result.
This commit is contained in:
parent
fb3dc92b36
commit
c4a95fd64e
|
@ -57,7 +57,6 @@ class SyncCheckForm extends DirectorForm
|
||||||
$this->setSuccessMessage(
|
$this->setSuccessMessage(
|
||||||
$this->translate('Nothing would change, this rule is still in sync')
|
$this->translate('Nothing would change, this rule is still in sync')
|
||||||
);
|
);
|
||||||
parent::onSuccess();
|
|
||||||
} else {
|
} else {
|
||||||
$this->addError($this->translate('Checking this sync rule failed'));
|
$this->addError($this->translate('Checking this sync rule failed'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,5 @@ class SyncRunForm extends DirectorForm
|
||||||
} else {
|
} else {
|
||||||
$this->addError($this->translate('Synchronization failed'));
|
$this->addError($this->translate('Synchronization failed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::onSuccess();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Icinga\Module\Director\Import;
|
namespace Icinga\Module\Director\Import;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Icinga\Application\Benchmark;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Module\Director\Application\MemoryLimit;
|
use Icinga\Module\Director\Application\MemoryLimit;
|
||||||
use Icinga\Module\Director\Data\Db\DbObject;
|
use Icinga\Module\Director\Data\Db\DbObject;
|
||||||
|
@ -173,6 +174,7 @@ class Sync
|
||||||
{
|
{
|
||||||
$this->run = SyncRun::start($this->rule);
|
$this->run = SyncRun::start($this->rule);
|
||||||
$this->runStartTime = microtime(true);
|
$this->runStartTime = microtime(true);
|
||||||
|
Benchmark::measure('Starting sync');
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +262,8 @@ class Sync
|
||||||
*/
|
*/
|
||||||
protected function fetchImportedData()
|
protected function fetchImportedData()
|
||||||
{
|
{
|
||||||
|
Benchmark::measure('Begin loading imported data');
|
||||||
|
|
||||||
$this->imported = array();
|
$this->imported = array();
|
||||||
|
|
||||||
$sourceKeyPattern = $this->rule->getSourceKeyPattern();
|
$sourceKeyPattern = $this->rule->getSourceKeyPattern();
|
||||||
|
@ -293,8 +297,10 @@ class Sync
|
||||||
$usedColumns[$column] = $column;
|
$usedColumns[$column] = $column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Benchmark::measure(sprintf('Done pre-processing columns for source %s', $source->source_name));
|
||||||
|
|
||||||
$rows = $run->fetchRows($usedColumns);
|
$rows = $run->fetchRows($usedColumns);
|
||||||
|
Benchmark::measure(sprintf('Fetched source %s', $source->source_name));
|
||||||
|
|
||||||
$this->imported[$sourceId] = array();
|
$this->imported[$sourceId] = array();
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
|
@ -335,6 +341,8 @@ class Sync
|
||||||
unset($rows);
|
unset($rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Benchmark::measure('Done loading imported data');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,6 +376,8 @@ class Sync
|
||||||
|
|
||||||
protected function loadExistingObjects()
|
protected function loadExistingObjects()
|
||||||
{
|
{
|
||||||
|
Benchmark::measure('Begin loading existing objects');
|
||||||
|
|
||||||
// TODO: Make object_type (template, object...) and object_name mandatory?
|
// TODO: Make object_type (template, object...) and object_name mandatory?
|
||||||
if ($this->rule->hasCombinedKey()) {
|
if ($this->rule->hasCombinedKey()) {
|
||||||
$this->objects = array();
|
$this->objects = array();
|
||||||
|
@ -412,6 +422,8 @@ class Sync
|
||||||
$this->removeForeignListEntries();
|
$this->removeForeignListEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Benchmark::measure('Done loading existing objects');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,6 +606,8 @@ class Sync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Benchmark::measure('Begin preparing updated objects');
|
||||||
|
|
||||||
/** @var DbObject|IcingaObject $object */
|
/** @var DbObject|IcingaObject $object */
|
||||||
foreach ($newObjects as $key => $object) {
|
foreach ($newObjects as $key => $object) {
|
||||||
if (array_key_exists($key, $this->objects)) {
|
if (array_key_exists($key, $this->objects)) {
|
||||||
|
@ -619,6 +633,8 @@ class Sync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Benchmark::measure('Done preparing updated objects');
|
||||||
|
|
||||||
$noAction = array();
|
$noAction = array();
|
||||||
foreach ($this->rule->purgeStrategy()->listObjectsToPurge() as $key) {
|
foreach ($this->rule->purgeStrategy()->listObjectsToPurge() as $key) {
|
||||||
if (array_key_exists($key, $newObjects)) {
|
if (array_key_exists($key, $newObjects)) {
|
||||||
|
@ -634,6 +650,8 @@ class Sync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Benchmark::measure('Done marking objects for purge');
|
||||||
|
|
||||||
foreach ($this->objects as $key => $object) {
|
foreach ($this->objects as $key => $object) {
|
||||||
if (! $object->hasBeenModified() && ! $object->shouldBeRemoved()) {
|
if (! $object->hasBeenModified() && ! $object->shouldBeRemoved()) {
|
||||||
$noAction[] = $key;
|
$noAction[] = $key;
|
||||||
|
@ -646,6 +664,8 @@ class Sync
|
||||||
|
|
||||||
$this->isPrepared = true;
|
$this->isPrepared = true;
|
||||||
|
|
||||||
|
Benchmark::measure('Done preparing objects');
|
||||||
|
|
||||||
return $this->objects;
|
return $this->objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -657,6 +677,8 @@ class Sync
|
||||||
*/
|
*/
|
||||||
public function apply()
|
public function apply()
|
||||||
{
|
{
|
||||||
|
Benchmark::measure('Begin applying objects');
|
||||||
|
|
||||||
$objects = $this->prepare();
|
$objects = $this->prepare();
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
$dba = $db->getDbAdapter();
|
$dba = $db->getDbAdapter();
|
||||||
|
@ -711,6 +733,8 @@ class Sync
|
||||||
$this->run->set('duration_ms', (int) round(
|
$this->run->set('duration_ms', (int) round(
|
||||||
(microtime(true) - $this->runStartTime) * 1000
|
(microtime(true) - $this->runStartTime) * 1000
|
||||||
))->store();
|
))->store();
|
||||||
|
|
||||||
|
Benchmark::measure('Done applying objects');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$dba->rollBack();
|
$dba->rollBack();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue