Skip to content

Commit b157ab6

Browse files
authored
early skip of irrelevant objects in object distributions (#5482)
1 parent 2fd1145 commit b157ab6

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

ydb/core/mind/hive/object_distribution.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct TObjectDistribution {
7272
}
7373

7474
void UpdateCount(const TNodeInfo& node, i64 diff) {
75-
if (!node.MatchesFilter(NodeFilter) || !node.IsAllowedToRunTablet()) {
75+
if (!node.IsAllowedToRunTablet()) {
7676
// We should not use this node for computing imbalance, hence we ignore it in SortedDistribution
7777
// But we still account for it in Distribution, because it might become relevant later
7878
Distribution[node.Id] += diff;
@@ -216,7 +216,9 @@ struct TObjectDistributions {
216216
return;
217217
}
218218
for (const auto& [obj, it] : Distributions) {
219-
UpdateCount(obj, node, 0);
219+
if (node.MatchesFilter(it->NodeFilter)) {
220+
UpdateCount(obj, node, 0);
221+
}
220222
}
221223
}
222224

ydb/core/mind/hive/object_distribution_ut.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "hive_impl.h"
33
#include "object_distribution.h"
44

5+
#include <util/datetime/cputimer.h>
56
#include <util/stream/null.h>
67

78
#include <map>
@@ -16,7 +17,7 @@ using namespace NHive;
1617
#define Ctest Cerr
1718
#endif
1819

19-
Y_UNIT_TEST_SUITE(ObjectDistribuiton) {
20+
Y_UNIT_TEST_SUITE(ObjectDistribution) {
2021
Y_UNIT_TEST(TestImbalanceCalcualtion) {
2122
static constexpr size_t NUM_NODES = 8;
2223
static constexpr size_t NUM_OBJECTS = 250;
@@ -245,4 +246,50 @@ Y_UNIT_TEST_SUITE(ObjectDistribuiton) {
245246
UNIT_ASSERT_VALUES_EQUAL(imbalance, objectDistributions.GetMaxImbalance());
246247

247248
}
249+
250+
Y_UNIT_TEST(TestManyIrrelevantNodes) {
251+
static constexpr size_t NUM_NODES = 10'000;
252+
static constexpr size_t NUM_OBJECTS = 10'000;
253+
static constexpr TSubDomainKey DOMAIN_A = {1, 1};
254+
static constexpr TSubDomainKey DOMAIN_B = {2, 2};
255+
256+
TIntrusivePtr<TTabletStorageInfo> hiveStorage = new TTabletStorageInfo;
257+
hiveStorage->TabletType = TTabletTypes::Hive;
258+
THive hive(hiveStorage.Get(), TActorId());
259+
260+
std::unordered_map<TNodeId, TNodeInfo> nodes;
261+
TObjectDistributions objectDistributions(nodes);
262+
NKikimrLocal::TTabletAvailability dummyTabletAvailability;
263+
dummyTabletAvailability.SetType(TTabletTypes::Dummy);
264+
for (TNodeId nodeId = 0; nodeId < NUM_NODES; ++nodeId) {
265+
TNodeInfo& node = nodes.emplace(std::piecewise_construct, std::tuple<TNodeId>(nodeId), std::tuple<TNodeId, THive&>(nodeId, hive)).first->second;
266+
node.ServicedDomains.push_back(nodeId == 0 ? DOMAIN_A : DOMAIN_B);
267+
node.RegisterInDomains();
268+
node.LocationAcquired = true;
269+
node.TabletAvailability.emplace(std::piecewise_construct,
270+
std::tuple<TTabletTypes::EType>(TTabletTypes::Dummy),
271+
std::tuple<NKikimrLocal::TTabletAvailability>(dummyTabletAvailability));
272+
}
273+
274+
for (size_t i = 0; i < NUM_OBJECTS; i++) {
275+
TLeaderTabletInfo tablet(0, hive);
276+
tablet.AssignDomains(DOMAIN_A, {});
277+
tablet.ObjectId = {1, i + 1};
278+
tablet.SetType(TTabletTypes::Dummy);
279+
objectDistributions.UpdateCountForTablet(tablet, nodes.at(0), +1);
280+
}
281+
282+
TProfileTimer timer;
283+
for (const auto& [nodeId, node] : nodes) {
284+
objectDistributions.AddNode(node);
285+
}
286+
287+
double passed = timer.Get().SecondsFloat();
288+
Cerr << "Took " << passed << " seconds" << Endl;
289+
#ifndef SANITIZER_TYPE
290+
#ifdef NDEBUG
291+
UNIT_ASSERT_GE(NUM_NODES / passed, 1000);
292+
#endif
293+
#endif
294+
}
248295
}

0 commit comments

Comments
 (0)