diff options
author | udovichenko-r <rvu@ydb.tech> | 2023-01-27 16:18:51 +0300 |
---|---|---|
committer | udovichenko-r <rvu@ydb.tech> | 2023-01-27 16:18:51 +0300 |
commit | 4c52fa16c52ee78634187ebe07cfa2dd7c4867c9 (patch) | |
tree | 77a3b101bba6d118203a27745a521d74877d64cc | |
parent | 50b842ae5652850c67c4d9acf8ef5adfc8539415 (diff) | |
download | ydb-4c52fa16c52ee78634187ebe07cfa2dd7c4867c9.tar.gz |
[yql] Use sampling stat timer in yt reader
-rw-r--r-- | ydb/library/yql/minikql/mkql_stats_registry.h | 56 | ||||
-rw-r--r-- | ydb/library/yql/providers/common/codec/yql_codec_buf.h | 6 |
2 files changed, 49 insertions, 13 deletions
diff --git a/ydb/library/yql/minikql/mkql_stats_registry.h b/ydb/library/yql/minikql/mkql_stats_registry.h index 1b888153e48..02b74cd68ed 100644 --- a/ydb/library/yql/minikql/mkql_stats_registry.h +++ b/ydb/library/yql/minikql/mkql_stats_registry.h @@ -4,6 +4,7 @@ #include <util/generic/intrlist.h> #include <util/system/datetime.h> #include <util/system/hp_timer.h> +#include <util/system/yassert.h> namespace NKikimr { namespace NMiniKQL { @@ -103,14 +104,35 @@ IStatsRegistryPtr CreateDefaultStatsRegistry(); #define MKQL_INC_STAT(statRegistry, key) MKQL_ADD_STAT(statRegistry, key, 1) #define MKQL_DEC_STAT(statRegistry, key) MKQL_ADD_STAT(statRegistry, key, -1) -class TStatTimer { +class TStatTimerBase { public: - TStatTimer(const TStatKey& key) + TStatTimerBase(const TStatKey& key) : Key_(key) , Total_(0) , Start_(0) {} + void Reset() { + Total_ = 0; + } + + void Report(IStatsRegistry* statRegistry) const { + auto value = (i64)(1e3 * Total_ / NHPTimer::GetClockRate()); + MKQL_ADD_STAT(statRegistry, Key_, value); + } + +protected: + const TStatKey& Key_; + i64 Total_; + i64 Start_; +}; + +class TStatTimer: public TStatTimerBase { +public: + TStatTimer(const TStatKey& key) + : TStatTimerBase(key) + {} + void Acquire() { Start_ = GetCycleCount(); } @@ -118,20 +140,34 @@ public: void Release() { Total_ += GetCycleCount() - Start_; } +}; - void Reset() { - Total_ = 0; +class TSamplingStatTimer: public TStatTimerBase { +public: + TSamplingStatTimer(const TStatKey& key, ui64 frequency = 100) + : TStatTimerBase(key) + , Frequency_(frequency) + { + Y_ASSERT(Frequency_ > 0); } - void Report(IStatsRegistry* statRegistry) const { - auto value = (i64)(1e3 * Total_ / NHPTimer::GetClockRate()); - MKQL_ADD_STAT(statRegistry, Key_, value); + void Acquire() { + if (Counter_ == 0) { + Start_ = GetCycleCount(); + } } + void Release() { + if (Counter_ == 0) { + Total_ += (GetCycleCount() - Start_) * Frequency_; + } + if (++Counter_ == Frequency_) { + Counter_ = 0; + } + } private: - const TStatKey& Key_; - i64 Total_; - i64 Start_; + const ui64 Frequency_; + ui64 Counter_ = 0; }; } // namespace NMiniKQL diff --git a/ydb/library/yql/providers/common/codec/yql_codec_buf.h b/ydb/library/yql/providers/common/codec/yql_codec_buf.h index d951a9010da..556426bccab 100644 --- a/ydb/library/yql/providers/common/codec/yql_codec_buf.h +++ b/ydb/library/yql/providers/common/codec/yql_codec_buf.h @@ -56,11 +56,11 @@ friend void InputBufReadManySlowThunk(TInputBuf& in, char* buffer, size_t count) friend void InputBufSkipManySlowThunk(TInputBuf& in, size_t count); public: - TInputBuf(NKikimr::NMiniKQL::TStatTimer* readTimer) + TInputBuf(NKikimr::NMiniKQL::TSamplingStatTimer* readTimer) : ReadTimer_(readTimer) {} - TInputBuf(IBlockReader& source, NKikimr::NMiniKQL::TStatTimer* readTimer) + TInputBuf(IBlockReader& source, NKikimr::NMiniKQL::TSamplingStatTimer* readTimer) : TInputBuf(readTimer) { SetSource(source); @@ -181,7 +181,7 @@ private: private: IBlockReader* Source_ = nullptr; - NKikimr::NMiniKQL::TStatTimer* ReadTimer_; + NKikimr::NMiniKQL::TSamplingStatTimer* ReadTimer_; NKikimr::NMiniKQL::IStatsRegistry* JobStats_ = nullptr; const char* Current_ = nullptr; const char* End_ = nullptr; |