From bd79c91a20d2711e623cb7eacd653847f8b61c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3?= <150132506+iddqdex@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:19:49 +0300 Subject: [PATCH] Use threadsafe randomizer (#13754) --- ydb/library/workload/log/log.cpp | 15 ++------------- ydb/library/workload/log/log.h | 5 ----- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/ydb/library/workload/log/log.cpp b/ydb/library/workload/log/log.cpp index 4f6c214972fe..f2c540a68291 100644 --- a/ydb/library/workload/log/log.cpp +++ b/ydb/library/workload/log/log.cpp @@ -1,17 +1,9 @@ #include "log.h" #include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include - namespace NYdbWorkload { namespace NLog { @@ -22,8 +14,6 @@ using TRow = TLogGenerator::TRow; TLogGenerator::TLogGenerator(const TLogWorkloadParams* params) : TBase(params) , TotalColumnsCnt(1 + Params.IntColumnsCnt + Params.StrColumnsCnt) - , RandomDevice() - , Mt19937(RandomDevice()) { Y_ABORT_UNLESS(TotalColumnsCnt >= Params.KeyColumnsCnt); } @@ -209,10 +199,9 @@ TVector TLogGenerator::GetCleanPaths() const { TVector TLogGenerator::GenerateRandomRows() { TVector result(Params.RowsCnt); - std::normal_distribution normal_distribution_generator(0, static_cast(Params.TimestampStandardDeviationMinutes)); for (size_t row = 0; row < Params.RowsCnt; ++row) { result[row].Ts = TInstant::Now(); - i64 millisecondsDiff = 60*1000*normal_distribution_generator(Mt19937); + i64 millisecondsDiff = 60 * 1000 * NormalRandom(0., static_cast(Params.TimestampStandardDeviationMinutes)); if (millisecondsDiff >= 0) { // TDuration::MilliSeconds can't be negative for some reason... result[row].Ts = result[row].Ts + TDuration::MilliSeconds(millisecondsDiff); } else { diff --git a/ydb/library/workload/log/log.h b/ydb/library/workload/log/log.h index 04851a2cc797..7dd8cc3101f6 100644 --- a/ydb/library/workload/log/log.h +++ b/ydb/library/workload/log/log.h @@ -3,8 +3,6 @@ #include #include -#include -#include namespace NYdbWorkload { @@ -102,9 +100,6 @@ class TLogGenerator final: public TWorkloadQueryGeneratorBase GenerateRandomRows(); const ui64 TotalColumnsCnt; - - std::random_device RandomDevice; - std::mt19937 Mt19937; }; } // namespace NLog