Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix harmonizer when it works with shared threads #9069

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ydb/library/actors/core/executor_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ namespace NActors {
ExecutorPool->ScheduleActivation(capturedActivation);
}
if (!activation) {
return {IsSharedThread, wasWorking};
break;
}
executeActivation(activation, false);
}
Expand Down
11 changes: 6 additions & 5 deletions ydb/library/actors/core/harmonizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ Y_FORCE_INLINE bool IsStarved(double consumed, double booked) {
}

Y_FORCE_INLINE bool IsHoggish(double booked, double currentThreadCount) {
return booked < currentThreadCount - 1;
return booked < currentThreadCount - 0.5;
}

void THarmonizer::HarmonizeImpl(ui64 ts) {
Expand All @@ -435,7 +435,7 @@ void THarmonizer::HarmonizeImpl(ui64 ts) {
i64 beingStopped = 0;
double total = 0;
TStackVec<size_t, 8> needyPools;
TStackVec<size_t, 8> hoggishPools;
TStackVec<std::pair<size_t, double>, 8> hoggishPools;
TStackVec<bool, 8> isNeedyByPool;

size_t sumOfAdditionalThreads = 0;
Expand Down Expand Up @@ -577,7 +577,7 @@ void THarmonizer::HarmonizeImpl(ui64 ts) {
bool isHoggish = IsHoggish(poolBooked, currentThreadCount)
|| IsHoggish(lastSecondPoolBooked, currentThreadCount);
if (isHoggish) {
hoggishPools.push_back(poolIdx);
hoggishPools.push_back({poolIdx, std::max(poolBooked - currentThreadCount, lastSecondPoolBooked - currentThreadCount)});
}
booked += poolBooked;
consumed += poolConsumed;
Expand Down Expand Up @@ -714,18 +714,19 @@ void THarmonizer::HarmonizeImpl(ui64 ts) {
}
}

for (size_t hoggishPoolIdx : hoggishPools) {
for (auto &[hoggishPoolIdx, freeCpu] : hoggishPools) {
TPoolInfo &pool = *Pools[hoggishPoolIdx];
i64 threadCount = pool.GetFullThreadCount();
if (hasBorrowedSharedThread[hoggishPoolIdx]) {
Shared->ReturnBorrowedHalfThread(hoggishPoolIdx);
freeCpu -= 0.5;
continue;
}
if (pool.BasicPool && pool.LocalQueueSize > NFeatures::TLocalQueuesFeatureFlags::MIN_LOCAL_QUEUE_SIZE) {
pool.LocalQueueSize = std::min<ui16>(NFeatures::TLocalQueuesFeatureFlags::MIN_LOCAL_QUEUE_SIZE, pool.LocalQueueSize / 2);
pool.BasicPool->SetLocalQueueSize(pool.LocalQueueSize);
}
if (threadCount > pool.MinFullThreadCount) {
if (threadCount > pool.MinFullThreadCount && freeCpu >= 1) {
AtomicIncrement(pool.DecreasingThreadsByHoggishState);
LWPROBE(HarmonizeOperation, hoggishPoolIdx, pool.Pool->GetName(), "decrease by hoggish", threadCount - 1, pool.DefaultFullThreadCount, pool.MaxFullThreadCount);
pool.SetFullThreadCount(threadCount - 1);
Expand Down
Loading