Skip to content

Commit 7860ed1

Browse files
authored
25-3-1: schemeshard: stats processing opt 1 (#28226)
Cherry-pick from `main`: - 626410b, #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 ShardInfos - 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
2 parents 4f77aed + 73da610 commit 7860ed1

File tree

11 files changed

+191
-132
lines changed

11 files changed

+191
-132
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
@@ -1845,6 +1845,8 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
18451845
}
18461846
}
18471847

1848+
tableInfo->IsExternalBlobsEnabled = PartitionConfigHasExternalBlobsEnabled(tableInfo->PartitionConfig());
1849+
18481850
TString alterTabletFull = std::get<4>(rec);
18491851
TString alterTabletDiff = std::get<5>(rec);
18501852
if (alterTabletFull) {
@@ -2384,6 +2386,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
23842386

23852387
TPathId prevTableId;
23862388

2389+
TInstant now = AppData()->TimeProvider->Now();
23872390
while (!rowSet.EndOfSet()) {
23882391
const TPathId tableId = TPathId(
23892392
rowSet.GetValue<Schema::TablePartitionStats::TableOwnerId>(),
@@ -2460,7 +2463,6 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
24602463
stats.RangeReads = rowSet.GetValue<Schema::TablePartitionStats::RangeReads>();
24612464
stats.RangeReadRows = rowSet.GetValue<Schema::TablePartitionStats::RangeReadRows>();
24622465

2463-
TInstant now = AppData(ctx)->TimeProvider->Now();
24642466
stats.SetCurrentRawCpuUsage(rowSet.GetValue<Schema::TablePartitionStats::CPU>(), now);
24652467
stats.Memory = rowSet.GetValue<Schema::TablePartitionStats::Memory>();
24662468
stats.Network = rowSet.GetValue<Schema::TablePartitionStats::Network>();
@@ -2478,7 +2480,8 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
24782480
stats.LocksWholeShard = rowSet.GetValueOrDefault<Schema::TablePartitionStats::LocksWholeShard>();
24792481
stats.LocksBroken = rowSet.GetValueOrDefault<Schema::TablePartitionStats::LocksBroken>();
24802482

2481-
tableInfo->UpdateShardStats(shardIdx, stats);
2483+
TDiskSpaceUsageDelta unusedDelta;
2484+
tableInfo->UpdateShardStats(&unusedDelta, shardIdx, stats, now);
24822485

24832486
// note that we don't update shard metrics here, because we will always update
24842487
// 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
@@ -124,7 +124,7 @@ class TTxStoreStats: public NTabletFlatExecutor::TTransactionBase<TSchemeShard>
124124
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override;
125125

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

129129
virtual void ScheduleNextBatch(const TActorContext& ctx) = 0;
130130
};

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)