diff options
author | monster <monster@ydb.tech> | 2022-10-21 12:41:31 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-10-21 12:41:31 +0300 |
commit | 788eb8719d56f75e9761cfad0f2a269d70e01fea (patch) | |
tree | e3f7b236004886ad3b6476f6e6642252ecf4c9c2 | |
parent | df864686c3757d3f7186d276ee2a7c22005d69ab (diff) | |
download | ydb-788eb8719d56f75e9761cfad0f2a269d70e01fea.tar.gz |
optimize aggregator calculations
-rw-r--r-- | ydb/core/tablet/private/aggregated_counters.cpp | 260 | ||||
-rw-r--r-- | ydb/core/tablet/private/aggregated_counters.h | 43 | ||||
-rw-r--r-- | ydb/core/tablet/tablet_counters_aggregator.cpp | 64 |
3 files changed, 205 insertions, 162 deletions
diff --git a/ydb/core/tablet/private/aggregated_counters.cpp b/ydb/core/tablet/private/aggregated_counters.cpp index be31a8da04a..2dccbf9e323 100644 --- a/ydb/core/tablet/private/aggregated_counters.cpp +++ b/ydb/core/tablet/private/aggregated_counters.cpp @@ -10,7 +10,8 @@ using TCountersVector = TVector<::NMonitoring::TDynamicCounters::TCounterPtr>; /* ** struct THistogramCounter -*/ + */ + THistogramCounter::THistogramCounter( const TVector<TTabletPercentileCounter::TRangeDef>& ranges, TCountersVector&& values, @@ -40,30 +41,31 @@ using THistogramVector = TVector<THolder<THistogramCounter>>; /* ** class TAggregatedSimpleCounters -*/ + */ + TAggregatedSimpleCounters::TAggregatedSimpleCounters(::NMonitoring::TDynamicCounterPtr counterGroup) : CounterGroup(counterGroup) {} void TAggregatedSimpleCounters::Reserve(size_t hint) { - CountersByTabletID.reserve(hint); ChangedCounters.reserve(hint); MaxSimpleCounters.reserve(hint); + SumSimpleCounters.reserve(hint); + HistSimpleCounters.reserve(hint); } void TAggregatedSimpleCounters::AddSimpleCounter( - const char* name, - THolder<THistogramCounter> percentileAggregate) { - auto fnAddCounter = [this](const char* name, TCountersVector& container) { - auto counter = CounterGroup->GetCounter(name, false); - container.push_back(counter); - }; - - CountersByTabletID.push_back(TCountersByTabletIDMap()); + const char* name, THolder<THistogramCounter> percentileAggregate) +{ ChangedCounters.push_back(true); + TString maxName = Sprintf("MAX(%s)", name); TString sumName = Sprintf("SUM(%s)", name); + auto fnAddCounter = [this](const char* name, TCountersVector& container) { + auto counter = CounterGroup->GetCounter(name, false); + container.push_back(counter); + }; fnAddCounter(maxName.data(), MaxSimpleCounters); fnAddCounter(sumName.data(), SumSimpleCounters); @@ -94,86 +96,108 @@ void TAggregatedSimpleCounters::SetMax(ui32 counterIndex, ui64 value) { *MaxSimpleCounters[counterIndex] = value; } -void TAggregatedSimpleCounters::SetValue(ui64 tabletID, ui32 counterIndex, ui64 value, NKikimrTabletBase::TTabletTypes::EType tabletType) { - Y_VERIFY(counterIndex < CountersByTabletID.size(), - "inconsistent counters for tablet type %s", TTabletTypes::TypeToStr(tabletType)); - TCountersByTabletIDMap::insert_ctx insertCtx; - auto it = CountersByTabletID[counterIndex].find(tabletID, insertCtx); - if (it != CountersByTabletID[counterIndex].end()) { - if (it->second != value) { - ChangedCounters[counterIndex] = true; - it->second = value; +void TAggregatedSimpleCounters::SetValues( + ui64 tabletId, const TVector<ui64>& values, NKikimrTabletBase::TTabletTypes::EType tabletType) +{ + size_t count = ChangedCounters.size(); + Y_VERIFY(count <= values.size(), + "inconsistent simple counters for tablet type %s", TTabletTypes::TypeToStr(tabletType)); + + auto it = CountersByTabletId.find(tabletId); + if (it != CountersByTabletId.end()) { + auto& current = it->second; + Y_VERIFY(count == current.size(), + "inconsistent simple counters for tablet type %s", TTabletTypes::TypeToStr(tabletType)); + for (size_t i = 0; i < count; ++i) { + if (current[i] != values[i]) { + current[i] = values[i]; + ChangedCounters[i] = true; + } } } else { - CountersByTabletID[counterIndex].insert_direct(std::make_pair(tabletID, value), insertCtx); - ChangedCounters[counterIndex] = true; + auto& current = CountersByTabletId[tabletId]; + current.resize(count); + for (size_t i = 0; i < count; ++i) { + current[i] = values[i]; + ChangedCounters[i] = true; + } } } void TAggregatedSimpleCounters::ForgetTablet(ui64 tabletId) { - for (ui32 idx : xrange(CountersByTabletID.size())) { - auto &counters = CountersByTabletID[idx]; - if (counters.erase(tabletId) != 0) - ChangedCounters[idx] = true; + if (CountersByTabletId.erase(tabletId) != 0) { + size_t count = ChangedCounters.size(); + for (size_t i = 0; i < count; ++i) { + ChangedCounters[i] = true; + } } } void TAggregatedSimpleCounters::RecalcAll() { - for (ui32 idx : xrange(CountersByTabletID.size())) { - if (ChangedCounters[idx]) - Recalc(idx); - ChangedCounters[idx] = false; - } -} - -void TAggregatedSimpleCounters::Recalc(ui32 idx) { - auto &counters = CountersByTabletID[idx]; - THistogramCounter* histCounter = HistSimpleCounters[idx].Get(); + TVector<ui64> maxValues; + TVector<ui64> sumValues; - ui64 maxVal = 0; - ui64 sumVal = 0; + size_t count = ChangedCounters.size(); + maxValues.resize(count, 0); + sumValues.resize(count, 0); - if (histCounter) { - histCounter->Clear(); + for (size_t i = 0; i < count; ++i) { + auto* histCounter = HistSimpleCounters[i].Get(); + if (histCounter) { + histCounter->Clear(); + } } - for (auto&& t : counters) { - ui64 tValue = t.second; - maxVal = Max(tValue, maxVal); - sumVal += tValue; - if (histCounter) { - histCounter->IncrementFor(tValue); + for (auto& [_, counters] : CountersByTabletId) { + for (size_t i = 0; i < count; ++i) { + if (!ChangedCounters[i]) { + continue; + } + auto value = counters[i]; + maxValues[i] = Max(value, maxValues[i]); + sumValues[i] += value; + auto* histCounter = HistSimpleCounters[i].Get(); + if (histCounter) { + histCounter->IncrementFor(value); + } } } - *MaxSimpleCounters[idx].Get() = maxVal; - *SumSimpleCounters[idx].Get() = sumVal; + for (size_t i = 0; i < count; ++i) { + if (!ChangedCounters[i]) { + continue; + } + *MaxSimpleCounters[i].Get() = maxValues[i]; + *SumSimpleCounters[i].Get() = sumValues[i]; + ChangedCounters[i] = false; + } } /* ** class TAggregatedCumulativeCounters */ + TAggregatedCumulativeCounters::TAggregatedCumulativeCounters(::NMonitoring::TDynamicCounterPtr counterGroup) : CounterGroup(counterGroup) {} void TAggregatedCumulativeCounters::Reserve(size_t hint) { - CountersByTabletID.reserve(hint); ChangedCounters.reserve(hint); MaxCumulativeCounters.reserve(hint); + HistCumulativeCounters.reserve(hint); } void TAggregatedCumulativeCounters::AddCumulativeCounter( - const char* name, THolder<THistogramCounter> percentileAggregate) { + const char* name, THolder<THistogramCounter> percentileAggregate) +{ + ChangedCounters.push_back(true); + + TString maxName = Sprintf("MAX(%s)", name); + auto fnAddCounter = [this](const char* name, TCountersVector& container) { auto counter = CounterGroup->GetCounter(name, false); container.push_back(counter); }; - - CountersByTabletID.push_back(TCountersByTabletIDMap()); - ChangedCounters.push_back(true); - TString maxName = Sprintf("MAX(%s)", name); - fnAddCounter(maxName.data(), MaxCumulativeCounters); HistCumulativeCounters.emplace_back(std::move(percentileAggregate)); @@ -191,57 +215,77 @@ void TAggregatedCumulativeCounters::SetMax(ui32 counterIndex, ui64 value) { *MaxCumulativeCounters[counterIndex] = value; } -void TAggregatedCumulativeCounters::SetValue(ui64 tabletID, ui32 counterIndex, ui64 value, - NKikimrTabletBase::TTabletTypes::EType tabletType) { - Y_VERIFY(counterIndex < CountersByTabletID.size(), "inconsistent counters for tablet type %s", TTabletTypes::TypeToStr(tabletType)); - TCountersByTabletIDMap::insert_ctx insertCtx; - auto it = CountersByTabletID[counterIndex].find(tabletID, insertCtx); - if (it != CountersByTabletID[counterIndex].end()) { - if (it->second != value) { - ChangedCounters[counterIndex] = true; - it->second = value; +void TAggregatedCumulativeCounters::SetValues( + ui64 tabletId, const TVector<ui64>& values, NKikimrTabletBase::TTabletTypes::EType tabletType) +{ + size_t count = ChangedCounters.size(); + Y_VERIFY(count <= values.size(), + "inconsistent cumulative counters for tablet type %s", TTabletTypes::TypeToStr(tabletType)); + + auto it = CountersByTabletId.find(tabletId); + if (it != CountersByTabletId.end()) { + auto& current = it->second; + Y_VERIFY(count == current.size(), + "inconsistent cumulative counters for tablet type %s", TTabletTypes::TypeToStr(tabletType)); + for (size_t i = 0; i < count; ++i) { + if (current[i] != values[i]) { + current[i] = values[i]; + ChangedCounters[i] = true; + } } } else { - CountersByTabletID[counterIndex].insert_direct(std::make_pair(tabletID, value), insertCtx); - ChangedCounters[counterIndex] = true; + auto& current = CountersByTabletId[tabletId]; + current.resize(count); + for (size_t i = 0; i < count; ++i) { + current[i] = values[i]; + ChangedCounters[i] = true; + } } } void TAggregatedCumulativeCounters::ForgetTablet(ui64 tabletId) { - for (ui32 idx : xrange(CountersByTabletID.size())) { - auto &counters = CountersByTabletID[idx]; - if (counters.erase(tabletId) != 0) - ChangedCounters[idx] = true; + if (CountersByTabletId.erase(tabletId) != 0) { + size_t count = ChangedCounters.size(); + for (size_t i = 0; i < count; ++i) { + ChangedCounters[i] = true; + } } } void TAggregatedCumulativeCounters::RecalcAll() { - for (ui32 idx : xrange(CountersByTabletID.size())) { - if (ChangedCounters[idx]) - Recalc(idx); - ChangedCounters[idx] = false; - } -} - -void TAggregatedCumulativeCounters::Recalc(ui32 idx) { - auto &counters = CountersByTabletID[idx]; - THistogramCounter* histCounter = HistCumulativeCounters[idx].Get(); + TVector<ui64> maxValues; - ui64 maxVal = 0; + size_t count = ChangedCounters.size(); + maxValues.resize(count, 0); - if (histCounter) { - histCounter->Clear(); + for (size_t i = 0; i < count; ++i) { + auto* histCounter = HistCumulativeCounters[i].Get(); + if (histCounter) { + histCounter->Clear(); + } } - for (auto&& t : counters) { - ui64 tValue = t.second; - maxVal = Max(tValue, maxVal); - if (histCounter) { - histCounter->IncrementFor(tValue); + for (auto& [_, counters] : CountersByTabletId) { + for (size_t i = 0; i < count; ++i) { + if (!ChangedCounters[i]) { + continue; + } + auto value = counters[i]; + maxValues[i] = Max(value, maxValues[i]); + auto* histCounter = HistCumulativeCounters[i].Get(); + if (histCounter) { + histCounter->IncrementFor(value); + } } } - *MaxCumulativeCounters[idx].Get() = maxVal; + for (size_t i = 0; i < count; ++i) { + if (!ChangedCounters[i]) { + continue; + } + *MaxCumulativeCounters[i].Get() = maxValues[i]; + ChangedCounters[i] = false; + } } /* @@ -257,7 +301,7 @@ void TAggregatedHistogramCounters::Reserve(size_t hint) { Histograms.reserve(hint); IsDerivative.reserve(hint); BucketBounds.reserve(hint); - CountersByTabletID.reserve(hint); + CountersByTabletId.reserve(hint); } void TAggregatedHistogramCounters::AddCounter( @@ -317,16 +361,16 @@ void TAggregatedHistogramCounters::AddCounter( // on the histogram updated outside Histograms.push_back(histogram); - CountersByTabletID.emplace_back(TCountersByTabletIDMap()); + CountersByTabletId.emplace_back(TCountersByTabletIdMap()); } void TAggregatedHistogramCounters::SetValue( - ui64 tabletID, + ui64 tabletId, ui32 counterIndex, const NKikimr::TTabletPercentileCounter& percentileCounter, const char* name, NKikimrTabletBase::TTabletTypes::EType tabletType) { - Y_VERIFY(counterIndex < CountersByTabletID.size(), + Y_VERIFY(counterIndex < CountersByTabletId.size(), "inconsistent counters for tablet type %s, counter %s", TTabletTypes::TypeToStr(tabletType), name); @@ -364,9 +408,9 @@ void TAggregatedHistogramCounters::SetValue( for (auto i: xrange(rangeCount)) newValues.push_back(percentileCounter.GetRangeValue(i)); - TCountersByTabletIDMap::insert_ctx insertCtx; - auto it = CountersByTabletID[counterIndex].find(tabletID, insertCtx); - if (it != CountersByTabletID[counterIndex].end()) { + TCountersByTabletIdMap::insert_ctx insertCtx; + auto it = CountersByTabletId[counterIndex].find(tabletId, insertCtx); + if (it != CountersByTabletId[counterIndex].end()) { auto& oldValues = it->second; if (newValues != oldValues) { SubValues(counterIndex, oldValues); @@ -375,13 +419,13 @@ void TAggregatedHistogramCounters::SetValue( oldValues.swap(newValues); } else { AddValues(counterIndex, newValues); - CountersByTabletID[counterIndex].insert_direct(std::make_pair(tabletID, std::move(newValues)), insertCtx); + CountersByTabletId[counterIndex].insert_direct(std::make_pair(tabletId, std::move(newValues)), insertCtx); } } void TAggregatedHistogramCounters::ForgetTablet(ui64 tabletId) { - for (auto idx : xrange(CountersByTabletID.size())) { - auto &tabletToCounters = CountersByTabletID[idx]; + for (auto idx : xrange(CountersByTabletId.size())) { + auto &tabletToCounters = CountersByTabletId[idx]; auto it = tabletToCounters.find(tabletId); if (it == tabletToCounters.end()) continue; @@ -456,22 +500,22 @@ TAggregatedLabeledCounters::TAggregatedLabeledCounters( , AggrCounters(count, 0) , Ids(count, 0) , Changed(false) - , CountersByTabletID(count) + , CountersByTabletId(count) { } -void TAggregatedLabeledCounters::SetValue(ui64 tabletID, ui32 counterIndex, ui64 value, ui64 id) { - CountersByTabletID[counterIndex][tabletID] = std::make_pair(value, id); +void TAggregatedLabeledCounters::SetValue(ui64 tabletId, ui32 counterIndex, ui64 value, ui64 id) { + CountersByTabletId[counterIndex][tabletId] = std::make_pair(value, id); Changed = true; } bool TAggregatedLabeledCounters::ForgetTablet(ui64 tabletId) { - for (ui32 idx : xrange(CountersByTabletID.size())) { - auto &counters = CountersByTabletID[idx]; + for (ui32 idx : xrange(CountersByTabletId.size())) { + auto &counters = CountersByTabletId[idx]; counters.erase(tabletId); } Changed = true; - return CountersByTabletID.size() == 0 || CountersByTabletID[0].size() == 0; + return CountersByTabletId.size() == 0 || CountersByTabletId[0].size() == 0; } ui32 TAggregatedLabeledCounters::Size() const { @@ -490,7 +534,7 @@ void TAggregatedLabeledCounters::FillGetRequestV1( NKikimrLabeledCounters::TTabletLabeledCounters* labeledCounters, const TString& group, ui32 start, ui32 end) const { if (Changed) { - for (ui32 idx : xrange(CountersByTabletID.size())) { + for (ui32 idx : xrange(CountersByTabletId.size())) { Recalc(idx); } Changed = false; @@ -513,7 +557,7 @@ void TAggregatedLabeledCounters::FillGetRequestV1( void TAggregatedLabeledCounters::FillGetRequestV2( NKikimr::TTabletLabeledCountersResponseContext* context, const TString& group) const { if (Changed) { - for (ui32 idx : xrange(CountersByTabletID.size())) { + for (ui32 idx : xrange(CountersByTabletId.size())) { Recalc(idx); } Changed = false; @@ -532,7 +576,7 @@ void TAggregatedLabeledCounters::FillGetRequestV2( void TAggregatedLabeledCounters::Recalc(ui32 idx) const { Y_VERIFY(idx < Ids.size()); - auto &counters = CountersByTabletID[idx]; + auto &counters = CountersByTabletId[idx]; TTabletLabeledCountersBase::EAggregateFunc aggrFunc{AggrFunc[idx]}; std::pair<ui64, ui64> aggrVal{0,0}; ui64 cntCount = counters.size(); diff --git a/ydb/core/tablet/private/aggregated_counters.h b/ydb/core/tablet/private/aggregated_counters.h index 44c92cd46fc..24e5ab04d36 100644 --- a/ydb/core/tablet/private/aggregated_counters.h +++ b/ydb/core/tablet/private/aggregated_counters.h @@ -40,8 +40,7 @@ public: void Reserve(size_t hint); - void AddSimpleCounter(const char* name, - THolder<THistogramCounter> percentileAggregate = THolder<THistogramCounter>()); + void AddSimpleCounter(const char* name, THolder<THistogramCounter> percentileAggregate = {}); ui64 GetSum(ui32 counterIndex) const; void SetSum(ui32 counterIndex, ui64 value); @@ -49,24 +48,21 @@ public: ui64 GetMax(ui32 counterIndex) const; void SetMax(ui32 counterIndex, ui64 value); - void SetValue(ui64 tabletID, ui32 counterIndex, ui64 value, NKikimrTabletBase::TTabletTypes::EType tabletType); + void SetValues(ui64 tabletId, const TVector<ui64>& values, NKikimrTabletBase::TTabletTypes::EType tabletType); void ForgetTablet(ui64 tabletId); void RecalcAll(); private: - // ::NMonitoring::TDynamicCounterPtr CounterGroup; TCountersVector MaxSimpleCounters; TCountersVector SumSimpleCounters; THistogramVector HistSimpleCounters; - using TCountersByTabletIDMap = THashMap<ui64, ui64>; - TVector<TCountersByTabletIDMap> CountersByTabletID; - TVector<bool> ChangedCounters; + using TCountersByTabletIdMap = THashMap<ui64, TVector<ui64>>; + TCountersByTabletIdMap CountersByTabletId; -private: - void Recalc(ui32 idx); + TVector<bool> ChangedCounters; }; class TAggregatedCumulativeCounters { @@ -75,28 +71,26 @@ public: TAggregatedCumulativeCounters(::NMonitoring::TDynamicCounterPtr counterGroup); void Reserve(size_t hint); - void AddCumulativeCounter(const char* name, - THolder<THistogramCounter> percentileAggregate = THolder<THistogramCounter>()); + + void AddCumulativeCounter(const char* name, THolder<THistogramCounter> percentileAggregate = {}); + ui64 GetMax(ui32 counterIndex) const; void SetMax(ui32 counterIndex, ui64 value); - void SetValue(ui64 tabletID, ui32 counterIndex, ui64 value, - NKikimrTabletBase::TTabletTypes::EType tabletType); + + void SetValues(ui64 tabletId, const TVector<ui64>& values, NKikimrTabletBase::TTabletTypes::EType tabletType); void ForgetTablet(ui64 tabletId); void RecalcAll(); private: - // ::NMonitoring::TDynamicCounterPtr CounterGroup; TCountersVector MaxCumulativeCounters; THistogramVector HistCumulativeCounters; - using TCountersByTabletIDMap = THashMap<ui64, ui64>; - TVector<TCountersByTabletIDMap> CountersByTabletID; - TVector<bool> ChangedCounters; + using TCountersByTabletIdMap = THashMap<ui64, TVector<ui64>>; + TCountersByTabletIdMap CountersByTabletId; -private: - void Recalc(ui32 idx); + TVector<bool> ChangedCounters; }; class TAggregatedHistogramCounters { @@ -111,13 +105,12 @@ public: THashMap<TString, THolder<THistogramCounter>>& histogramAggregates); void SetValue( - ui64 tabletID, + ui64 tabletId, ui32 counterIndex, const NKikimr::TTabletPercentileCounter& percentileCounter, const char* name, NKikimrTabletBase::TTabletTypes::EType tabletType); - void ForgetTablet(ui64 tabletId); NMonitoring::THistogramPtr GetHistogram(size_t i); @@ -141,10 +134,10 @@ private: TVector<NMonitoring::TBucketBounds> BucketBounds; // tabletId -> values - using TCountersByTabletIDMap = THashMap<ui64, TValuesVec>; + using TCountersByTabletIdMap = THashMap<ui64, TValuesVec>; // counter values (not "real" monitoring counters); - TVector<TCountersByTabletIDMap> CountersByTabletID; // each index is map from tablet to counter value + TVector<TCountersByTabletIdMap> CountersByTabletId; // each index is map from tablet to counter value }; class TAggregatedLabeledCounters { @@ -175,8 +168,8 @@ private: mutable TVector<ui64> Ids; mutable bool Changed; - using TCountersByTabletIDMap = THashMap<ui64, std::pair<ui64, ui64>>; //second pair is for counter and id - TVector<TCountersByTabletIDMap> CountersByTabletID; + using TCountersByTabletIdMap = THashMap<ui64, std::pair<ui64, ui64>>; //second pair is for counter and id + TVector<TCountersByTabletIdMap> CountersByTabletId; private: void Recalc(ui32 idx) const; diff --git a/ydb/core/tablet/tablet_counters_aggregator.cpp b/ydb/core/tablet/tablet_counters_aggregator.cpp index 78a106277f9..0ebbe4aa0a4 100644 --- a/ydb/core/tablet/tablet_counters_aggregator.cpp +++ b/ydb/core/tablet/tablet_counters_aggregator.cpp @@ -87,27 +87,27 @@ public: } } - void Apply(ui64 tabletID, TTabletTypes::EType tabletType, TPathId tenantPathId, + void Apply(ui64 tabletId, TTabletTypes::EType tabletType, TPathId tenantPathId, const TTabletCountersBase* executorCounters, const TTabletCountersBase* appCounters, const TActorContext& ctx) { - AllTypes->Apply(tabletID, executorCounters, nullptr, tabletType); + AllTypes->Apply(tabletId, executorCounters, nullptr, tabletType); // auto typeCounters = GetOrAddCountersByTabletType(tabletType, CountersByTabletType, Counters); if (typeCounters) { - typeCounters->Apply(tabletID, executorCounters, appCounters, tabletType); + typeCounters->Apply(tabletId, executorCounters, appCounters, tabletType); } // if (!IsFollower && AppData(ctx)->FeatureFlags.GetEnableDbCounters() && tenantPathId) { auto dbCounters = GetDbCounters(tenantPathId, ctx); if (dbCounters) { auto* limitedAppCounters = GetOrAddLimitedAppCounters(tabletType); - dbCounters->Apply(tabletID, executorCounters, appCounters, tabletType, limitedAppCounters); + dbCounters->Apply(tabletId, executorCounters, appCounters, tabletType, limitedAppCounters); } } // - auto& quietStats = QuietTabletCounters[tabletID]; + auto& quietStats = QuietTabletCounters[tabletId]; if (executorCounters) { if (quietStats.first == nullptr) @@ -122,7 +122,7 @@ public: } } - void ApplyLabeledCounters(ui64 tabletID, TTabletTypes::EType tabletType, const TTabletLabeledCountersBase* labeledCounters) { + void ApplyLabeledCounters(ui64 tabletId, TTabletTypes::EType tabletType, const TTabletLabeledCountersBase* labeledCounters) { auto iterTabletType = LabeledCountersByTabletTypeAndGroup.find(std::make_pair(tabletType, labeledCounters->GetGroup())); @@ -157,25 +157,25 @@ public: for (ui32 i = 0, e = labeledCounters->GetCounters().Size(); i < e; ++i) { const ui64& value = labeledCounters->GetCounters()[i].Get(); const ui64& id = labeledCounters->GetIds()[i].Get(); - iterTabletType->second->SetValue(tabletID, i, value, id); + iterTabletType->second->SetValue(tabletId, i, value, id); } } - void ForgetTablet(ui64 tabletID, TTabletTypes::EType tabletType, TPathId tenantPathId) { - AllTypes->Forget(tabletID); + void ForgetTablet(ui64 tabletId, TTabletTypes::EType tabletType, TPathId tenantPathId) { + AllTypes->Forget(tabletId); // and now erase from every other path auto iterTabletType = CountersByTabletType.find(tabletType); if (iterTabletType != CountersByTabletType.end()) { - iterTabletType->second->Forget(tabletID); + iterTabletType->second->Forget(tabletId); } // from db counters if (auto itPath = CountersByPathId.find(tenantPathId); itPath != CountersByPathId.end()) { - itPath->second->Forget(tabletID, tabletType); + itPath->second->Forget(tabletId, tabletType); } //and from all labeledCounters that could have this tablet auto iterTabletTypeAndGroup = LabeledCountersByTabletTypeAndGroup.lower_bound(std::make_pair(tabletType, TString())); for (; iterTabletTypeAndGroup != LabeledCountersByTabletTypeAndGroup.end() && iterTabletTypeAndGroup->first.first == tabletType; ) { - bool empty = iterTabletTypeAndGroup->second->ForgetTablet(tabletID); + bool empty = iterTabletTypeAndGroup->second->ForgetTablet(tabletId); if (empty) { iterTabletTypeAndGroup = LabeledCountersByTabletTypeAndGroup.erase(iterTabletTypeAndGroup); } else { @@ -183,15 +183,15 @@ public: } } - QuietTabletCounters.erase(tabletID); + QuietTabletCounters.erase(tabletId); - TString tabletIdStr = Sprintf("%" PRIu64, tabletID); + TString tabletIdStr = Sprintf("%" PRIu64, tabletId); Counters->RemoveSubgroup("tabletid", tabletIdStr.data()); } void Query(const NKikimrTabletCountersAggregator::TEvTabletCountersRequest& request, NKikimrTabletCountersAggregator::TEvTabletCountersResponse& response) { - TVector<ui64> tabletIDs(request.GetTabletIds().begin(), request.GetTabletIds().end()); - if (tabletIDs.empty()) { + TVector<ui64> tabletIds(request.GetTabletIds().begin(), request.GetTabletIds().end()); + if (tabletIds.empty()) { for (const auto& pr : QuietTabletCounters) { auto& countersInfo = *response.AddCountersInfo(); countersInfo.SetTabletId(pr.first); @@ -219,8 +219,8 @@ public: } } } else { - for (ui64 tabletID : tabletIDs) { - auto it = QuietTabletCounters.find(tabletID); + for (ui64 tabletId : tabletIds) { + auto it = QuietTabletCounters.find(tabletId); if (it != QuietTabletCounters.end()) { auto& countersInfo = *response.AddCountersInfo(); countersInfo.SetTabletId(it->first); @@ -323,7 +323,7 @@ private: , TabletAppCounters(TabletAppCountersSection) {} - void Apply(ui64 tabletID, + void Apply(ui64 tabletId, const TTabletCountersBase* executorCounters, const TTabletCountersBase* appCounters, TTabletTypes::EType tabletType, @@ -335,14 +335,14 @@ private: if (!TabletExecutorCounters.IsInitialized) { TabletExecutorCounters.Initialize(executorCounters); } - TabletExecutorCounters.Apply(tabletID, executorCounters, tabletType); + TabletExecutorCounters.Apply(tabletId, executorCounters, tabletType); } if (appCounters) { if (!TabletAppCounters.IsInitialized) { TabletAppCounters.Initialize(limitedAppCounters ? limitedAppCounters : appCounters); } - TabletAppCounters.Apply(tabletID, appCounters, tabletType); + TabletAppCounters.Apply(tabletId, appCounters, tabletType); } } @@ -463,7 +463,7 @@ private: // cumulative counters FullSizeCumulative = counters->Cumulative().Size(); - AggregatedCumulativeCounters.Reserve(FullSizeSimple); + AggregatedCumulativeCounters.Reserve(FullSizeCumulative); for (ui32 i = 0; i < FullSizeCumulative; ++i) { const char* name = counters->CumulativeCounterName(i); if (!name) { @@ -485,32 +485,37 @@ private: IsInitialized = true; } - void Apply(ui64 tabletID, const TTabletCountersBase* counters, TTabletTypes::EType tabletType) { + void Apply(ui64 tabletId, const TTabletCountersBase* counters, TTabletTypes::EType tabletType) { Y_VERIFY(counters); TInstant now = TInstant::Now(); - auto it = LastAggregateUpdateTime.find(tabletID); + auto it = LastAggregateUpdateTime.find(tabletId); TDuration diff; if (it != LastAggregateUpdateTime.end()) { diff = now - it->second; it->second = now; } else { - LastAggregateUpdateTime.emplace(tabletID, now); + LastAggregateUpdateTime.emplace(tabletId, now); } // simple counters ui32 nextSimpleOffset = 0; + TVector<ui64> simpleValues; + simpleValues.resize(FullSizeSimple); // more than needed for (ui32 i = 0; i < FullSizeSimple; ++i) { if (!counters->SimpleCounterName(i)) { continue; } const ui32 offset = nextSimpleOffset++; const ui64 value = counters->Simple()[i].Get(); - AggregatedSimpleCounters.SetValue(tabletID, offset, value, tabletType); + simpleValues[offset] = value; } + AggregatedSimpleCounters.SetValues(tabletId, simpleValues, tabletType); // cumulative counters ui32 nextCumulativeOffset = 0; + TVector<ui64> cumulativeValues; + cumulativeValues.resize(FullSizeCumulative, 0); for (ui32 i = 0; i < FullSizeCumulative; ++i) { if (!counters->CumulativeCounterName(i)) { continue; @@ -518,12 +523,12 @@ private: const ui32 offset = nextCumulativeOffset++; const ui64 valueDiff = counters->Cumulative()[i].Get(); if (diff) { - const ui64 diffValue = valueDiff * 1000000 / diff.MicroSeconds(); // differentiate value to per second rate - AggregatedCumulativeCounters.SetValue(tabletID, offset, diffValue, tabletType); + cumulativeValues[offset] = valueDiff * 1000000 / diff.MicroSeconds(); // differentiate value to per second rate } Y_VERIFY(offset < CumulativeCounters.size(), "inconsistent counters for tablet type %s", TTabletTypes::TypeToStr(tabletType)); *CumulativeCounters[offset] += valueDiff; } + AggregatedCumulativeCounters.SetValues(tabletId, cumulativeValues, tabletType); // percentile counters ui32 nextPercentileOffset = 0; @@ -534,12 +539,13 @@ private: const ui32 offset = nextPercentileOffset++; AggregatedHistogramCounters.SetValue( - tabletID, + tabletId, offset, counters->Percentile()[i], counters->PercentileCounterName(i), tabletType); } + } void Forget(ui64 tabletId) { |