Skip to content

Commit

Permalink
issue-2703: correct issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vladstepanyuk committed Dec 16, 2024
1 parent 75ed07a commit 0bb682e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ struct TVolumeThrottlingPolicy::TImpl
double WriteCostMultiplier = 1;
ui32 PostponedWeight = 0;

mutable double UsedIoOperationsBudget = 0;
mutable double UsedBandwidthBudget = 0;
double UsedIoOperationsBudget = 0;
double UsedBandwidthBudget = 0;

TImpl(
const NProto::TVolumePerformanceProfile& config,
Expand Down Expand Up @@ -248,23 +248,25 @@ struct TVolumeThrottlingPolicy::TImpl
MaxBandwidth(static_cast<EOpType>(requestInfo.OpType));
const auto maxIops = MaxIops(static_cast<EOpType>(requestInfo.OpType));

const auto recalculatedMaxIops =
CalculateThrottlerC1(maxIops, maxBandwidth);
const auto recalculatedMaxBandwidth =
CalculateThrottlerC2(maxIops, maxBandwidth);
auto d = Bucket.Register(
ts,
m * CostPerIO(
CalculateThrottlerC1(maxIops, maxBandwidth),
CalculateThrottlerC2(maxIops, maxBandwidth),
bandwidthUpdate
)
);
recalculatedMaxIops,
recalculatedMaxBandwidth,
bandwidthUpdate));

if (!d.GetValue()) {
// 0 is special value which disables throttling by byteCount
if (maxBandwidth) {
UsedBandwidthBudget += static_cast<double>(bandwidthUpdate) /
static_cast<double>(maxBandwidth);
UsedBandwidthBudget +=
m * (static_cast<double>(bandwidthUpdate) /
static_cast<double>(recalculatedMaxBandwidth));
}
UsedIoOperationsBudget +=
static_cast<double>(1) / static_cast<double>(maxIops);
UsedIoOperationsBudget += m * (1.0 / recalculatedMaxIops);
return TDuration::Zero();
}

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

double GetUsedIoBudget() const
{
return UsedIoOperationsBudget;
}

double GetUsedBandwidthBudget() const
{
return UsedBandwidthBudget;
}

void FlushSpentIopsBudget() const
double TakeUsedIoBudget()
{
auto res = UsedIoOperationsBudget;
UsedIoOperationsBudget = 0;
return res;
}

void FlushSpentBandwidthBudget() const
double TakeUsedBandwidthBudget()
{
auto res = UsedBandwidthBudget;
UsedBandwidthBudget = 0;
return res;
}
};

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

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

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

void TVolumeThrottlingPolicy::FlushSpentIoBudget() const
double TVolumeThrottlingPolicy::TakeUsedIoBudget()
{
Impl->FlushSpentIopsBudget();
return Impl->TakeUsedIoBudget();
}

void TVolumeThrottlingPolicy::FlushSpentBandwidthBudget() const
double TVolumeThrottlingPolicy::TakeUsedBandwidthBudget()
{
Impl->FlushSpentBandwidthBudget();
return Impl->TakeUsedBandwidthBudget();
}

const TBackpressureReport& TVolumeThrottlingPolicy::GetCurrentBackpressure() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ class TVolumeThrottlingPolicy final
TDuration GetCurrentBoostBudget() const;
ui32 CalculatePostponedWeight() const;
double CalculateCurrentSpentBudgetShare(TInstant ts) const;
[[nodiscard]] double GetUsedIoBudget() const;
[[nodiscard]] double GetUsedBandwidthBudget() const;
void FlushSpentIoBudget() const;
void FlushSpentBandwidthBudget() const;
[[nodiscard]] double TakeUsedIoBudget();
[[nodiscard]] double TakeUsedBandwidthBudget();
const TBackpressureReport& GetCurrentBackpressure() const;
const NProto::TVolumePerformanceProfile& GetConfig() const;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "volume_throttling_policy.h"
#include "cloud/storage/core/libs/throttling/helpers.h"

#include <cloud/blockstore/libs/storage/protos/part.pb.h>

Expand Down Expand Up @@ -674,24 +675,25 @@ Y_UNIT_TEST_SUITE(TVolumeThrottlingPolicyTest)
DO_TEST(tp, 0, 0, byteCount, static_cast<ui32>(EOpType::Read));
}

auto recalculatedMaxIops = CalculateThrottlerC1(maxIops, maxBandwidth);
auto recalculatedMaxBandwidth =
CalculateThrottlerC2(maxIops, maxBandwidth);

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

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

UNIT_ASSERT_DOUBLES_EQUAL(
tp.GetUsedIoBudget(),
static_cast<double>(ioOperation) / static_cast<double>(maxIops),
tp.TakeUsedIoBudget(),
static_cast<double>(ioOperation) /
static_cast<double>(recalculatedMaxIops),
1e-6);

tp.FlushSpentBandwidthBudget();

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

tp.FlushSpentIoBudget();

UNIT_ASSERT_DOUBLES_EQUAL(tp.GetUsedIoBudget(), 0, 1e-6);
UNIT_ASSERT_DOUBLES_EQUAL(tp.TakeUsedIoBudget(), 0, 1e-6);
}

Y_UNIT_TEST(UsedBandwidthBudgetZeroWithoutBytesThrotling)
Expand Down Expand Up @@ -725,12 +727,12 @@ Y_UNIT_TEST_SUITE(TVolumeThrottlingPolicyTest)
}

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

UNIT_ASSERT_DOUBLES_EQUAL(
tp.GetUsedIoBudget(),
tp.TakeUsedIoBudget(),
static_cast<double>(ioOperation) / static_cast<double>(maxIops),
1e-6);
}
Expand Down
8 changes: 3 additions & 5 deletions cloud/blockstore/libs/storage/volume/volume_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,13 @@ void TVolumeActor::UpdateLeakyBucketCounters(const TActorContext& ctx)

auto& simple = VolumeSelfCounters->Simple;
auto& cumulative = VolumeSelfCounters->Cumulative;
const auto& tp = State->GetThrottlingPolicy();
auto& tp = State->AccessThrottlingPolicy();

cumulative.UsedIoBudget.Increment(
static_cast<ui64>(tp.GetUsedIoBudget() * 100.0));
tp.FlushSpentIoBudget();
static_cast<ui64>(tp.TakeUsedIoBudget() * 100.0));

cumulative.UsedBandwidthBudget.Increment(
static_cast<ui64>(tp.GetUsedBandwidthBudget() * 100.0));
tp.FlushSpentBandwidthBudget();
static_cast<ui64>(tp.TakeUsedBandwidthBudget() * 100.0));

ui64 currentRate = tp.CalculateCurrentSpentBudgetShare(ctx.Now()) * 100;
simple.MaxUsedQuota.Set(Max(simple.MaxUsedQuota.Value, currentRate));
Expand Down
6 changes: 4 additions & 2 deletions cloud/blockstore/libs/throttling/throttler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,10 @@ class TThrottler final
{
ui64 quota = 0;
with_lock (ThrottlerLock) {
quota = static_cast<ui64>(ceil(ThrottlerPolicy
->CalculateCurrentSpentBudgetShare(Timer->Now()) * 100.0));
quota = static_cast<ui64>(
ThrottlerPolicy->CalculateCurrentSpentBudgetShare(
Timer->Now()) *
100.0);
}
ThrottlerMetrics->UpdateUsedQuota(quota);
ThrottlerMetrics->UpdateMaxUsedQuota();
Expand Down

0 comments on commit 0bb682e

Please sign in to comment.