Skip to content

Commit da6131e

Browse files
author
Илья
committed
Refactor delay
1 parent 5e003f9 commit da6131e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

slo-workload/src/Commands/RunCommand.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ protected function readJob(string $endpoint, string $path, $tableName, int $init
185185
$dataGenerator = new DataGenerator($initialDataCount);
186186
$query = sprintf(Defaults::READ_QUERY, $tableName);
187187
$table = $ydb->table();
188+
$i = 0;
188189

189190
while (microtime(true) <= $startTime + $time) {
190191
$begin = microtime(true);
@@ -213,7 +214,8 @@ protected function readJob(string $endpoint, string $path, $tableName, int $init
213214
$table->getLogger()->error($e->getMessage());
214215
Utils::metricFail("read", $this->queueId, $attemps, get_class($e), $this->getLatency($begin));
215216
} finally {
216-
$delay = $begin * 1e6 + 1e6 / Defaults::RPS_PER_WRITE_FORK - microtime(true) * 1e6;
217+
$i++;
218+
$delay = $this->getDelay($startTime, Defaults::RPS_PER_READ_FORK, $i);
217219
usleep($delay > 0 ? $delay : 1);
218220
}
219221
}
@@ -225,6 +227,7 @@ protected function writeJob(string $endpoint, string $path, $tableName, int $ini
225227
$dataGenerator = new DataGenerator($initialDataCount);
226228
$query = sprintf(Defaults::WRITE_QUERY, $tableName);
227229
$table = $ydb->table();
230+
$i=0;
228231
while (microtime(true) <= $startTime + $time) {
229232
$begin = microtime(true);
230233
Utils::metricsStart("write", $this->queueId);
@@ -246,7 +249,8 @@ protected function writeJob(string $endpoint, string $path, $tableName, int $ini
246249
$table->getLogger()->error($e->getMessage());
247250
Utils::metricFail("write", $this->queueId, $attemps, get_class($e), $this->getLatency($begin));
248251
} finally {
249-
$delay = $begin * 1e6 + 1e6 / Defaults::RPS_PER_READ_FORK - microtime(true)* 1e6;
252+
$i++;
253+
$delay = $this->getDelay($startTime, Defaults::RPS_PER_WRITE_FORK, $i);
250254
usleep($delay > 0 ? $delay : 1);
251255
}
252256
}
@@ -323,6 +327,16 @@ protected function metricsJob(int $reportPeriod, float $startTime, int $time, st
323327
}
324328
}
325329

330+
protected function getLatency($begin)
331+
{
332+
return (microtime(true) - $begin) * 1000;
333+
}
334+
335+
protected function getDelay(float $startTime, int $rps, int $i)
336+
{
337+
return $startTime * 1000000 + $i * 1000000 / $rps - microtime(true) * 1000000;
338+
}
339+
326340
protected $errors = [
327341
"GRPC_CANCELLED",
328342
"GRPC_UNKNOWN",
@@ -362,9 +376,4 @@ protected function metricsJob(int $reportPeriod, float $startTime, int $time, st
362376
"YDB_SESSION_BUSY"
363377
];
364378

365-
protected function getLatency($begin)
366-
{
367-
return (microtime(true) - $begin) * 1000;
368-
}
369-
370379
}

0 commit comments

Comments
 (0)