Skip to content

Commit 4d0e986

Browse files
committed
Refactor BulkInsertObjectStore::hasRaisedTimeout to avoid that some to avoid a huge delay (around 30 seconds) from reading objects from the queue and writing objects into the database
1 parent 8850221 commit 4d0e986

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

bin/StatusengineWorker.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@
5252

5353
if ($Config->isRedisEnabled() || $Config->storeLiveDateInArchive()) {
5454
for ($i = 0; $i < $Config->getNumberOfServicestatusWorkers(); $i++) {
55-
$Syslog->info('Fork new service status worker');
56-
$ServicestatusChild = new Statusengine\ServicestatusChild(
57-
$Config,
58-
$ParentPid,
59-
$Syslog
60-
);
61-
$servicestatusChildPid = $ServicestatusChild->fork();
62-
$pids[] = $servicestatusChildPid;
55+
$pids[] = $ChildFactory->forkServicestatusChild();
6356
}
6457
}
6558

src/Backends/MySQL/MySQL.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ public function deleteNodeByName($nodeName) {
230230
}
231231

232232
public function dispatch() {
233+
/*$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
234+
235+
if($bt[3]['function'] === 'forkServicestatusChild'){
236+
// echo "============ START ========== \n";
237+
// foreach($bt as $line){
238+
// printf("File: %s Line: %s function: %s\n", $line['file'], $line['line'], $line['function']);
239+
// }
240+
// echo "============ END ========== \n\n";
241+
}*/
242+
243+
233244
if ($this->BulkInsertObjectStore->hasRaisedTimeout()) {
234245
try {
235246
$type = $this->BulkInsertObjectStore->getStoredType();

src/BulkInsertObjectStore.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BulkInsertObjectStore {
3838
/**
3939
* @var int
4040
*/
41-
private $lastAction;
41+
private $lastFlush;
4242

4343
/**
4444
* @var int
@@ -66,13 +66,12 @@ public function __construct($maxDelay, $maxObjects) {
6666

6767
$this->maxObjects = $maxObjects;
6868
$this->maxDelay = $maxDelay;
69-
$this->lastAction = 0;
69+
$this->lastFlush = 0;
7070
}
7171

7272
public function addObject($object) {
7373
$this->objects[] = $object;
7474
$this->objectCount++;
75-
$this->lastAction = time();
7675
}
7776

7877
/**
@@ -89,7 +88,7 @@ public function getObjects() {
8988
public function reset() {
9089
$this->objects = [];
9190
$this->objectCount = 0;
92-
$this->lastAction = time();
91+
$this->lastFlush = time();
9392
}
9493

9594
/**
@@ -107,11 +106,12 @@ public function getStoredType(){
107106
* @return bool
108107
*/
109108
public function hasRaisedTimeout() {
110-
if ($this->objectCount >= $this->maxObjects || time() - $this->lastAction > $this->maxDelay) {
111-
if ($this->objectCount > 0) {
109+
if ($this->objectCount > 0) {
110+
if ($this->objectCount >= $this->maxObjects || (time() - $this->lastFlush) > $this->maxDelay) {
112111
return true;
113112
}
114113
}
114+
115115
return false;
116116
}
117117

0 commit comments

Comments
 (0)