Skip to content

Commit

Permalink
Pretty view for workload run (#5531)
Browse files Browse the repository at this point in the history
  • Loading branch information
iddqdex authored Jun 14, 2024
1 parent a72739a commit 746b182
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 81 deletions.
46 changes: 36 additions & 10 deletions ydb/public/lib/ydb_cli/commands/benchmark_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ TTestInfo::TTestInfo(std::vector<TDuration>&& clientTimings, std::vector<TDurati
RttMean = totalDiff / static_cast<double>(ServerTimings.size());

auto serverTimingsCopy = ServerTimings;
Sort(serverTimingsCopy);
auto centerElement = serverTimingsCopy.begin() + ServerTimings.size() / 2;
std::nth_element(serverTimingsCopy.begin(), centerElement, serverTimingsCopy.end());

Expand All @@ -79,6 +80,36 @@ TTestInfo::TTestInfo(std::vector<TDuration>&& clientTimings, std::vector<TDurati
} else {
Median = centerElement->MilliSeconds();
}
const auto ubCount = std::max<size_t>(1, serverTimingsCopy.size() * 2 / 3);
double ub = 1;
for (ui32 i = 0; i < ubCount; ++i) {
ub *= serverTimingsCopy[i].MillisecondsFloat();
}
UnixBench = TDuration::MilliSeconds(pow(ub, 1. / ubCount));
}

void TTestInfo::operator /=(const ui32 count) {
ColdTime /= count;
Min /= count;
Max /= count;
RttMin /= count;
RttMax /= count;
RttMean /= count;
Mean /= count;
Median /= count;
UnixBench /= count;
}

void TTestInfo::operator +=(const TTestInfo& other) {
ColdTime += other.ColdTime;
Min += other.Min;
Max += other.Max;
RttMin += other.RttMin;
RttMax += other.RttMax;
RttMean += other.RttMean;
Mean += other.Mean;
Median += other.Median;
UnixBench += other.UnixBench;
}

TString FullTablePath(const TString& database, const TString& table) {
Expand Down Expand Up @@ -106,8 +137,9 @@ bool HasCharsInString(const TString& str) {

class IQueryResultScanner {
private:
TString ErrorInfo;
TDuration ServerTiming;
YDB_READONLY_DEF(TString, ErrorInfo);
YDB_READONLY_DEF(TDuration, ServerTiming);

public:
virtual ~IQueryResultScanner() = default;
virtual void OnStart(const TVector<NYdb::TColumn>& columns) = 0;
Expand All @@ -118,12 +150,6 @@ class IQueryResultScanner {
void OnError(const TString& info) {
ErrorInfo = info;
}
const TString& GetErrorInfo() const {
return ErrorInfo;
}
TDuration GetServerTiming() const {
return ServerTiming;
}

template <typename TIterator>
bool Scan(TIterator& it) {
Expand All @@ -139,12 +165,12 @@ class IQueryResultScanner {

if constexpr (std::is_same_v<TIterator, NTable::TScanQueryPartIterator>) {
if (streamPart.HasQueryStats()) {
ServerTiming = streamPart.GetQueryStats().GetTotalDuration();
ServerTiming += streamPart.GetQueryStats().GetTotalDuration();
}
} else {
const auto& stats = streamPart.GetStats();
if (stats) {
ServerTiming = stats->GetTotalDuration();
ServerTiming += stats->GetTotalDuration();
}
}

Expand Down
28 changes: 10 additions & 18 deletions ydb/public/lib/ydb_cli/commands/benchmark_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <library/cpp/json/json_value.h>
#include <ydb/public/sdk/cpp/client/ydb_table/table.h>
#include <ydb/public/sdk/cpp/client/ydb_query/client.h>
#include <ydb/library/accessor/accessor.h>

#include <vector>

Expand All @@ -20,10 +21,13 @@ struct TTestInfo {
double Mean = 0;
double Median = 0;
double Std = 0;
TDuration UnixBench;
std::vector<TDuration> ClientTimings; // timings captured by the client application. these timings include time RTT between server and the client application.
std::vector<TDuration> ServerTimings; // query timings measured by the server.

explicit TTestInfo(std::vector<TDuration>&& clientTimings, std::vector<TDuration>&& serverTimings);
void operator +=(const TTestInfo& other);
void operator /=(const ui32 count);
};

class TQueryResultInfo {
Expand Down Expand Up @@ -51,10 +55,10 @@ class TQueryResultInfo {

class TQueryBenchmarkResult {
private:
TString ErrorInfo;
TString YSONResult;
TQueryResultInfo QueryResult;
TDuration ServerTiming;
YDB_READONLY_DEF(TString, ErrorInfo);
YDB_READONLY_DEF(TString, YSONResult);
YDB_READONLY_DEF(TQueryResultInfo, QueryResult);
YDB_READONLY_DEF(TDuration, ServerTiming);
TQueryBenchmarkResult() = default;
public:
static TQueryBenchmarkResult Result(const TString& yson, const TQueryResultInfo& queryResult, const TDuration& serverTiming) {
Expand All @@ -69,20 +73,8 @@ class TQueryBenchmarkResult {
result.ErrorInfo = error;
return result;
}
bool operator!() const {
return !!ErrorInfo;
}
const TString& GetErrorInfo() const {
return ErrorInfo;
}
TDuration GetServerTiming() const {
return ServerTiming;
}
const TString& GetYSONResult() const {
return YSONResult;
}
const TQueryResultInfo& GetQueryResult() const {
return QueryResult;
operator bool() const {
return !ErrorInfo;
}
};

Expand Down
Loading

0 comments on commit 746b182

Please sign in to comment.