Skip to content

Commit

Permalink
Optimize AdjustMaxWorkersActive (dotnet#1103)
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 dotnet#1079
  • Loading branch information
billwert authored and jkotas committed Jan 6, 2020
1 parent 6425b2d commit 8cc2aa3
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 8cc2aa3

Please sign in to comment.