8
8
#include " transactions.h"
9
9
10
10
#include < ydb/public/lib/ydb_cli/commands/ydb_command.h>
11
+ #include < ydb/public/lib/ydb_cli/common/interactive.h>
11
12
#include < ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/query/client.h>
12
13
13
14
#include < library/cpp/logger/log.h>
@@ -216,14 +217,27 @@ TPCCRunner::TPCCRunner(const NConsoleClient::TClientCommand::TConfig& connection
216
217
std::exit (1 );
217
218
}
218
219
219
- const size_t networkThreadCount = NConsoleClient::TYdbCommand::GetNetworkThreadNum (ConnectionConfig);
220
- const size_t maxTerminalThreadCount = cpuCount > networkThreadCount ? cpuCount - networkThreadCount : 1 ;
220
+ if (Config.WarehouseCount == 0 ) {
221
+ std::cerr << " Specified zero warehouses" << std::endl;
222
+ std::exit (1 );
223
+ }
221
224
222
225
const size_t terminalsCount = Config.WarehouseCount * TERMINALS_PER_WAREHOUSE;
223
226
224
- // we might consider using less than maxTerminalThreads
225
- const size_t threadCount = Config.ThreadCount == 0 ?
226
- std::min (maxTerminalThreadCount, terminalsCount) : Config.ThreadCount ;
227
+ size_t threadCount = 0 ;
228
+ if (Config.ThreadCount == 0 ) {
229
+ // here we calculate max possible efficient thread number
230
+ const size_t networkThreadCount = NConsoleClient::TYdbCommand::GetNetworkThreadNum (ConnectionConfig);
231
+ const size_t maxTerminalThreadCount = cpuCount > networkThreadCount ? cpuCount - networkThreadCount : 1 ;
232
+ threadCount = std::min (maxTerminalThreadCount, terminalsCount);
233
+
234
+ // usually this allows to lower number of threads
235
+ const size_t recommendedThreadCount =
236
+ (Config.WarehouseCount + WAREHOUSES_PER_CPU_CORE - 1 ) / WAREHOUSES_PER_CPU_CORE;
237
+ threadCount = std::min (threadCount, recommendedThreadCount);
238
+ } else {
239
+ threadCount = Config.ThreadCount ;
240
+ }
227
241
228
242
// The number of terminals might be hundreds of thousands.
229
243
// For now, we don't have more than 32 network threads (check TYdbCommand::GetNetworkThreadNum()),
@@ -351,7 +365,7 @@ void TPCCRunner::Join() {
351
365
}
352
366
353
367
void TPCCRunner::RunSync () {
354
- Config.SetDisplayUpdateInterval ();
368
+ Config.SetDisplay ();
355
369
356
370
Clock::time_point now = Clock::now ();
357
371
@@ -363,14 +377,14 @@ void TPCCRunner::RunSync() {
363
377
// We don't want to start all terminals at the same time, because then there will be
364
378
// a huge queue of ready terminals, which we can't handle
365
379
bool forcedWarmup = false ;
366
- int minWarmupSeconds = Terminals.size () * MinWarmupPerTerminal.count () / 1000 + 1 ;
367
- int minWarmupMinutes = (minWarmupSeconds + 59 ) / 60 ;
368
- int warmupMinutes;
369
- if (Config.WarmupMinutes < minWarmupMinutes) {
380
+ uint32_t minWarmupSeconds = Terminals.size () * MinWarmupPerTerminal.count () / 1000 + 1 ;
381
+ uint32_t minWarmupMinutes = (minWarmupSeconds + 59 ) / 60 ;
382
+ uint32_t warmupMinutes;
383
+ if (Config.WarmupDuration . Minutes () < minWarmupMinutes) {
370
384
forcedWarmup = true ; // we must print log message later after display update
371
385
warmupMinutes = minWarmupMinutes;
372
386
} else {
373
- warmupMinutes = Config.WarmupMinutes ;
387
+ warmupMinutes = Config.WarmupDuration . Minutes () ;
374
388
}
375
389
376
390
WarmupStartTs = Clock::now ();
@@ -411,14 +425,14 @@ void TPCCRunner::RunSync() {
411
425
412
426
StopWarmup.store (true , std::memory_order_relaxed);
413
427
414
- LOG_I (" Measuring during " << Config.RunMinutes << " minutes " );
428
+ LOG_I (" Measuring during " << Config.RunDuration );
415
429
416
430
MeasurementsStartTs = Clock::now ();
417
431
418
432
// reset statistics
419
433
LastStatisticsSnapshot = std::make_unique<TAllStatistics>(PerThreadTerminalStats.size (), MeasurementsStartTs);
420
434
421
- StopDeadline = MeasurementsStartTs + std::chrono::minutes (Config.RunMinutes );
435
+ StopDeadline = MeasurementsStartTs + std::chrono::seconds (Config.RunDuration . Seconds () );
422
436
while (!GetGlobalInterruptSource ().stop_requested ()) {
423
437
if (now >= StopDeadline) {
424
438
break ;
@@ -469,10 +483,12 @@ void TPCCRunner::UpdateDisplayTextMode(const TCalculatedStatusData& data) {
469
483
ss << std::endl << " Efficiency: " << std::setprecision (1 ) << data.Efficiency << " % | "
470
484
<< " tpmC: " << std::setprecision (1 ) << data.Tpmc ;
471
485
472
- std::cout << ss.str ();
486
+ LOG_I ( ss.str () );
473
487
474
488
// Per thread statistics (two columns)
475
- std::cout << " \n Per thread statistics:" << std::endl;
489
+
490
+ std::stringstream debugSs;
491
+ debugSs << " \n Per thread statistics:" << std::endl;
476
492
477
493
size_t threadCount = LastStatisticsSnapshot->StatVec .size ();
478
494
size_t halfCount = (threadCount + 1 ) / 2 ;
@@ -487,10 +503,10 @@ void TPCCRunner::UpdateDisplayTextMode(const TCalculatedStatusData& data) {
487
503
<< std::setw (15 ) << " queue p90, ms" ;
488
504
489
505
// Print headers side by side
490
- std::cout << threadsHeader.str () << " | " << threadsHeader.str () << std::endl;
506
+ debugSs << threadsHeader.str () << " | " << threadsHeader.str () << std::endl;
491
507
492
508
size_t totalWidth = threadsHeader.str ().length () * 2 + 3 ;
493
- std::cout << std::string (totalWidth, ' -' ) << std::endl;
509
+ debugSs << std::string (totalWidth, ' -' ) << std::endl;
494
510
495
511
// Print thread data in two columns
496
512
for (size_t i = 0 ; i < halfCount; ++i) {
@@ -525,13 +541,15 @@ void TPCCRunner::UpdateDisplayTextMode(const TCalculatedStatusData& data) {
525
541
rightLine << std::string (threadsHeader.str ().length (), ' ' );
526
542
}
527
543
528
- std::cout << leftLine.str () << " | " << rightLine.str () << std::endl;
544
+ debugSs << leftLine.str () << " | " << rightLine.str () << std::endl;
529
545
}
530
- std::cout << std::string (totalWidth, ' -' ) << std::endl;
546
+ debugSs << std::string (totalWidth, ' -' ) << std::endl;
531
547
532
548
// Transaction statistics
533
- std::cout << " \n\n " ;
534
- PrintTransactionStatisticsPretty (std::cout);
549
+ debugSs << " \n " ;
550
+ PrintTransactionStatisticsPretty (debugSs);
551
+
552
+ LOG_D (debugSs.str ());
535
553
}
536
554
537
555
void TPCCRunner::UpdateDisplayTuiMode (const TCalculatedStatusData& data) {
@@ -903,6 +921,31 @@ void TPCCRunner::PrintFinalResultPretty() {
903
921
904
922
// -----------------------------------------------------------------------------
905
923
924
+ void TRunConfig::SetDisplay () {
925
+ if (NoTui) {
926
+ DisplayMode = EDisplayMode::Text;
927
+ } else {
928
+ if (NConsoleClient::IsStdoutInteractive ()) {
929
+ DisplayMode = EDisplayMode::Tui;
930
+ } else {
931
+ DisplayMode = EDisplayMode::Text;
932
+ }
933
+ }
934
+
935
+ switch (DisplayMode) {
936
+ case EDisplayMode::None:
937
+ return ;
938
+ case EDisplayMode::Text:
939
+ DisplayUpdateInterval = DisplayUpdateTextInterval;
940
+ return ;
941
+ case EDisplayMode::Tui:
942
+ DisplayUpdateInterval = DisplayUpdateTuiInterval;
943
+ return ;
944
+ }
945
+ }
946
+
947
+ // -----------------------------------------------------------------------------
948
+
906
949
void RunSync (const NConsoleClient::TClientCommand::TConfig& connectionConfig, const TRunConfig& runConfig) {
907
950
TPCCRunner runner (connectionConfig, runConfig);
908
951
runner.RunSync ();
0 commit comments