监控游标,有哪些好的查询/脚本可以做到这一点?

发布于 2024-08-15 01:53:22 字数 326 浏览 3 评论 0原文

我需要向管理层提供证据,证明一组使用游标的现有存储过程是造成我们大部分性能问题的原因。有人可以指出我正确的方向来查找脚本和查询来完成此任务吗?比如,如何监控和测量游标等。使用SQL Server 2005。

谢谢。

========更新============

管理层需要弹药来带回第3方供应商,告诉他们以很少或没有成本的方式改变他们的程序。由于这些是影响我们会计系统的第三方进程,我没有任何方法可以先重写它们。

除了痕迹(已经在做)之外,我还能做其他事情吗?我发现使用 sys.dm_exec_cursors(0) 可以让我获得现有游标的快速列表。还有其他类似的事情吗?

I need to provide management with proof that a group of existing stored procedures that use cursors are the cause of much of our performance issues. Can someone point me in the right direction to find scripts and queries to accomplish this, please? Such as, how to monitor and measure cursors, etc. Using SQL Server 2005.

Thanks.

========UPDATE============

Management needs ammunition to take back to 3rd party vendor to tell them to change their procs at little or no cost to us. Since these are 3rd party procs hitting our accounting system, I don't have any way of rewriting them first.

Besides traces (already doing), are there any other things I can do? I've found that using sys.dm_exec_cursors(0) lets me get a quick list of exisitng cursors. Are there any other things like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天涯沦落人 2024-08-22 01:53:22

因此,您进行了严格的测量并收集了执行时间和统计数据,表明问题程序是使用光标的程序,对吧?那么收集到的信息就是证明你的情况的绝佳论据。如果你没有...那么你怎么知道是光标?

首先查看 sys.dm_exec_query_stats 并收集按工作时间 (CPU)、运行时间(持续时间)和 I/O 划分的最昂贵的查询。这些应该足以指出罪魁祸首并查明问题是否确实是由光标引起的。

如果游标确实是一个问题,也有专门的 DMV,sys.dm_exec_cursors

例如,最昂贵的CPU频繁执行的语句:

select top(10) substring(Text,
  statement_start_offset/2, 
  (statement_end_offset-statement_start_offset)/2) as Statement
  , *
from sys.dm_exec_query_stats q
cross apply sys.dm_exec_sql_text(sql_handle)
where execution_count > 100
order by total_worker_time/execution_count desc

So you did hard measurements and collected execution times and statistics showing that the problem procedures are the ones using the cursors, right? Then the collected information is an excellent argument to prove your case. If you did not... then how do you know is the cursors?

Start by looking at sys.dm_exec_query_stats and collect the most expensive queries by worker time (CPU), elapsed time (duration) and by I/O. These should be enough to point to the culprit and find out if indeed, the problem is because of the cursors or not.

If the cursors turn out to be indeed an issue, there are dedicated DMVs for them too, sys.dm_exec_cursors

For example, the top most expensive CPU frequently executed statements:

select top(10) substring(Text,
  statement_start_offset/2, 
  (statement_end_offset-statement_start_offset)/2) as Statement
  , *
from sys.dm_exec_query_stats q
cross apply sys.dm_exec_sql_text(sql_handle)
where execution_count > 100
order by total_worker_time/execution_count desc
梦冥 2024-08-22 01:53:22

最好的事情(时间允许)是将一些过程重写为基于集合的语句,然后将两者与等待分析进行比较(http://technet.microsoft.com/en-us/library/cc966413.aspx 有一篇关于如何执行此类操作的很好的论文)。如果没有前后对比,你的对手可能只会说“基于集合不会更好:-)”

The best thing (time permitting) would be to rewrite some of the procs as set-based statements and then compare the two with waits analysis (http://technet.microsoft.com/en-us/library/cc966413.aspx has a good paper about how to do this type of thing). Without a before-and-after, your adversaries might just say "set-based won't be any better :-)"

痴情换悲伤 2024-08-22 01:53:22

您可以运行 SQL Profiler 并捕获有问题的存储过程的跟踪(这将为您提供重要的测量值,例如读取数、CPU、持续时间)。

一个好主意是以其中一个为例,它很容易重写为基于集合的方法,运行它并捕获分析器跟踪。通过这种方式,您可以显示现实世界中的性能差异。

如果可能的话(即不在生产环境中),您应该在运行存储过程的每个版本之前清除执行计划和数据缓存,以进行公平的比较。

此外,您还可以获得游标版本和基于集合的版本的执行计划。

归根结底,底线统计数据不言而喻,因此对“之前”和“之后”进行比较将是有益的。

You can run SQL Profiler and capture a trace with the offending sprocs (this will give you important measures like Reads, CPU, Duration).

A good idea would be to e.g. take one of them as an example that's quite easy to rewrite as a set-based approach, run it and capture the profiler trace for that. This way, you can show realworld differences in performance.

If possible, (i.e. not on production), you should clear down the execution plan and data cache before running each version of the sproc to allow a fair comparison.

Also, you could get the execution plans for the cursor version, and the set-based version.

At the end of the day, bottom-line stats speak for themselves so having a comparison "before" and "after" will be beneficial.

迟到的我 2024-08-22 01:53:22

性能监视器(perfmon.exe)是实时分析SQL Server性能的优秀工具。

Performance monitor (perfmon.exe) is an excellent tool for real time analysis of SQL Server performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文