Skip to content

Commit 68afe24

Browse files
authored
Fix CostMetrics* tests (#1944)
1 parent 3d20d64 commit 68afe24

File tree

3 files changed

+68
-34
lines changed

3 files changed

+68
-34
lines changed

.github/config/muted_ya.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
ydb/core/blobstorage/dsproxy/ut TBlobStorageProxySequenceTest.TestBlock42PutWithChangingSlowDisk
22
ydb/core/blobstorage/dsproxy/ut_fat TBlobStorageProxyTest.TestBatchedPutRequestDoesNotContainAHugeBlob
3-
ydb/core/blobstorage/ut_blobstorage CostMetrics*
43
ydb/core/client/ut TClientTest.PromoteFollower
54
ydb/core/client/ut TClientTest.ReadFromFollower
65
ydb/core/client/ut TFlatTest.AutoSplitMergeQueue

ydb/core/blobstorage/ut_blobstorage/monitoring.cpp

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ TString MakeData(ui32 dataSize) {
1212
return data;
1313
}
1414

15-
ui64 AggregateVDiskCounters(std::unique_ptr<TEnvironmentSetup>& env, const NKikimrBlobStorage::TBaseConfig& baseConfig,
16-
TString storagePool, ui32 groupSize, ui32 groupId, const std::vector<ui32>& pdiskLayout, TString subsystem,
17-
TString counter, bool derivative = false) {
15+
ui64 AggregateVDiskCounters(std::unique_ptr<TEnvironmentSetup>& env, TString storagePool, ui32 nodesCount, ui32 groupId,
16+
const std::vector<ui32>& pdiskLayout, TString subsystem, TString counter, bool derivative = false) {
1817
ui64 ctr = 0;
1918

20-
for (const auto& vslot : baseConfig.GetVSlot()) {
21-
auto* appData = env->Runtime->GetNode(vslot.GetVSlotId().GetNodeId())->AppData.get();
22-
for (ui32 i = 0; i < groupSize; ++i) {
19+
for (ui32 nodeId = 1; nodeId <= nodesCount; ++nodeId) {
20+
auto* appData = env->Runtime->GetNode(nodeId)->AppData.get();
21+
for (ui32 i = 0; i < nodesCount; ++i) {
2322
ctr += GetServiceCounters(appData->Counters, "vdisks")->
2423
GetSubgroup("storagePool", storagePool)->
2524
GetSubgroup("group", std::to_string(groupId))->
@@ -34,8 +33,7 @@ ui64 AggregateVDiskCounters(std::unique_ptr<TEnvironmentSetup>& env, const NKiki
3433
};
3534

3635
void SetupEnv(const TBlobStorageGroupInfo::TTopology& topology, std::unique_ptr<TEnvironmentSetup>& env,
37-
NKikimrBlobStorage::TBaseConfig& baseConfig, ui32& groupSize, TBlobStorageGroupType& groupType,
38-
ui32& groupId, std::vector<ui32>& pdiskLayout) {
36+
ui32& groupSize, TBlobStorageGroupType& groupType, ui32& groupId, std::vector<ui32>& pdiskLayout) {
3937
groupSize = topology.TotalVDisks;
4038
groupType = topology.GType;
4139
env.reset(new TEnvironmentSetup({
@@ -51,7 +49,7 @@ void SetupEnv(const TBlobStorageGroupInfo::TTopology& topology, std::unique_ptr<
5149
request.AddCommand()->MutableQueryBaseConfig();
5250
auto response = env->Invoke(request);
5351

54-
baseConfig = response.GetStatus(0).GetBaseConfig();
52+
const auto& baseConfig = response.GetStatus(0).GetBaseConfig();
5553
UNIT_ASSERT_VALUES_EQUAL(baseConfig.GroupSize(), 1);
5654
groupId = baseConfig.GetGroup(0).GetGroupId();
5755
pdiskLayout.resize(groupSize);
@@ -67,51 +65,79 @@ void SetupEnv(const TBlobStorageGroupInfo::TTopology& topology, std::unique_ptr<
6765
template <typename TInflightActor>
6866
void TestDSProxyAndVDiskEqualCost(const TBlobStorageGroupInfo::TTopology& topology, TInflightActor* actor) {
6967
std::unique_ptr<TEnvironmentSetup> env;
70-
NKikimrBlobStorage::TBaseConfig baseConfig;
7168
ui32 groupSize;
7269
TBlobStorageGroupType groupType;
7370
ui32 groupId;
7471
std::vector<ui32> pdiskLayout;
75-
SetupEnv(topology, env, baseConfig, groupSize, groupType, groupId, pdiskLayout);
72+
SetupEnv(topology, env, groupSize, groupType, groupId, pdiskLayout);
7673

7774
ui64 dsproxyCost = 0;
7875
ui64 vdiskCost = 0;
76+
ui64 queuePut = 0;
77+
ui64 queueSent = 0;
78+
79+
std::vector<TString> priorities = {
80+
"GetAsyncRead", "GetDiscover", "GetFastRead", "GetLowRead",
81+
"PutAsyncBlob", "PutTabletLog", "PutUserData"
82+
};
7983

8084
auto updateCounters = [&]() {
8185
dsproxyCost = 0;
86+
queuePut = 0;
87+
queueSent = 0;
8288

83-
for (const auto& vslot : baseConfig.GetVSlot()) {
84-
auto* appData = env->Runtime->GetNode(vslot.GetVSlotId().GetNodeId())->AppData.get();
89+
for (ui32 nodeId = 1; nodeId <= groupSize; ++nodeId) {
90+
auto* appData = env->Runtime->GetNode(nodeId)->AppData.get();
8591
dsproxyCost += GetServiceCounters(appData->Counters, "dsproxynode")->
8692
GetSubgroup("subsystem", "request")->
8793
GetSubgroup("storagePool", env->StoragePoolName)->
8894
GetCounter("DSProxyDiskCostNs")->Val();
95+
96+
for (TString priority : priorities) {
97+
queuePut += GetServiceCounters(appData->Counters, "dsproxy_queue")->
98+
GetSubgroup("queue", priority)->
99+
GetCounter("QueueItemsPut")->Val();
100+
queueSent += GetServiceCounters(appData->Counters, "dsproxy_queue")->
101+
GetSubgroup("queue", priority)->
102+
GetCounter("QueueItemsSent")->Val();
103+
}
89104
}
90-
vdiskCost = AggregateVDiskCounters(env, baseConfig, env->StoragePoolName, groupSize, groupId,
91-
pdiskLayout, "cost", "SkeletonFrontUserCostNs");
105+
vdiskCost = AggregateVDiskCounters(env, env->StoragePoolName, groupSize, groupId, pdiskLayout,
106+
"cost", "SkeletonFrontUserCostNs");
92107
};
93108

94109
updateCounters();
95110
UNIT_ASSERT_VALUES_EQUAL(dsproxyCost, vdiskCost);
96111

97112
actor->SetGroupId(groupId);
98113
env->Runtime->Register(actor, 1);
99-
env->Sim(TDuration::Minutes(15));
114+
env->Sim(TDuration::Minutes(5));
100115

116+
updateCounters();
117+
env->Sim(TDuration::Minutes(5));
101118
updateCounters();
102119

103120
TStringStream str;
104121
double proportion = 1. * dsproxyCost / vdiskCost;
105122
i64 diff = (i64)dsproxyCost - vdiskCost;
106-
str << "OKs# " << actor->ResponsesByStatus[NKikimrProto::OK] << ", Errors# " << actor->ResponsesByStatus[NKikimrProto::ERROR]
107-
<< ", Cost on dsproxy# " << dsproxyCost << ", Cost on vdisks# " << vdiskCost << ", proportion# " << proportion
108-
<< " diff# " << diff;
123+
ui32 oks = actor->ResponsesByStatus[NKikimrProto::OK];
124+
ui32 errors = actor->ResponsesByStatus[NKikimrProto::ERROR];
125+
str << "OKs# " << oks << ", Errors# " << errors << ", QueueItemsPut# " << queuePut
126+
<< ", QueueItemsSent# " << queueSent << ", Cost on dsproxy# " << dsproxyCost
127+
<< ", Cost on vdisks# " << vdiskCost << ", proportion# " << proportion << " diff# " << diff;
109128

110129
if constexpr(VERBOSE) {
111130
Cerr << str.Str() << Endl;
112-
// env->Runtime->GetAppData()->Counters->OutputPlainText(Cerr);
131+
for (ui32 i = 1; i <= groupSize; ++i) {
132+
Cerr << " ##################### Node " << i << " ##################### " << Endl;
133+
env->Runtime->GetNode(i)->AppData->Counters->OutputPlainText(Cerr);
134+
}
135+
}
136+
137+
if (dsproxyCost == vdiskCost) {
138+
return;
113139
}
114-
UNIT_ASSERT_VALUES_EQUAL_C(dsproxyCost, vdiskCost, str.Str());
140+
UNIT_ASSERT_C(oks != actor->RequestsSent || queuePut != queueSent, str.Str());
115141
}
116142

117143
#define MAKE_TEST(erasure, requestType, requests, inflight) \
@@ -190,7 +216,6 @@ Y_UNIT_TEST_SUITE(CostMetricsGetHugeMirror3dc) {
190216
MAKE_TEST_W_DATASIZE(Mirror3dc, Get, 2, 2, 2000000);
191217
MAKE_TEST_W_DATASIZE(Mirror3dc, Get, 10, 10, 2000000);
192218
MAKE_TEST_W_DATASIZE(Mirror3dc, Get, 100, 10, 2000000);
193-
MAKE_TEST_W_DATASIZE(Mirror3dc, Get, 10000, 100, 2000000);
194219
}
195220

196221
Y_UNIT_TEST_SUITE(CostMetricsPatchMirror3dc) {
@@ -221,19 +246,18 @@ enum class ELoadDistribution : ui8 {
221246
template <typename TInflightActor>
222247
void TestBurst(const TBlobStorageGroupInfo::TTopology& topology, TInflightActor* actor, ELoadDistribution loadDistribution) {
223248
std::unique_ptr<TEnvironmentSetup> env;
224-
NKikimrBlobStorage::TBaseConfig baseConfig;
225249
ui32 groupSize;
226250
TBlobStorageGroupType groupType;
227251
ui32 groupId;
228252
std::vector<ui32> pdiskLayout;
229-
SetupEnv(topology, env, baseConfig, groupSize, groupType, groupId, pdiskLayout);
253+
SetupEnv(topology, env, groupSize, groupType, groupId, pdiskLayout);
230254

231255
actor->SetGroupId(groupId);
232256
env->Runtime->Register(actor, 1);
233257
env->Sim(TDuration::Minutes(10));
234258

235-
ui64 redMs = AggregateVDiskCounters(env, baseConfig, env->StoragePoolName, groupSize, groupId,
236-
pdiskLayout, "advancedCost", "BurstDetector_redMs");
259+
ui64 redMs = AggregateVDiskCounters(env, env->StoragePoolName, groupSize, groupId, pdiskLayout,
260+
"advancedCost", "BurstDetector_redMs");
237261

238262
if (loadDistribution == ELoadDistribution::DistributionBurst) {
239263
UNIT_ASSERT_VALUES_UNEQUAL(redMs, 0);

ydb/core/blobstorage/ut_blobstorage/ut_helpers.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,33 +135,44 @@ class TInflightActorGet : public TInflightActor {
135135
{}
136136

137137
STRICT_STFUNC(StateWork,
138-
cFunc(TEvBlobStorage::TEvPutResult::EventType, ScheduleRequests);
138+
cFunc(TEvBlobStorage::TEvPutResult::EventType, HandlePut);
139139
cFunc(TEvents::TEvWakeup::EventType, WakeupAndSchedule);
140140
hFunc(TEvBlobStorage::TEvGetResult, Handle);
141141
)
142142

143143
virtual void BootstrapImpl(const TActorContext&/* ctx*/) override {
144-
TString data = MakeData(DataSize);
145-
BlobId = TLogoBlobID(1, 1, 1, 10, DataSize, Cookie++);
146-
auto ev = new TEvBlobStorage::TEvPut(BlobId, data, TInstant::Max());
147-
SendToBSProxy(SelfId(), GroupId, ev, 0);
144+
for (ui32 i = 0; i < Settings.Requests; ++i) {
145+
TString data = MakeData(DataSize);
146+
TLogoBlobID blobId = TLogoBlobID(1, 1, 1, 10, DataSize, Cookie++);
147+
BlobIds.push_back(blobId);
148+
auto ev = new TEvBlobStorage::TEvPut(blobId, data, TInstant::Max());
149+
SendToBSProxy(SelfId(), GroupId, ev, 0);
150+
}
148151
Become(&TInflightActorGet::StateWork);
149152
}
150153

151154
protected:
152155
virtual void SendRequest() override {
153-
auto ev = new TEvBlobStorage::TEvGet(BlobId, 0, 10, TInstant::Max(), NKikimrBlobStorage::EGetHandleClass::FastRead);
156+
auto ev = new TEvBlobStorage::TEvGet(BlobIds[RequestsSent - 1], 0, DataSize, TInstant::Max(),
157+
NKikimrBlobStorage::EGetHandleClass::FastRead);
154158
SendToBSProxy(SelfId(), GroupId, ev, 0);
155159
}
156160

157161
void Handle(TEvBlobStorage::TEvGetResult::TPtr res) {
158162
HandleReply(res->Get()->Status);
159163
}
160164

165+
void HandlePut() {
166+
if (++BlobsWritten == Settings.Requests) {
167+
ScheduleRequests();
168+
}
169+
}
170+
161171
private:
162-
TLogoBlobID BlobId;
163172
std::string Data;
164173
ui32 DataSize;
174+
std::vector<TLogoBlobID> BlobIds;
175+
ui32 BlobsWritten = 0;
165176
};
166177

167178
/////////////////////////////////// TInflightActorPatch ///////////////////////////////////

0 commit comments

Comments
 (0)