Skip to content

Commit 9acc750

Browse files
authored
Merge pull request #3509 from BrentOzarULTD/3491_sp_BlitzFirst_max_worker_threads
#3491 sp_BlitzFirst max worker threads
2 parents 21d5ea5 + d529cd5 commit 9acc750

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

Documentation/sp_BlitzFirst_Checks_by_Priority.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Before adding a new check, make sure to add a Github issue for it first, and hav
66

77
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.
88

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

1212
| Priority | FindingsGroup | Finding | URL | CheckID |
1313
|----------|---------------------------------|---------------------------------------|-------------------------------------------------|----------|
@@ -47,6 +47,7 @@ If you want to add a new check, start at 48
4747
| 100 | Query Problems | Skewed Parallelism | https://www.brentozar.com/go/skewedup | 43 |
4848
| 100 | Query Problems | Query with a memory grant exceeding @MemoryGrantThresholdPct | https://www.brentozar.com/memory-grants-sql-servers-public-toilet/ | 46 |
4949
| 200 | Wait Stats | (One per wait type) | https://www.brentozar.com/sql/wait-stats/#(waittype) | 6 |
50+
| 210 | Potential Upcoming Problems | High Number of Connections |https://www.brentozar.com/archive/2014/05/connections-slow-sql-server-threadpool/ | 49 |
5051
| 210 | Query Stats | Plan Cache Analysis Skipped | https://www.brentozar.com/go/topqueries | 18 |
5152
| 210 | Query Stats | Top Resource-Intensive Queries | https://www.brentozar.com/go/topqueries | 17 |
5253
| 250 | Server Info | Batch Requests per Second | https://www.brentozar.com/go/measure | 19 |
@@ -57,3 +58,4 @@ If you want to add a new check, start at 48
5758
| 251 | Server Info | Database Count | | 22 |
5859
| 251 | Server Info | Database Size, Total GB | | 21 |
5960
| 251 | Server Info | Memory Grant/Workspace info | | 40 |
61+
| 254 | Informational | Thread Time Inaccurate | | 48 |

sp_BlitzFirst.sql

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ DECLARE @StringToExecute NVARCHAR(MAX),
143143
@dm_exec_query_statistics_xml BIT = 0,
144144
@total_cpu_usage BIT = 0,
145145
@get_thread_time_ms NVARCHAR(MAX) = N'',
146-
@thread_time_ms FLOAT = 0;
146+
@thread_time_ms FLOAT = 0,
147+
@logical_processors INT = 0,
148+
@max_worker_threads INT = 0;
147149

148150
/* Sanitize our inputs */
149151
SELECT
@@ -308,6 +310,10 @@ BEGIN
308310
@FinishSampleTimeWaitFor = DATEADD(ss, @Seconds, GETDATE());
309311

310312

313+
SELECT @logical_processors = COUNT(*)
314+
FROM sys.dm_os_schedulers
315+
WHERE status = 'VISIBLE ONLINE';
316+
311317
IF EXISTS
312318
(
313319

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

25822588
END
25832589

2590+
/* Potential Upcoming Problems - High Number of Connections - CheckID 49 */
2591+
IF (@Debug = 1)
2592+
BEGIN
2593+
RAISERROR('Running CheckID 49',10,1) WITH NOWAIT;
2594+
END
2595+
IF CAST(SERVERPROPERTY('edition') AS VARCHAR(100)) LIKE '%64%' AND SERVERPROPERTY('EngineEdition') <> 5
2596+
BEGIN
2597+
IF @logical_processors <= 4
2598+
SET @max_worker_threads = 512;
2599+
ELSE IF @logical_processors > 64 AND
2600+
((@v = 13 AND @build >= 5026) OR @v >= 14)
2601+
SET @max_worker_threads = 512 + ((@logical_processors - 4) * 32)
2602+
ELSE
2603+
SET @max_worker_threads = 512 + ((@logical_processors - 4) * 16)
2604+
2605+
IF @max_worker_threads > 0
2606+
BEGIN
2607+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
2608+
SELECT 49 AS CheckID,
2609+
210 AS Priority,
2610+
'Potential Upcoming Problems' AS FindingGroup,
2611+
'High Number of Connections' AS Finding,
2612+
'https://www.brentozar.com/archive/2014/05/connections-slow-sql-server-threadpool/' AS URL,
2613+
'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
2614+
FROM sys.dm_exec_connections c
2615+
HAVING SUM(1) > @max_worker_threads;
2616+
END
2617+
END
2618+
25842619
RAISERROR('Finished running investigatory queries',10,1) WITH NOWAIT;
25852620

25862621

0 commit comments

Comments
 (0)