Skip to content

Commit

Permalink
Merge pull request #3509 from BrentOzarULTD/3491_sp_BlitzFirst_max_wo…
Browse files Browse the repository at this point in the history
…rker_threads

#3491 sp_BlitzFirst max worker threads
  • Loading branch information
BrentOzar authored May 1, 2024
2 parents 21d5ea5 + d529cd5 commit 9acc750
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Documentation/sp_BlitzFirst_Checks_by_Priority.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Before adding a new check, make sure to add a Github issue for it first, and hav

If you want to change anything about a check - the priority, finding, URL, or ID - open a Github issue first. The relevant scripts have to be updated too.

CURRENT HIGH CHECKID: 47
If you want to add a new check, start at 48
CURRENT HIGH CHECKID: 49
If you want to add a new check, start at 50.

| Priority | FindingsGroup | Finding | URL | CheckID |
|----------|---------------------------------|---------------------------------------|-------------------------------------------------|----------|
Expand Down Expand Up @@ -47,6 +47,7 @@ If you want to add a new check, start at 48
| 100 | Query Problems | Skewed Parallelism | https://www.brentozar.com/go/skewedup | 43 |
| 100 | Query Problems | Query with a memory grant exceeding @MemoryGrantThresholdPct | https://www.brentozar.com/memory-grants-sql-servers-public-toilet/ | 46 |
| 200 | Wait Stats | (One per wait type) | https://www.brentozar.com/sql/wait-stats/#(waittype) | 6 |
| 210 | Potential Upcoming Problems | High Number of Connections |https://www.brentozar.com/archive/2014/05/connections-slow-sql-server-threadpool/ | 49 |
| 210 | Query Stats | Plan Cache Analysis Skipped | https://www.brentozar.com/go/topqueries | 18 |
| 210 | Query Stats | Top Resource-Intensive Queries | https://www.brentozar.com/go/topqueries | 17 |
| 250 | Server Info | Batch Requests per Second | https://www.brentozar.com/go/measure | 19 |
Expand All @@ -57,3 +58,4 @@ If you want to add a new check, start at 48
| 251 | Server Info | Database Count | | 22 |
| 251 | Server Info | Database Size, Total GB | | 21 |
| 251 | Server Info | Memory Grant/Workspace info | | 40 |
| 254 | Informational | Thread Time Inaccurate | | 48 |
37 changes: 36 additions & 1 deletion sp_BlitzFirst.sql
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ DECLARE @StringToExecute NVARCHAR(MAX),
@dm_exec_query_statistics_xml BIT = 0,
@total_cpu_usage BIT = 0,
@get_thread_time_ms NVARCHAR(MAX) = N'',
@thread_time_ms FLOAT = 0;
@thread_time_ms FLOAT = 0,
@logical_processors INT = 0,
@max_worker_threads INT = 0;

/* Sanitize our inputs */
SELECT
Expand Down Expand Up @@ -308,6 +310,10 @@ BEGIN
@FinishSampleTimeWaitFor = DATEADD(ss, @Seconds, GETDATE());


SELECT @logical_processors = COUNT(*)
FROM sys.dm_os_schedulers
WHERE status = 'VISIBLE ONLINE';

IF EXISTS
(

Expand Down Expand Up @@ -2581,6 +2587,35 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,

END

/* Potential Upcoming Problems - High Number of Connections - CheckID 49 */
IF (@Debug = 1)
BEGIN
RAISERROR('Running CheckID 49',10,1) WITH NOWAIT;
END
IF CAST(SERVERPROPERTY('edition') AS VARCHAR(100)) LIKE '%64%' AND SERVERPROPERTY('EngineEdition') <> 5
BEGIN
IF @logical_processors <= 4
SET @max_worker_threads = 512;
ELSE IF @logical_processors > 64 AND
((@v = 13 AND @build >= 5026) OR @v >= 14)
SET @max_worker_threads = 512 + ((@logical_processors - 4) * 32)
ELSE
SET @max_worker_threads = 512 + ((@logical_processors - 4) * 16)

IF @max_worker_threads > 0
BEGIN
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
SELECT 49 AS CheckID,
210 AS Priority,
'Potential Upcoming Problems' AS FindingGroup,
'High Number of Connections' AS Finding,
'https://www.brentozar.com/archive/2014/05/connections-slow-sql-server-threadpool/' AS URL,
'There are ' + CAST(SUM(1) AS VARCHAR(20)) + ' open connections, which would lead to ' + @LineFeed + 'worker thread exhaustion and THREADPOOL waits' + @LineFeed + 'if they all ran queries at the same time.' AS Details
FROM sys.dm_exec_connections c
HAVING SUM(1) > @max_worker_threads;
END
END

RAISERROR('Finished running investigatory queries',10,1) WITH NOWAIT;


Expand Down

0 comments on commit 9acc750

Please sign in to comment.