Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use threadsafe randomizer #13754

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions ydb/library/workload/log/log.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#include "log.h"
#include <util/generic/serialized_enum.h>
#include <util/random/normal.h>
#include <util/random/random.h>
#include <util/datetime/base.h>

#include <cmath>
#include <iomanip>
#include <string>
#include <thread>
#include <random>
#include <sstream>
#include <chrono>
#include <format>

namespace NYdbWorkload {

namespace NLog {
Expand All @@ -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);
}
Expand Down Expand Up @@ -209,10 +199,9 @@ TVector<std::string> TLogGenerator::GetCleanPaths() const {
TVector<TRow> TLogGenerator::GenerateRandomRows() {
TVector<TRow> result(Params.RowsCnt);

std::normal_distribution<double> normal_distribution_generator(0, static_cast<double>(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<double>(Params.TimestampStandardDeviationMinutes));
if (millisecondsDiff >= 0) { // TDuration::MilliSeconds can't be negative for some reason...
result[row].Ts = result[row].Ts + TDuration::MilliSeconds(millisecondsDiff);
} else {
Expand Down
5 changes: 0 additions & 5 deletions ydb/library/workload/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <ydb/library/workload/abstract/workload_query_generator.h>

#include <cctype>
#include <random>
#include <sstream>

namespace NYdbWorkload {

Expand Down Expand Up @@ -102,9 +100,6 @@ class TLogGenerator final: public TWorkloadQueryGeneratorBase<TLogWorkloadParams
TVector<TRow> GenerateRandomRows();

const ui64 TotalColumnsCnt;

std::random_device RandomDevice;
std::mt19937 Mt19937;
};

} // namespace NLog
Expand Down
Loading