Skip to content

Commit 24c0509

Browse files
committed
schemeshard: stats processing optimizations (#27165)
Streamline and optimize datashard statistics processing. Profile guided optimizations of PersistSingleStats() (in synthetic test). Total gain is around 30%. - remove unreasonable iteration over entire ShardInfoscommits/6fefb4b0d08afdd7a9430d54d3d5d70e7bf00100) - single Now() timestamp for entire stats batch - optimize number of lookups - stop building now unnecessary storage pool kind mappings - remove table/store aggregated stats copying - collect ExternalBlobsEnabled only on PartitionConfig change - replace ETxType->CounterId map with absl::flat_hash_map - remove extra OpType->TxType lookup - remove call to GetMainTableForIndex for not-index-table shards
1 parent dc3f368 commit 24c0509

File tree

11 files changed

+196
-134
lines changed

11 files changed

+196
-134
lines changed

ydb/core/tx/schemeshard/olap/store/store.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ struct TOlapStoreInfo {
147147

148148
ILayoutPolicy::TPtr GetTablesLayoutPolicy() const;
149149

150-
void UpdateShardStats(TShardIdx shardIdx, const TPartitionStats& newStats) {
150+
void UpdateShardStats(TDiskSpaceUsageDelta* diskSpaceUsageDelta, TShardIdx shardIdx, const TPartitionStats& newStats, TInstant now) {
151151
Stats.Aggregated.PartCount = ColumnShards.size();
152152
Stats.PartitionStats[shardIdx]; // insert if none
153-
Stats.UpdateShardStats(shardIdx, newStats);
153+
Stats.UpdateShardStats(diskSpaceUsageDelta, shardIdx, newStats, now);
154154
}
155155
};
156156

157-
}
157+
}

ydb/core/tx/schemeshard/olap/table/table.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ struct TColumnTableInfo {
103103
return Stats;
104104
}
105105

106-
void UpdateShardStats(const TShardIdx shardIdx, const TPartitionStats& newStats) {
106+
void UpdateShardStats(TDiskSpaceUsageDelta* diskSpaceUsageDelta, const TShardIdx shardIdx, const TPartitionStats& newStats, TInstant now) {
107107
Stats.Aggregated.PartCount = GetColumnShards().size();
108108
Stats.PartitionStats[shardIdx]; // insert if none
109-
Stats.UpdateShardStats(shardIdx, newStats);
109+
Stats.UpdateShardStats(diskSpaceUsageDelta, shardIdx, newStats, now);
110110
}
111111

112-
void UpdateTableStats(const TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats) {
112+
void UpdateTableStats(TDiskSpaceUsageDelta* diskSpaceUsageDelta, const TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats, TInstant now) {
113113
Stats.TableStats[pathId].Aggregated.PartCount = GetColumnShards().size();
114-
Stats.UpdateTableStats(shardIdx, pathId, newStats);
114+
Stats.UpdateTableStats(diskSpaceUsageDelta, shardIdx, pathId, newStats, now);
115115
}
116116

117117
TConclusion<std::shared_ptr<NOlap::NAlter::ISSEntity>> BuildEntity(const TPathId& pathId, const NOlap::NAlter::TEntityInitializationContext& iContext) const;

ydb/core/tx/schemeshard/schemeshard__init.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,8 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
18341834
}
18351835
}
18361836

1837+
tableInfo->IsExternalBlobsEnabled = PartitionConfigHasExternalBlobsEnabled(tableInfo->PartitionConfig());
1838+
18371839
TString alterTabletFull = std::get<4>(rec);
18381840
TString alterTabletDiff = std::get<5>(rec);
18391841
if (alterTabletFull) {
@@ -2328,6 +2330,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
23282330

23292331
TPathId prevTableId;
23302332

2333+
TInstant now = AppData()->TimeProvider->Now();
23312334
while (!rowSet.EndOfSet()) {
23322335
const TPathId tableId = TPathId(
23332336
rowSet.GetValue<Schema::TablePartitionStats::TableOwnerId>(),
@@ -2404,7 +2407,6 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
24042407
stats.RangeReads = rowSet.GetValue<Schema::TablePartitionStats::RangeReads>();
24052408
stats.RangeReadRows = rowSet.GetValue<Schema::TablePartitionStats::RangeReadRows>();
24062409

2407-
TInstant now = AppData(ctx)->TimeProvider->Now();
24082410
stats.SetCurrentRawCpuUsage(rowSet.GetValue<Schema::TablePartitionStats::CPU>(), now);
24092411
stats.Memory = rowSet.GetValue<Schema::TablePartitionStats::Memory>();
24102412
stats.Network = rowSet.GetValue<Schema::TablePartitionStats::Network>();
@@ -2422,7 +2424,8 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
24222424
stats.LocksWholeShard = rowSet.GetValueOrDefault<Schema::TablePartitionStats::LocksWholeShard>();
24232425
stats.LocksBroken = rowSet.GetValueOrDefault<Schema::TablePartitionStats::LocksBroken>();
24242426

2425-
tableInfo->UpdateShardStats(shardIdx, stats);
2427+
TDiskSpaceUsageDelta unusedDelta;
2428+
tableInfo->UpdateShardStats(&unusedDelta, shardIdx, stats, now);
24262429

24272430
// note that we don't update shard metrics here, because we will always update
24282431
// the shard metrics in TSchemeShard::SetPartitioning

ydb/core/tx/schemeshard/schemeshard__pq_stats.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class TTxStoreTopicStats: public TTxStoreStats<TEvPersQueue::TEvPeriodicTopicSta
2222
void Complete(const TActorContext& ) override;
2323

2424
// returns true to continue batching
25-
bool PersistSingleStats(const TPathId& pathId, const TStatsQueue<TEvPersQueue::TEvPeriodicTopicStats>::TItem& item, TTransactionContext& txc, const TActorContext& ctx) override;
25+
bool PersistSingleStats(const TPathId& pathId, const TStatsQueue<TEvPersQueue::TEvPeriodicTopicStats>::TItem& item, TInstant now, TTransactionContext& txc, const TActorContext& ctx) override;
2626
void ScheduleNextBatch(const TActorContext& ctx) override;
2727
};
2828

2929

30-
bool TTxStoreTopicStats::PersistSingleStats(const TPathId& pathId, const TStatsQueueItem<TEvPersQueue::TEvPeriodicTopicStats>& item, TTransactionContext& txc, const TActorContext& ctx) {
30+
bool TTxStoreTopicStats::PersistSingleStats(const TPathId& pathId, const TStatsQueueItem<TEvPersQueue::TEvPeriodicTopicStats>& item, TInstant /*now*/, TTransactionContext& txc, const TActorContext& ctx) {
3131
const auto& rec = item.Ev->Get()->Record;
3232

3333
TTopicStats newStats;

ydb/core/tx/schemeshard/schemeshard__stats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class TTxStoreStats: public NTabletFlatExecutor::TTransactionBase<TSchemeShard>
122122
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override;
123123

124124
// returns true to continue batching
125-
virtual bool PersistSingleStats(const TPathId& pathId, const TItem& item, TTransactionContext& txc, const TActorContext& ctx) = 0;
125+
virtual bool PersistSingleStats(const TPathId& pathId, const TItem& item, TInstant now, TTransactionContext& txc, const TActorContext& ctx) = 0;
126126

127127
virtual void ScheduleNextBatch(const TActorContext& ctx) = 0;
128128
};

ydb/core/tx/schemeshard/schemeshard__stats_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@ bool TTxStoreStats<TEvent>::Execute(NTabletFlatExecutor::TTransactionContext& tx
118118
return true;
119119
}
120120

121+
TInstant now = AppData(ctx)->TimeProvider->Now();
121122
TMonotonic start = TMonotonic::Now();
122123
const ui32 maxBatchSize = Queue.MaxBatchSize();
123124
ui32 batchSize = 0;
124125
for (; batchSize < maxBatchSize && !Queue.Empty(); ++batchSize) {
125126
auto item = Queue.Next();
126127
Queue.WriteLatencyMetric(item);
127-
if (!PersistSingleStats(item.PathId(), item, txc, ctx)) {
128+
if (!PersistSingleStats(item.PathId(), item, now, txc, ctx)) {
128129
break;
129130
}
130131

0 commit comments

Comments
 (0)