diff options
author | Aleksei Borzenkov <snaury@ydb.tech> | 2025-07-03 16:05:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-03 16:05:55 +0300 |
commit | 052d3fca9733e459e7cb696758fbfa114c8fd542 (patch) | |
tree | 35dd3dd95b943a76540ac2c23abd7dcd87241e2f | |
parent | aa4ec23b19827fa806e8e95912453385f453c7e0 (diff) | |
download | ydb-052d3fca9733e459e7cb696758fbfa114c8fd542.tar.gz |
Avoid unnecessary activations before reclaiming free mailboxes (#20582)
-rw-r--r-- | ydb/library/actors/core/executor_thread.cpp | 4 | ||||
-rw-r--r-- | ydb/library/actors/core/mailbox_lockfree.h | 8 |
2 files changed, 9 insertions, 3 deletions
diff --git a/ydb/library/actors/core/executor_thread.cpp b/ydb/library/actors/core/executor_thread.cpp index bef8d3b16fa..42ec51d28d9 100644 --- a/ydb/library/actors/core/executor_thread.cpp +++ b/ydb/library/actors/core/executor_thread.cpp @@ -212,7 +212,6 @@ namespace NActors { ThreadCtx.ResetOverwrittenEventsPerMailbox(); ThreadCtx.ResetOverwrittenTimePerMailboxTs(); - bool drained = false; for (; execCtx.ExecutedEvents < ThreadCtx.OverwrittenEventsPerMailbox(); execCtx.ExecutedEvents++) { if (TAutoPtr<IEventHandle> evExt = mailbox->Pop()) { EXECUTOR_THREAD_DEBUG(EDebugLevel::Event, "mailbox->Pop()"); @@ -387,7 +386,6 @@ namespace NActors { ThreadCtx.WorkerId(), recipient.ToString(), SafeTypeName(actor)); - drained = true; break; // empty queue, leave } } @@ -412,7 +410,7 @@ namespace NActors { NProfiling::TMemoryTagScope::Reset(0); TlsActivationContext = nullptr; - if (mailbox->IsEmpty() && drained) { + if (mailbox->IsEmpty() && mailbox->CanReclaim()) { ThreadCtx.FreeMailbox(mailbox); } else { mailbox->Unlock(ThreadCtx.Pool(), hpnow, RevolvingWriteCounter); diff --git a/ydb/library/actors/core/mailbox_lockfree.h b/ydb/library/actors/core/mailbox_lockfree.h index 4a4614c36a7..9a8ab9041ac 100644 --- a/ydb/library/actors/core/mailbox_lockfree.h +++ b/ydb/library/actors/core/mailbox_lockfree.h @@ -186,6 +186,14 @@ namespace NActors { */ void Unlock(IExecutorPool* pool, NHPTimer::STime now, ui64& revolvingCounter); + /** + * Returns true when a free mailbox can be reclaimed + */ + bool CanReclaim() const { + Y_DEBUG_ABORT_UNLESS(IsFree()); + return !EventHead; + } + private: void EnsureActorMap(); void OnPreProcessed(IEventHandle* head, IEventHandle* tail) noexcept; |