Skip to content

Commit

Permalink
issue-2703: rename metric and change Take method
Browse files Browse the repository at this point in the history
  • Loading branch information
vladstepanyuk committed Dec 19, 2024
1 parent ed436ec commit a5e95c2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cloud/blockstore/config/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,6 @@ message TStorageServiceConfig
// Enabling direct copying of data between disk agents.
optional bool UseDirectCopyRange = 394;

// Enabling UsedQuota calculation as UsedIoQuota + UsedBandwidthQuota
// Enabling UsedQuota calculation as UsedIopsQuota + UsedBandwidthQuota
optional bool CalculateUsedQuotaFromOtherMetrics = 395;
}
4 changes: 2 additions & 2 deletions cloud/blockstore/libs/storage/core/disk_counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ struct TVolumeSelfCumulativeCounters
EPublishingPolicy::All,
TCumulativeCounter::ECounterType::Generic,
ECounterExpirationPolicy::Permanent};
TCounter UsedIoQuota{
TCounter UsedIopsQuota{
EPublishingPolicy::All,
TCumulativeCounter::ECounterType::Generic,
ECounterExpirationPolicy::Permanent};
Expand All @@ -637,7 +637,7 @@ struct TVolumeSelfCumulativeCounters
MakeMeta<&TVolumeSelfCumulativeCounters::ThrottlerPostponedRequests>(),
MakeMeta<&TVolumeSelfCumulativeCounters::ThrottlerSkippedRequests>(),
MakeMeta<&TVolumeSelfCumulativeCounters::UsedQuota>(),
MakeMeta<&TVolumeSelfCumulativeCounters::UsedIoQuota>(),
MakeMeta<&TVolumeSelfCumulativeCounters::UsedIopsQuota>(),
MakeMeta<&TVolumeSelfCumulativeCounters::UsedBandwidthQuota>(),
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct TVolumeThrottlingPolicy::TImpl
double WriteCostMultiplier = 1;
ui32 PostponedWeight = 0;

double UsedIoQuota = 0;
double UsedIopsQuota = 0;
double UsedBandwidthQuota = 0;

TImpl(
Expand Down Expand Up @@ -266,7 +266,7 @@ struct TVolumeThrottlingPolicy::TImpl
m * (static_cast<double>(bandwidthUpdate) /
static_cast<double>(recalculatedMaxBandwidth));
}
UsedIoQuota += m * (1.0 / recalculatedMaxIops);
UsedIopsQuota += m * (1.0 / recalculatedMaxIops);
return TDuration::Zero();
}

Expand Down Expand Up @@ -296,18 +296,13 @@ struct TVolumeThrottlingPolicy::TImpl
return Bucket.CalculateCurrentSpentBudgetShare(ts);
}

double TakeUsedIoQuota()
std::pair<double, double> TakeUsedQuota()
{
auto res = UsedIoQuota;
UsedIoQuota = 0;
return res;
}

double TakeUsedBandwidthQuota()
{
auto res = UsedBandwidthQuota;
auto result = std::make_pair(UsedIopsQuota, UsedBandwidthQuota);
UsedIopsQuota = 0;
UsedBandwidthQuota = 0;
return res;

return result;
}
};

Expand Down Expand Up @@ -416,14 +411,9 @@ double TVolumeThrottlingPolicy::CalculateCurrentSpentBudgetShare(TInstant ts) co
return Impl->CalculateCurrentSpentBudgetShare(ts);
}

double TVolumeThrottlingPolicy::TakeUsedIoQuota()
{
return Impl->TakeUsedIoQuota();
}

double TVolumeThrottlingPolicy::TakeUsedBandwidthQuota()
std::pair<double, double> TVolumeThrottlingPolicy::TakeUsedQuota()
{
return Impl->TakeUsedBandwidthQuota();
return Impl->TakeUsedQuota();
}

const TBackpressureReport& TVolumeThrottlingPolicy::GetCurrentBackpressure() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class TVolumeThrottlingPolicy final
TDuration GetCurrentBoostBudget() const;
ui32 CalculatePostponedWeight() const;
double CalculateCurrentSpentBudgetShare(TInstant ts) const;
[[nodiscard]] double TakeUsedIoQuota();
[[nodiscard]] double TakeUsedBandwidthQuota();
// Returns pair of UsedIopsQuota and UsedBandwidthQuota.
[[nodiscard]] std::pair<double, double> TakeUsedQuota();
const TBackpressureReport& GetCurrentBackpressure() const;
const NProto::TVolumePerformanceProfile& GetConfig() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,21 +679,26 @@ Y_UNIT_TEST_SUITE(TVolumeThrottlingPolicyTest)
auto recalculatedMaxBandwidth =
CalculateThrottlerC2(maxIops, maxBandwidth);

const auto [usedIopsQuota, usedBandwidthQuota] = tp.TakeUsedQuota();

UNIT_ASSERT_DOUBLES_EQUAL(
tp.TakeUsedBandwidthQuota(),
usedBandwidthQuota,
static_cast<double>(ioOperation * byteCount) /
static_cast<double>(recalculatedMaxBandwidth),
1e-6);

UNIT_ASSERT_DOUBLES_EQUAL(tp.TakeUsedBandwidthQuota(), 0, 1e-6);

UNIT_ASSERT_DOUBLES_EQUAL(
tp.TakeUsedIoQuota(),
usedIopsQuota,
static_cast<double>(ioOperation) /
static_cast<double>(recalculatedMaxIops),
1e-6);

UNIT_ASSERT_DOUBLES_EQUAL(tp.TakeUsedIoQuota(), 0, 1e-6);
auto [usedIopsQuotaAfterTake, usedBandwidthQuotaAfterTake] =
tp.TakeUsedQuota();

UNIT_ASSERT_DOUBLES_EQUAL(usedIopsQuotaAfterTake, 0, 1e-6);

UNIT_ASSERT_DOUBLES_EQUAL(usedBandwidthQuotaAfterTake, 0, 1e-6);
}

Y_UNIT_TEST(UsedBandwidthQuotaZeroWithoutBytesThrotling)
Expand Down Expand Up @@ -726,13 +731,12 @@ Y_UNIT_TEST_SUITE(TVolumeThrottlingPolicyTest)
DO_TEST(tp, 0, 0, byteCount, static_cast<ui32>(EOpType::Read));
}

UNIT_ASSERT_DOUBLES_EQUAL(
tp.TakeUsedBandwidthQuota(),
0,
1e-6);
const auto [usedIopsQuota, usedBandwidthQuota] = tp.TakeUsedQuota();

UNIT_ASSERT_DOUBLES_EQUAL(usedBandwidthQuota, 0, 1e-6);

UNIT_ASSERT_DOUBLES_EQUAL(
tp.TakeUsedIoQuota(),
usedIopsQuota,
static_cast<double>(ioOperation) / static_cast<double>(maxIops),
1e-6);
}
Expand Down
7 changes: 3 additions & 4 deletions cloud/blockstore/libs/storage/volume/volume_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,17 @@ void TVolumeActor::UpdateLeakyBucketCounters(const TActorContext& ctx)
auto& cumulative = VolumeSelfCounters->Cumulative;
auto& tp = State->AccessThrottlingPolicy();

auto usedIoQuota = tp.TakeUsedIoQuota();
auto usedBandwidthQuota = tp.TakeUsedBandwidthQuota();
auto [usedIopsQuota, usedBandwidthQuota] = tp.TakeUsedQuota();

cumulative.UsedIoQuota.Increment(static_cast<ui64>(usedIoQuota * 100.0));
cumulative.UsedIopsQuota.Increment(static_cast<ui64>(usedIopsQuota * 100.0));
cumulative.UsedBandwidthQuota.Increment(
static_cast<ui64>(usedBandwidthQuota * 100.0));

auto currentRate = static_cast<ui64>(Min(
[&]()
{
if (Config->GetCalculateUsedQuotaFromOtherMetrics()) {
return (usedIoQuota + usedBandwidthQuota) * 100.0;
return (usedIopsQuota + usedBandwidthQuota) * 100.0;
}
return tp.CalculateCurrentSpentBudgetShare(ctx.Now()) * 100.0;
}(),
Expand Down

0 comments on commit a5e95c2

Please sign in to comment.