线程计数

Microsoft.SQLServer.2008.DBEngine.ThreadCountMonitor (UnitMonitor)

针对 2008 数据库引擎的线程计数

Knowledge Base article:

摘要

一般情况下,SQL Server 会为每个查询请求打开一个系统线程;但是,如果线程数量超过了指定的 max worker threads 值,SQL Server 会将工作线程集中到池中。如果所有工作线程随长时间运行的查询而处于活动状态,SQL Server 可能表现为停止响应,直到一个工作线程完成并变成可用。虽然这不是缺点,但有时用户可能并不希望如此。监视器对可用线程量进行分析并且在该数量较低时发出通知。

原因

工作量的增加导致使用的线程增加,这可能指示 SQL Server 正在很高的负荷下工作或者数目过多的查询正在并行运行。

解决方法

调整 max worker threads 是一个高级选项,仅应由有经验的数据库管理员或认证的 SQL Server 技术人员更改。

当服务器上连接有大量客户端时,线程池有助于优化性能。一般情况下,会为每个查询请求创建一个单独的操作系统线程。但是,当到服务器的连接达到数以百计时,为每个查询请求使用一个线程会占用大量的系统资源。max worker threads 选项使 SQL Server 可以为更大数量的查询请求创建一个工作线程池,这将提高性能。

Max worker threads 选项

http://go.microsoft.com/fwlink/?LinkId=789164

可替代参数

名称

说明

默认值

警报优先级

定义警报优先级。

正常

警报严重性

定义警报严重性。

错误

缓存到期时间

指定工作流可使用的缓存中信息的最长存在时间。可以省略。

43200

已启用

启用或禁用工作流。

生成警报

定义工作流是否生成警报。

间隔(秒)

运行工作流的重复间隔时间(秒)。

300

最小可用线程计数

数据源确定每个数据库引擎进程的阈值和线程计数,如果阈值减去当前线程计数后的结果小于或等于可用线程计数,将生成警报

10

样本数

将样本与阈值进行比较前要进行平均的样本数

6

同步时间

使用 24 小时格式指定的同步时间。可以忽略。

00:06

超时(秒)

指定允许工作流在被关闭并标记为失败之前运行的时间。

200

Element properties:

TargetMicrosoft.SQLServer.2008.DBEngine
Parent MonitorSystem.Health.PerformanceState
CategoryPerformanceHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityError
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.SQLServer.2008.DBEngine.ThreadCount.MonitorType
RemotableTrue
AccessibilityPublic
Alert Message
SQL 数据库 2008 引擎线程计数过高
计算机“{1}”上 SQL 实例“{0}”线程计数过高。有关详细信息,请参阅“警报上下文”选项卡。
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.SQLServer.2008.DBEngine.ThreadCountMonitor" Accessibility="Public" Enabled="true" Target="SQL2008Core!Microsoft.SQLServer.2008.DBEngine" ParentMonitorID="SystemHealth!System.Health.PerformanceState" Remotable="true" Priority="Normal" TypeID="Microsoft.SQLServer.2008.DBEngine.ThreadCount.MonitorType" ConfirmDelivery="false">
<Category>PerformanceHealth</Category>
<AlertSettings AlertMessage="Microsoft.SQLServer.2008.DBEngine.ThreadCountMonitor.AlertMessage">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Error</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="SQL!Microsoft.SQLServer.ServerRole"]/InstanceName$</AlertParameter1>
<AlertParameter2>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</AlertParameter2>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Normal" MonitorTypeStateID="Normal" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
</OperationalStates>
<Configuration>
<ServiceName>$Target/Property[Type="SQL!Microsoft.SQLServer.DBEngine"]/ServiceName$</ServiceName>
<IntervalSeconds>300</IntervalSeconds>
<TimeoutSeconds>200</TimeoutSeconds>
<MinFreeThreadsCount>10</MinFreeThreadsCount>
<NumSamples>6</NumSamples>
<SyncTime/>
<CacheExpirationTime>43200</CacheExpirationTime>
</Configuration>
</UnitMonitor>