Skip to content

Commit da66c07

Browse files
committed
Adjust cost bucket capacity dynamically (ydb-platform#1681)
* Adjust cost bucket capacity dynamically * ui32 for BlobSize
1 parent 18be884 commit da66c07

5 files changed

Lines changed: 36 additions & 8 deletions

File tree

ydb/core/base/blobstorage_grouptype.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ ui64 TBlobStorageGroupType::PartSize(const TLogoBlobID &id) const {
196196

197197
ui64 TBlobStorageGroupType::MaxPartSize(const TLogoBlobID &id) const {
198198
Y_ABORT_UNLESS(!id.PartId());
199-
return TErasureType::PartSize((TErasureType::ECrcMode)id.CrcMode(), id.BlobSize());
199+
return MaxPartSize((TErasureType::ECrcMode)id.CrcMode(), id.BlobSize());
200+
}
201+
202+
ui64 TBlobStorageGroupType::MaxPartSize(TErasureType::ECrcMode crcMode, ui32 blobSize) const {
203+
return TErasureType::PartSize(crcMode, blobSize);
200204
}
201205

202206
bool TBlobStorageGroupType::PartFits(ui32 partId, ui32 idxInSubgroup) const {

ydb/core/base/blobstorage_grouptype.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ struct TBlobStorageGroupType : public TErasureType {
144144

145145
ui64 PartSize(const TLogoBlobID &id) const;
146146
ui64 MaxPartSize(const TLogoBlobID &id) const;
147+
ui64 MaxPartSize(TErasureType::ECrcMode crcMode, ui32 blobSize) const;
147148

148149
bool PartFits(ui32 partId, ui32 idxInSubgroup) const;
149150
};

ydb/core/blobstorage/ut_blobstorage/monitoring.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,13 @@ void TestBurst(const TBlobStorageGroupInfo::TTopology& topology, TInflightActor*
440440
#define MAKE_BURST_TEST(requestType, requests, inflight, delay, distribution) \
441441
Y_UNIT_TEST(Test##requestType##distribution) { \
442442
TBlobStorageGroupInfo::TTopology topology(TBlobStorageGroupType::ErasureNone, 1, 1, 1, true); \
443-
auto* actor = new TInflightActor##requestType({requests, inflight, delay}, 10_KB); \
443+
auto* actor = new TInflightActor##requestType({requests, inflight, delay}, 8_MB); \
444444
TestBurst(topology, actor, ELoadDistribution::Distribution##distribution); \
445445
}
446446

447447
Y_UNIT_TEST_SUITE(BurstDetection) {
448-
MAKE_BURST_TEST(Put, 3000, 1, TDuration::MilliSeconds(5), Evenly);
449-
MAKE_BURST_TEST(Put, 3000, 1000000, TDuration::Zero(), Burst);
448+
MAKE_BURST_TEST(Put, 50, 1, TDuration::MilliSeconds(100), Evenly);
449+
MAKE_BURST_TEST(Put, 50, 100, TDuration::Zero(), Burst);
450450
}
451451

452452
#undef MAKE_BURST_TEST

ydb/core/blobstorage/vdisk/common/blobstorage_cost_tracker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TBsCostTracker::TBsCostTracker(const TBlobStorageGroupType& groupType, NPDisk::E
5050
, ScrubDiskCost(CostCounters->GetCounter("ScrubDiskCost", true))
5151
, DefragDiskCost(CostCounters->GetCounter("DefragDiskCost", true))
5252
, InternalDiskCost(CostCounters->GetCounter("InternalDiskCost", true))
53-
, Bucket(1'000'000'000, BucketCapacity)
53+
, Bucket(&BucketInflow, &BucketCapacity, nullptr, nullptr, nullptr, nullptr, true)
5454
{
5555
BurstDetector.Initialize(CostCounters, "BurstDetector");
5656
switch (GroupType.GetErasure()) {
@@ -67,6 +67,7 @@ TBsCostTracker::TBsCostTracker(const TBlobStorageGroupType& groupType, NPDisk::E
6767
CostModel = std::make_unique<TBsCostModelErasureNone>(diskType);
6868
break;
6969
}
70+
UpdateBucketCapacity();
7071
}
7172

7273
} // NKikimr

ydb/core/blobstorage/vdisk/common/blobstorage_cost_tracker.h

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <library/cpp/bucket_quoter/bucket_quoter.h>
99
#include <util/system/compiler.h>
10+
#include <ydb/core/base/blobstorage.h>
1011
#include <ydb/core/blobstorage/base/blobstorage_events.h>
1112
#include <ydb/core/util/light.h>
1213

@@ -50,6 +51,8 @@ class TBsCostModelBase {
5051

5152
virtual ~TBsCostModelBase() = default;
5253

54+
friend class TBsCostTracker;
55+
5356
protected:
5457
NPDisk::EDeviceType DeviceType = NPDisk::DEVICE_TYPE_UNKNOWN;
5558

@@ -292,10 +295,12 @@ class TBsCostTracker {
292295
::NMonitoring::TDynamicCounters::TCounterPtr DefragDiskCost;
293296
::NMonitoring::TDynamicCounters::TCounterPtr InternalDiskCost;
294297

298+
TAtomic BucketCapacity = 1'000'000'000; // 10^9 nsec
299+
TAtomic BucketInflow = 1'000'000'000; // 10^9 nsec
295300
TBucketQuoter<i64, TSpinLock, THPTimerUs> Bucket;
296-
static constexpr ui64 BucketCapacity = 1'000'000'000;
297301
TLight BurstDetector;
298302
std::atomic<ui64> SeqnoBurstDetector = 0;
303+
static constexpr ui32 ConcurrentHugeRequestsAllowed = 3;
299304

300305
public:
301306
TBsCostTracker(const TBlobStorageGroupType& groupType, NPDisk::EDeviceType diskType,
@@ -312,14 +317,31 @@ class TBsCostTracker {
312317
return cost;
313318
}
314319

315-
/// SETTINGS
316-
void UpdateFromVDiskSettings(NKikimrBlobStorage::TVDiskCostSettings &settings) const;
320+
private:
321+
void UpdateBucketCapacity() {
322+
if (!CostModel) {
323+
return;
324+
}
325+
ui64 maxPartSize = GroupType.MaxPartSize(TBlobStorageGroupType::ECrcMode::CrcModeWholePart, MaxVDiskBlobSize);
326+
ui64 maxHugePartSize = GroupType.MaxPartSize(TBlobStorageGroupType::ECrcMode::CrcModeWholePart,
327+
CostModel->HugeBlobSize);
328+
ui64 capacity = std::max({
329+
CostModel->ReadCost(maxHugePartSize),
330+
CostModel->WriteCost(maxPartSize),
331+
CostModel->HugeWriteCost(maxHugePartSize)
332+
}) * ConcurrentHugeRequestsAllowed;
333+
334+
if (capacity != (ui64)AtomicGet(BucketCapacity)) {
335+
AtomicSet(BucketCapacity, capacity);
336+
}
337+
}
317338

318339
public:
319340
void UpdateCostModel(const TCostModel& costModel) {
320341
if (CostModel) {
321342
CostModel->Update(costModel);
322343
}
344+
UpdateBucketCapacity();
323345
}
324346

325347
void CountRequest(ui64 cost) {

0 commit comments

Comments
 (0)