forked from ydb-platform/ydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disk usage limit for CS compaction (in general slider limit) (ydb-pla…
…tform#4864) Conflicts: ydb/core/base/events.h ydb/core/driver_lib/run/service_mask.h ydb/core/protos/config.proto
- Loading branch information
1 parent
0a7bc1e
commit 19e4fbb
Showing
24 changed files
with
448 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "service.h" | ||
|
||
namespace NKikimr::NLimiter { | ||
|
||
TLimiterActor::TLimiterActor(const TConfig& config, const TString& limiterName, TIntrusivePtr<::NMonitoring::TDynamicCounters> baseCounters) | ||
: LimiterName(limiterName) | ||
, Config(config) | ||
, Counters(LimiterName, baseCounters) | ||
{ | ||
Counters.InProgressLimit->Set(Config.GetLimit()); | ||
} | ||
|
||
void TLimiterActor::HandleMain(TEvExternal::TEvAskResource::TPtr& ev) { | ||
const auto now = TMonotonic::Now(); | ||
if (RequestsInFlight.empty() || VolumeInFlight + ev->Get()->GetRequest()->GetVolume() <= Config.GetLimit()) { | ||
VolumeInFlight += ev->Get()->GetRequest()->GetVolume(); | ||
RequestsInFlight.emplace_back(now, ev->Get()->GetRequest()->GetVolume()); | ||
if (RequestsInFlight.size() == 1) { | ||
Schedule(now + Config.GetPeriod(), new NActors::TEvents::TEvWakeup()); | ||
} | ||
ev->Get()->GetRequest()->OnResourceAllocated(); | ||
Counters.InProgressStart->Inc(); | ||
} else { | ||
RequestsQueue.emplace_back(now, ev->Get()->GetRequest()); | ||
VolumeInWaiting += ev->Get()->GetRequest()->GetVolume(); | ||
} | ||
Counters.InProgressCount->Set(RequestsInFlight.size()); | ||
Counters.InProgressVolume->Set(VolumeInFlight); | ||
Counters.WaitingQueueCount->Set(RequestsQueue.size()); | ||
Counters.WaitingQueueVolume->Set(VolumeInWaiting); | ||
} | ||
|
||
void TLimiterActor::HandleMain(NActors::TEvents::TEvWakeup::TPtr& /*ev*/) { | ||
const auto now = TMonotonic::Now(); | ||
AFL_VERIFY(RequestsInFlight.size()); | ||
while (RequestsInFlight.size() && RequestsInFlight.front().GetInstant() + Config.GetPeriod() <= now) { | ||
AFL_VERIFY(RequestsInFlight.front().GetVolume() <= VolumeInFlight); | ||
VolumeInFlight = VolumeInFlight - RequestsInFlight.front().GetVolume(); | ||
RequestsInFlight.pop_front(); | ||
} | ||
if (RequestsInFlight.empty()) { | ||
AFL_VERIFY(!VolumeInFlight); | ||
} | ||
while (RequestsQueue.size() && (RequestsInFlight.empty() || VolumeInFlight + RequestsQueue.front().GetRequest()->GetVolume() <= Config.GetLimit())) { | ||
Counters.WaitingHistogram->Collect((i64)(now - RequestsQueue.front().GetInstant()).MilliSeconds(), 1); | ||
VolumeInFlight += RequestsQueue.front().GetRequest()->GetVolume(); | ||
RequestsInFlight.emplace_back(now, RequestsQueue.front().GetRequest()->GetVolume()); | ||
RequestsQueue.front().GetRequest()->OnResourceAllocated(); | ||
AFL_VERIFY(VolumeInWaiting >= RequestsQueue.front().GetRequest()->GetVolume()); | ||
VolumeInWaiting -= RequestsQueue.front().GetRequest()->GetVolume(); | ||
RequestsQueue.pop_front(); | ||
Counters.InProgressStart->Inc(); | ||
} | ||
if (RequestsInFlight.size()) { | ||
Schedule(RequestsInFlight.front().GetInstant() + Config.GetPeriod(), new NActors::TEvents::TEvWakeup()); | ||
} | ||
Counters.InProgressCount->Set(RequestsInFlight.size()); | ||
Counters.InProgressVolume->Set(VolumeInFlight); | ||
Counters.WaitingQueueCount->Set(RequestsQueue.size()); | ||
Counters.WaitingQueueVolume->Set(VolumeInWaiting); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#pragma once | ||
#include <ydb/core/tx/columnshard/counters/common/owner.h> | ||
#include <ydb/core/tx/limiter/usage/abstract.h> | ||
#include <ydb/core/tx/limiter/usage/config.h> | ||
#include <ydb/core/tx/limiter/usage/events.h> | ||
|
||
#include <ydb/library/actors/core/actor_bootstrapped.h> | ||
#include <ydb/library/actors/core/log.h> | ||
#include <ydb/library/accessor/accessor.h> | ||
|
||
#include <library/cpp/monlib/dynamic_counters/counters.h> | ||
|
||
#include <queue> | ||
|
||
namespace NKikimr::NLimiter { | ||
|
||
class TCounters: public NColumnShard::TCommonCountersOwner { | ||
private: | ||
using TBase = NColumnShard::TCommonCountersOwner; | ||
public: | ||
const ::NMonitoring::TDynamicCounters::TCounterPtr WaitingQueueCount; | ||
const ::NMonitoring::TDynamicCounters::TCounterPtr WaitingQueueVolume; | ||
const ::NMonitoring::TDynamicCounters::TCounterPtr InProgressLimit; | ||
|
||
const ::NMonitoring::TDynamicCounters::TCounterPtr InProgressCount; | ||
const ::NMonitoring::TDynamicCounters::TCounterPtr InProgressVolume; | ||
|
||
const ::NMonitoring::TDynamicCounters::TCounterPtr InProgressStart; | ||
|
||
const ::NMonitoring::THistogramPtr WaitingHistogram; | ||
|
||
TCounters(const TString& limiterName, TIntrusivePtr<::NMonitoring::TDynamicCounters> baseSignals) | ||
: TBase("Limiter/" + limiterName, baseSignals) | ||
, WaitingQueueCount(TBase::GetValue("WaitingQueue/Count")) | ||
, WaitingQueueVolume(TBase::GetValue("WaitingQueue/Volume")) | ||
, InProgressLimit(TBase::GetValue("InProgress/Limit/Volume")) | ||
, InProgressCount(TBase::GetValue("InProgress/Count")) | ||
, InProgressVolume(TBase::GetValue("InProgress/Volume")) | ||
, InProgressStart(TBase::GetDeriviative("InProgress")) | ||
, WaitingHistogram(TBase::GetHistogram("Waiting", NMonitoring::ExponentialHistogram(20, 2))) { | ||
} | ||
}; | ||
|
||
class TLimiterActor: public NActors::TActorBootstrapped<TLimiterActor> { | ||
private: | ||
const TString LimiterName; | ||
const TConfig Config; | ||
TCounters Counters; | ||
class TResourceRequest { | ||
private: | ||
YDB_READONLY(TMonotonic, Instant, TMonotonic::Zero()); | ||
YDB_READONLY_DEF(std::shared_ptr<IResourceRequest>, Request); | ||
public: | ||
TResourceRequest(const TMonotonic instant, const std::shared_ptr<IResourceRequest>& req) | ||
: Instant(instant) | ||
, Request(req) { | ||
|
||
} | ||
}; | ||
|
||
class TResourceRequestInFlight { | ||
private: | ||
YDB_READONLY(TMonotonic, Instant, TMonotonic::Zero()); | ||
YDB_READONLY(ui64, Volume, 0); | ||
public: | ||
TResourceRequestInFlight(const TMonotonic instant, const ui64 volume) | ||
: Instant(instant) | ||
, Volume(volume) { | ||
|
||
} | ||
}; | ||
|
||
ui64 VolumeInFlight = 0; | ||
ui64 VolumeInWaiting = 0; | ||
std::deque<TResourceRequest> RequestsQueue; | ||
std::deque<TResourceRequestInFlight> RequestsInFlight; | ||
|
||
void HandleMain(TEvExternal::TEvAskResource::TPtr& ev); | ||
void HandleMain(NActors::TEvents::TEvWakeup::TPtr& ev); | ||
|
||
public: | ||
|
||
STATEFN(StateMain) { | ||
switch (ev->GetTypeRewrite()) { | ||
hFunc(TEvExternal::TEvAskResource, HandleMain); | ||
hFunc(NActors::TEvents::TEvWakeup, HandleMain); | ||
default: | ||
AFL_ERROR(NKikimrServices::TX_LIMITER)("limiter", LimiterName)("problem", "unexpected event")("type", ev->GetTypeRewrite()); | ||
AFL_VERIFY_DEBUG(false)("type", ev->GetTypeRewrite()); | ||
break; | ||
} | ||
} | ||
|
||
TLimiterActor(const TConfig& config, const TString& limiterName, TIntrusivePtr<::NMonitoring::TDynamicCounters> baseCounters); | ||
|
||
void Bootstrap() { | ||
Become(&TLimiterActor::StateMain); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LIBRARY() | ||
|
||
SRCS( | ||
service.cpp | ||
) | ||
|
||
PEERDIR( | ||
ydb/core/tx/limiter/usage | ||
ydb/core/protos | ||
) | ||
|
||
END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "abstract.h" | ||
|
||
namespace NKikimr::NLimiter { | ||
|
||
} |
Oops, something went wrong.