diff options
author | va-kuznecov <va-kuznecov@ydb.tech> | 2022-12-07 18:02:43 +0300 |
---|---|---|
committer | va-kuznecov <va-kuznecov@ydb.tech> | 2022-12-07 18:02:43 +0300 |
commit | 4af13ba0a6ae5aee5c9ebe4e0d5784aaf507923c (patch) | |
tree | 3486efe9f47645784565b7f45572fcda4fb186b3 | |
parent | 073cfa733cd8ec817135f28cb8a2719452094d73 (diff) | |
download | ydb-4af13ba0a6ae5aee5c9ebe4e0d5784aaf507923c.tar.gz |
Implement pattern cache blacklist
4 files changed, 30 insertions, 6 deletions
diff --git a/ydb/library/yql/dq/runtime/dq_tasks_runner.cpp b/ydb/library/yql/dq/runtime/dq_tasks_runner.cpp index 3a8025e6c3..b444f11ef6 100644 --- a/ydb/library/yql/dq/runtime/dq_tasks_runner.cpp +++ b/ydb/library/yql/dq/runtime/dq_tasks_runner.cpp @@ -404,7 +404,11 @@ public: entry = cache->Find(program.GetRaw()); if (!entry) { entry = CreateComputationPattern(task, program.GetRaw()); - cache->EmplacePattern(task.GetProgram().GetRaw(), entry); + if (entry->Pattern->GetSuitableForCache()) { + cache->EmplacePattern(task.GetProgram().GetRaw(), entry); + } else { + cache->IncNotSuitablePattern(); + } } } else { entry = CreateComputationPattern(task, program.GetRaw()); diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node.h b/ydb/library/yql/minikql/computation/mkql_computation_node.h index 60fce73557..6ea0d9f15a 100644 --- a/ydb/library/yql/minikql/computation/mkql_computation_node.h +++ b/ydb/library/yql/minikql/computation/mkql_computation_node.h @@ -353,6 +353,7 @@ public: virtual ~IComputationPattern() = default; virtual THolder<IComputationGraph> Clone(const TComputationOptsFull& compOpts) = 0; + virtual bool GetSuitableForCache() const = 0; }; // node cookie's will be clean up when graph will be destroyed, explorer must not be changed/destroyed until that time diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp index d04ba790b3..f699a68833 100644 --- a/ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp +++ b/ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp @@ -191,6 +191,10 @@ public: return RootNode; } + bool GetSuitableForCache() const { + return SuitableForCache; + } + private: friend class TComputationGraphBuildingVisitor; friend class TComputationGraph; @@ -204,6 +208,7 @@ private: IComputationNode* RootNode = nullptr; TComputationExternalNodePtrVector Runtime2Computation; TComputationNodeOnNodeMap ElementsCache; + bool SuitableForCache = true; }; class TComputationGraphBuildingVisitor: @@ -444,10 +449,14 @@ private: PatternNodes->ElementsCache, std::bind(&TComputationGraphBuildingVisitor::PushBackNode, this, std::placeholders::_1)); const auto computationNode = Factory(node, ctx); + const auto& name = node.GetType()->GetName(); + if (name == "Switch") { // KIKIMR-16457 + PatternNodes->SuitableForCache = false; + } if (!computationNode) { THROW yexception() - << "Computation graph builder, unsupported function: " << node.GetType()->GetName() << " type: " << Factory.target_type().name() ; + << "Computation graph builder, unsupported function: " << name << " type: " << Factory.target_type().name() ; } AddNode(node, computationNode); @@ -809,6 +818,10 @@ public: return MakeHolder<TComputationGraph>(PatternNodes, compOpts); } + bool GetSuitableForCache() const final { + return PatternNodes->GetSuitableForCache(); + } + private: TTypeEnvironment* TypeEnv = nullptr; TPatternNodes::TPtr PatternNodes; diff --git a/ydb/library/yql/minikql/computation/mkql_computation_pattern_cache.h b/ydb/library/yql/minikql/computation/mkql_computation_pattern_cache.h index 4813f914bf..fdf3429fd8 100644 --- a/ydb/library/yql/minikql/computation/mkql_computation_pattern_cache.h +++ b/ydb/library/yql/minikql/computation/mkql_computation_pattern_cache.h @@ -58,8 +58,10 @@ class TComputationPatternLRUCache { public: NMonitoring::TDynamicCounters::TCounterPtr Hits; NMonitoring::TDynamicCounters::TCounterPtr Misses; + NMonitoring::TDynamicCounters::TCounterPtr NotSuitablePattern; NMonitoring::TDynamicCounters::TCounterPtr SizeItems; NMonitoring::TDynamicCounters::TCounterPtr SizeBytes; + NMonitoring::TDynamicCounters::TCounterPtr MaxSizeBytesCounter; public: TComputationPatternLRUCache(size_t sizeBytes, NMonitoring::TDynamicCounterPtr counters = MakeIntrusive<NMonitoring::TDynamicCounters>()) @@ -67,10 +69,12 @@ public: , MaxSizeBytes(sizeBytes) , Hits(counters->GetCounter("PatternCache/Hits", true)) , Misses(counters->GetCounter("PatternCache/Misses", true)) + , NotSuitablePattern(counters->GetCounter("PatternCache/NotSuitablePattern", true)) , SizeItems(counters->GetCounter("PatternCache/SizeItems", false)) , SizeBytes(counters->GetCounter("PatternCache/SizeBytes", false)) + , MaxSizeBytesCounter(counters->GetCounter("PatternCache/MaxSizeBytes", false)) { - *counters->GetCounter("PatternCache/MaxSizeBytes", false) = MaxSizeBytes; + *MaxSizeBytesCounter = MaxSizeBytes; } static std::shared_ptr<TPatternCacheEntry> CreateCacheEntry(bool useAlloc = true) { @@ -117,10 +121,9 @@ public: } void CleanCache() { - *Hits = 0; - *Misses = 0; *SizeItems = 0; *SizeBytes = 0; + *MaxSizeBytesCounter = 0; auto guard = std::scoped_lock<std::mutex>(Mutex); CurrentSizeBytes = 0; Cache.Clear(); @@ -141,9 +144,12 @@ public: return *Hits; } + void IncNotSuitablePattern() { + ++*NotSuitablePattern; + } + ~TComputationPatternLRUCache() { CleanCache(); - Mutex.lock(); } }; |