diff options
author | serg-belyakov <serg-belyakov@yandex-team.com> | 2023-03-13 15:53:59 +0300 |
---|---|---|
committer | serg-belyakov <serg-belyakov@yandex-team.com> | 2023-03-13 15:53:59 +0300 |
commit | 75278485ac4e65cab9c41d51b515c86ab979d599 (patch) | |
tree | 04338053fe51eb5ea43cbc9f8a34dcf69b5d5fa4 | |
parent | f538885a6e27311de02f362c8c3107d25d048285 (diff) | |
download | ydb-75278485ac4e65cab9c41d51b515c86ab979d599.tar.gz |
Add different next permission selection strategies for handshake broker,
Add different selection strategies for handhsake broker
-rw-r--r-- | library/cpp/actors/interconnect/handshake_broker.h | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/library/cpp/actors/interconnect/handshake_broker.h b/library/cpp/actors/interconnect/handshake_broker.h index 00d5116a0bd..daea26d579a 100644 --- a/library/cpp/actors/interconnect/handshake_broker.h +++ b/library/cpp/actors/interconnect/handshake_broker.h @@ -38,11 +38,44 @@ namespace NActors { class THandshakeBroker : public TActor<THandshakeBroker> { private: + enum class ESelectionStrategy { + FIFO = 0, + LIFO, + Random, + }; + + private: void PermitNext() { if (Capacity == 0 && !Waiters.empty()) { - const TActorId waiter = Waiters.front(); - Waiters.pop_front(); - WaiterLookup.erase(waiter); + TActorId waiter; + + switch (SelectionStrategy) { + case ESelectionStrategy::FIFO: + waiter = Waiters.front(); + Waiters.pop_front(); + SelectionStrategy = ESelectionStrategy::LIFO; + break; + + case ESelectionStrategy::LIFO: + waiter = Waiters.back(); + Waiters.pop_back(); + SelectionStrategy = ESelectionStrategy::Random; + break; + + case ESelectionStrategy::Random: { + const auto it = WaiterLookup.begin(); + waiter = it->first; + Waiters.erase(it->second); + SelectionStrategy = ESelectionStrategy::FIFO; + break; + } + + default: + Y_FAIL("Unimplimented selection strategy"); + } + + const size_t n = WaiterLookup.erase(waiter); + Y_VERIFY(n == 1); Send(waiter, new TEvHandshakeBrokerPermit()); PermittedLeases.insert(waiter); @@ -57,6 +90,8 @@ namespace NActors { std::unordered_map<TActorId, TWaiters::iterator> WaiterLookup; std::unordered_set<TActorId> PermittedLeases; + ESelectionStrategy SelectionStrategy = ESelectionStrategy::FIFO; + ui32 Capacity; void Handle(TEvHandshakeBrokerTake::TPtr &ev) { |