Skip to content

Commit

Permalink
Optimize AdjustMaxWorkersActive
Browse files Browse the repository at this point in the history
@ninedan reported this function as expensive in one of the server scenarios
he monitors. The actual time is spent in `ThreadStore::GetAllThreadList`.
Moving the call to `GetTotalWorkerThreadPoolCompletionCount` should reduce this
cost.

Fixes #1079
  • Loading branch information
billwert committed Dec 21, 2019
1 parent bd6c81a commit d7faed4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/coreclr/src/vm/win32threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,10 +919,6 @@ void ThreadpoolMgr::AdjustMaxWorkersActive()

_ASSERTE(ThreadAdjustmentLock.IsHeld());

DWORD currentTicks = GetTickCount();
LONG totalNumCompletions = (LONG)Thread::GetTotalWorkerThreadPoolCompletionCount();
LONG numCompletions = totalNumCompletions - VolatileLoad(&PriorCompletedWorkRequests);

LARGE_INTEGER startTime = CurrentSampleStartTime;
LARGE_INTEGER endTime;
QueryPerformanceCounter(&endTime);
Expand All @@ -941,6 +937,9 @@ void ThreadpoolMgr::AdjustMaxWorkersActive()
//
if (elapsed*1000.0 >= (ThreadAdjustmentInterval/2))
{
DWORD currentTicks = GetTickCount();
LONG totalNumCompletions = (LONG)Thread::GetTotalWorkerThreadPoolCompletionCount();
LONG numCompletions = totalNumCompletions - VolatileLoad(&PriorCompletedWorkRequests);
ThreadCounter::Counts currentCounts = WorkerCounter.GetCleanCounts();

int newMax = HillClimbingInstance.Update(
Expand Down

0 comments on commit d7faed4

Please sign in to comment.