Skip to content

Commit 3ee1884

Browse files
authored
Merge branch 'main' into add-logger-in-config
2 parents ccd41e2 + 46de874 commit 3ee1884

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

slo-workload/src/Commands/RunCommand.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ public function execute(string $endpoint, string $path, array $options)
106106
$initialDataCount = (int)($options["-initial-data-count"] ?? Defaults::GENERATOR_DATA_COUNT);
107107
$promPgw = ($options["-prom-pgw"] ?? Defaults::PROMETHEUS_PUSH_GATEWAY);
108108
$reportPeriod = (int)($options["-report-period"] ?? Defaults::PROMETHEUS_PUSH_PERIOD);
109-
$readForks = ((int)($options["-read-rps"] ?? Defaults::READ_RPS)) / Defaults::RPS_PER_READ_FORK;
109+
$readRps = ((int)($options["-read-rps"] ?? Defaults::READ_RPS));
110110
$readTimeout = (int)($options["-read-timeout"] ?? Defaults::READ_TIMEOUT);
111-
$writeForks = ((int)($options["-write-rps"] ?? Defaults::WRITE_RPS)) / Defaults::RPS_PER_WRITE_FORK;
111+
$writeRps = ((int)($options["-write-rps"] ?? Defaults::WRITE_RPS));
112112
$writeTimeout = (int)($options["-write-timeout"] ?? Defaults::WRITE_TIMEOUT);
113113
$time = (int)($options["-time"] ?? Defaults::READ_TIME);
114114
$shutdownTime = (int)($options["-shutdown-time"] ?? Defaults::SHUTDOWN_TIME);
@@ -125,12 +125,12 @@ public function execute(string $endpoint, string $path, array $options)
125125

126126
$readPIds = $this->forkJob(function (int $i) use ($endpoint, $path, $tableName, $initialDataCount, $time, $readTimeout, $shutdownTime, $startTime) {
127127
$this->readJob($endpoint, $path, $tableName, $initialDataCount, $time, $readTimeout, $i, $shutdownTime, $startTime);
128-
}, $readForks);
128+
}, Defaults::READ_FORKS);
129129
$pIds = array_merge($pIds, $readPIds);
130130

131131
$writePIds = $this->forkJob(function (int $i) use ($endpoint, $path, $tableName, $initialDataCount, $time, $writeTimeout, $shutdownTime, $startTime) {
132132
$this->writeJob($endpoint, $path, $tableName, $initialDataCount, $time, $writeTimeout, $i, $shutdownTime, $startTime);
133-
}, $writeForks);
133+
}, Defaults::WRITE_FORKS);
134134
$pIds = array_merge($pIds, $writePIds);
135135

136136
foreach ($pIds as $pid) {
@@ -185,7 +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;
188+
$table->createSession();
189189

190190
while (microtime(true) <= $startTime + $time) {
191191
$begin = microtime(true);
@@ -213,10 +213,6 @@ protected function readJob(string $endpoint, string $path, $tableName, int $init
213213
} catch (\Exception $e) {
214214
$table->getLogger()->error($e->getMessage());
215215
Utils::metricFail("read", $this->queueId, $attemps, get_class($e), $this->getLatencyMilliseconds($begin));
216-
} finally {
217-
$i++;
218-
$delay = $this->getDelayMicroseconds($startTime, Defaults::RPS_PER_READ_FORK, $i);
219-
usleep($delay > 0 ? $delay : 1);
220216
}
221217
}
222218
}
@@ -227,7 +223,7 @@ protected function writeJob(string $endpoint, string $path, $tableName, int $ini
227223
$dataGenerator = new DataGenerator($initialDataCount);
228224
$query = sprintf(Defaults::WRITE_QUERY, $tableName);
229225
$table = $ydb->table();
230-
$i=0;
226+
$table->createSession();
231227
while (microtime(true) <= $startTime + $time) {
232228
$begin = microtime(true);
233229
Utils::metricsStart("write", $this->queueId);
@@ -248,10 +244,6 @@ protected function writeJob(string $endpoint, string $path, $tableName, int $ini
248244
} catch (\Exception $e) {
249245
$table->getLogger()->error($e->getMessage());
250246
Utils::metricFail("write", $this->queueId, $attemps, get_class($e), $this->getLatencyMilliseconds($begin));
251-
} finally {
252-
$i++;
253-
$delay = $this->getDelayMicroseconds($startTime, Defaults::RPS_PER_WRITE_FORK, $i);
254-
usleep($delay > 0 ? $delay : 1);
255247
}
256248
}
257249
}
@@ -333,11 +325,6 @@ protected function getLatencyMilliseconds(float $begin): float
333325
return (microtime(true) - $begin) * 1000;
334326
}
335327

336-
protected function getDelayMicroseconds(float $startTime, int $rps, int $i): float
337-
{
338-
return $startTime * 1000000 + $i * 1000000 / $rps - microtime(true) * 1000000;
339-
}
340-
341328
protected $errors = [
342329
"GRPC_CANCELLED",
343330
"GRPC_UNKNOWN",

slo-workload/src/Defaults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class Defaults
1111

1212
const GENERATOR_DATA_COUNT = 1000;
1313

14-
const RPS_PER_READ_FORK = 50;
15-
const RPS_PER_WRITE_FORK = 25;
14+
const READ_FORKS = 3;
15+
const WRITE_FORKS = 1;
1616

1717
const READ_RPS = 1000;
1818
const READ_TIMEOUT = 70; // milliseconds

0 commit comments

Comments
 (0)