Some bugfixes and misc
This commit is contained in:
@@ -12,6 +12,8 @@ class PerceptronLimitedEpochEventBuffer implements IPerceptronIterationEventBuff
|
||||
|
||||
private bool $shouldBroadcastEpoch = false;
|
||||
|
||||
private ?float $lastBroadcastAt = null;
|
||||
|
||||
public function __construct(
|
||||
private string $sessionId,
|
||||
private string $trainingId,
|
||||
@@ -24,7 +26,9 @@ class PerceptronLimitedEpochEventBuffer implements IPerceptronIterationEventBuff
|
||||
return;
|
||||
}
|
||||
|
||||
$this->waitForBroadcastInterval();
|
||||
event(new PerceptronTrainingIteration($this->data, $this->sessionId, $this->trainingId));
|
||||
$this->lastBroadcastAt = microtime(true);
|
||||
$this->data = [];
|
||||
}
|
||||
|
||||
@@ -57,8 +61,22 @@ class PerceptronLimitedEpochEventBuffer implements IPerceptronIterationEventBuff
|
||||
private function payloadExceedsLimit(): bool
|
||||
{
|
||||
return strlen(json_encode([
|
||||
'iterations' => $this->data,
|
||||
'iterations' => PerceptronTrainingIteration::normalizeForJson($this->data),
|
||||
'trainingId' => $this->trainingId,
|
||||
], JSON_THROW_ON_ERROR)) > config('broadcasting.broadcast_max_payload_size');
|
||||
}
|
||||
|
||||
private function waitForBroadcastInterval(): void
|
||||
{
|
||||
if ($this->lastBroadcastAt === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$minimumInterval = config('perceptron.broadcast_minimum_interval_ms') / 1000;
|
||||
$remainingInterval = $minimumInterval - (microtime(true) - $this->lastBroadcastAt);
|
||||
|
||||
if ($remainingInterval > 0) {
|
||||
usleep((int) ceil($remainingInterval * 1_000_000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user