@@ -185,6 +185,7 @@ protected function readJob(string $endpoint, string $path, $tableName, int $init
185
185
$ dataGenerator = new DataGenerator ($ initialDataCount );
186
186
$ query = sprintf (Defaults::READ_QUERY , $ tableName );
187
187
$ table = $ ydb ->table ();
188
+ $ i = 0 ;
188
189
189
190
while (microtime (true ) <= $ startTime + $ time ) {
190
191
$ begin = microtime (true );
@@ -213,7 +214,8 @@ protected function readJob(string $endpoint, string $path, $tableName, int $init
213
214
$ table ->getLogger ()->error ($ e ->getMessage ());
214
215
Utils::metricFail ("read " , $ this ->queueId , $ attemps , get_class ($ e ), $ this ->getLatency ($ begin ));
215
216
} 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 );
217
219
usleep ($ delay > 0 ? $ delay : 1 );
218
220
}
219
221
}
@@ -225,6 +227,7 @@ protected function writeJob(string $endpoint, string $path, $tableName, int $ini
225
227
$ dataGenerator = new DataGenerator ($ initialDataCount );
226
228
$ query = sprintf (Defaults::WRITE_QUERY , $ tableName );
227
229
$ table = $ ydb ->table ();
230
+ $ i =0 ;
228
231
while (microtime (true ) <= $ startTime + $ time ) {
229
232
$ begin = microtime (true );
230
233
Utils::metricsStart ("write " , $ this ->queueId );
@@ -246,7 +249,8 @@ protected function writeJob(string $endpoint, string $path, $tableName, int $ini
246
249
$ table ->getLogger ()->error ($ e ->getMessage ());
247
250
Utils::metricFail ("write " , $ this ->queueId , $ attemps , get_class ($ e ), $ this ->getLatency ($ begin ));
248
251
} 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 );
250
254
usleep ($ delay > 0 ? $ delay : 1 );
251
255
}
252
256
}
@@ -323,6 +327,16 @@ protected function metricsJob(int $reportPeriod, float $startTime, int $time, st
323
327
}
324
328
}
325
329
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
+
326
340
protected $ errors = [
327
341
"GRPC_CANCELLED " ,
328
342
"GRPC_UNKNOWN " ,
@@ -362,9 +376,4 @@ protected function metricsJob(int $reportPeriod, float $startTime, int $time, st
362
376
"YDB_SESSION_BUSY "
363
377
];
364
378
365
- protected function getLatency ($ begin )
366
- {
367
- return (microtime (true ) - $ begin ) * 1000 ;
368
- }
369
-
370
379
}
0 commit comments