情况是存在某些存储过程和/或特殊SQL导致我们的CPU从30%上升到80%并且将所有索引从内存中删除,我想知道是否已经建立了良好的将性能峰值(CPU,磁盘读取等)与运行SP的特定实例相关联的方法。
答案 0 :(得分:3)
我可以想到两种间接方式
注意CPU,读取,通过存储过程调用的探查器写入 我们最近使用它来发现昂贵的IO / CPU与持续时间相比
使用DMV在我们的系统上找到最贵的,这也显示存储过程
示例:
SELECT TOP 10
QS.total_logical_reads,
QS.total_logical_writes,
QS.execution_count,
QS.total_logical_reads + QS.total_logical_writes AS [IO_total],
QS.total_logical_reads / QS.execution_count AS Avg_Reads_per_Execution,
ST.[text] AS query_text,
db_name(ST.dbid) AS database_name,
ST.objectid AS OBJECT_ID
FROM
sys.dm_exec_query_stats QS
CROSS APPLY
sys.dm_exec_sql_text(sql_handle) ST
WHERE
QS.total_logical_reads + QS.total_logical_writes > 0
--AND ST.dbid IS NULL
ORDER BY
[IO_total] DESC;
答案 1 :(得分:2)
性能监视器。如果是Sql Server 2008 - > 启动,程序文件,Microsoft Sql Server 2008,性能工具,Sql Server Profiler 。 生成跟踪。跟踪包含各种信息。例如,通过一些工作,可以找到存储过程的开始和结束跟踪事件,请注意它运行的时间覆盖了峰值,然后通过查看跟踪收集的资源计数器进一步验证。在sql server性能上尝试此链接:http://www.sql-server-performance.com/articles/per/correlate_trace_performance_p1.aspx
在SQL Server代理中使用警报来触发自定义T-SQL,该T-SQL捕获正在运行@特定时间的内容。 Sql Server代理,警报,常规,新警报,Type = SQL Server性能状况警报(根据需要设置),响应,执行作业。该作业有一个sql脚本写入表 - 告诉你发生了什么。各种各样的世界可能是你的牡蛎。例如,你可以问自己 - 嘿,现在记忆中的clr是什么?
现在记忆力是什么?
SELECT
a.*
,cla.*
,clr_ad.*
,state_desc = CASE clr_ad.[state]
WHEN N'E_APPDOMAIN_CREATING' THEN 'The AppDomain is being created.'
WHEN N'E_APPDOMAIN_SHARED' THEN 'The runtime AppDomain is ready for use by multiple users.'
WHEN N'E_APPDOMAIN_SINGLEUSER' THEN 'The AppDomain is ready for use in DDL operations. These differ from E_APPDOMAIN_SHARED in that shared AppDomains are used for CLR integration executions as opposed to DDL operations. Such AppDomains are isolated from other concurrent operations.'
WHEN N'E_APPDOMAIN_DOOMED' THEN 'The AppDomain is scheduled to be unloaded, but there are currently threads executing in it.'
WHEN N'E_APPDOMAIN_UNLOADING' THEN 'SQL Server has requested that the CLR unload the AppDomain, usually because the assembly that contains the managed database objects has been altered or dropped.'
WHEN N'E_APPDOMAIN_UNLOADED' THEN 'The CLR has unloaded the AppDomain. This is usually the result of an escalation procedure due to ThreadAbort, OutOfMemory, or an unhandled exception in user code.'
WHEN N'E_APPDOMAIN_ENQUEUE_DESTROY' THEN 'The AppDomain has been unloaded in CLR and set to be destroyed by SQL Server.'
WHEN N'E_APPDOMAIN_DESTROY' THEN 'The AppDomain is in the process of being destroyed by SQL Server.'
WHEN N'E_APPDOMAIN_ZOMBIE' THEN 'The AppDomain has been destroyed by SQL Server; however, not all of the references to the AppDomain have been cleaned up.'
ELSE '?'
END
FROM
sys.dm_clr_loaded_assemblies cla
JOIN sys.assemblies a
ON cla.assembly_id = a.assembly_id
JOIN sys.dm_clr_appdomains clr_ad
ON cla.appdomain_address = clr_ad.appdomain_address