Is there a SQL server performance counter for average execution time?

我们两清 提交于 2021-02-08 15:46:52

问题


I want to tune a production SQL server. After making adjustments (such as changing the degree of parallelism) I want to know if it helped or hurt query execution times.

This seems like an obvious performance counter, but for the last half hour I've been searching Google and the counter list in perfmon, and I have not been able to find a performance counter for SQL server to give me the average execution time for all queries hitting a server. The SQL Server equivalent of the ASP.NET Request Execution Time.

Does one exist that I'm missing? Is there another effective way of monitoring the average query times for a server?


回答1:


I don't believe there is a PerfMon but there is a report within SQL Server Management Studio:

Right click on the database, select Reports > Standard Reports > Object Execution Statistics. This will give you several very good statistics about what's running within the database, how long it's taking, how much memory/io processing it takes, etc.

You can also run this on the server level across all databases.




回答2:


You can use Query Analyzer (which is one of the tools with SQL Server) and see how they are executed internally so you can optimize indexing etc. That wouldn't tell you about the average, or round-trip back to the client. To do that you'd have to log it on the client and analyze the data yourself.




回答3:


I managed to do it by saving the Trace to SQL. When the trace is open

File > Save As > Trace Table

Select the SQL, and once its imported run

select avg(duration) from dbo.[YourTableImportName] 

You can very easily perform other stats, max, min, counts etc... Much better way of interrogating the trace result




回答4:


Average over what time and for which queries? You need to further define what you mean by "average" or it has no meaning, which is probably why it's not a simple performance counter.

You could capture this information by running a trace, capturing that to a table, and then you could slice and dice the execution times in one of many ways.




回答5:


It doesn't give exactly what you need, but I'd highly recommend trying the SQL Server 2005 Performance Dashboard Reports, which can be downloaded here. It includes a report of the top 20 queries and their average execution time and a lot of other useful ones as well (top queries by IO, wait stats etc). If you do install it be sure to take note of where it installs and follow the instructions in the Additional Info section.




回答6:


The profiler will give you statistics on query execution times and activities on the server. Overall query times may or may not mean very much without tying them to specific jobs and query plans.

Other indicators of performance bottlenecks are resource contention counters (general statistics, latches, locks). You can see these through performance counters. Also looking for large number of table-scan or other operations that do not make use of indexes can give you an indication that indexing may be necessary.

On a loaded server increasing parallelism is unlikely to materially affect performance as there are already many queries active at any given time. Where parallelism gets you a win is on large infrequently run batch jobs such as ETL processes. If you need to reduce the run-time of such a process then parallelism might be a good place to look. On a busy server doing a transactional workload with many users the system resources will be busy from the workload so parallelism is unlikely to be a big win.




回答7:


You can use Activity Monitor. It's built into SSMS. It will give you real-time tracking of all current expensive queries on the server.

To open Activity Monitor:

  1. In Sql Server Management Studio (SSMS), Right click on the server and select Activity Monitor.
  2. Open Recent Expensive Queries to see CPU Usage, Average Query Time, etc.

Hope that helps.




回答8:


There are counters in 'SQL Server:Batch Resp Statistics' group, which are able to track SQL Batch Response times. Counters are divided based on response time intervals, for example, from 0 ms to 1 ms, ..., from 10 ms to 20 ms, ..., from 1000 ms to 2000 ms and so on, So proper counters can be selected for the desired time interval.

Hope it helps.




回答9:


An other solution is to run multiple time the query and get the average query time:

DO $proc$
DECLARE
    StartTime timestamptz;
    EndTime timestamptz;
    Delta double precision;
BEGIN
    StartTime := clock_timestamp();
    FOR i IN 1..100 LOOP
        PERFORM * FROM table_name;
    END LOOP;
    EndTime := clock_timestamp();
    Delta := 1000 * (extract(epoch FROM EndTime) - extract(epoch FROM StartTime)) / 100;
    RAISE NOTICE 'Average duration in ms = %', Delta;
END;
$proc$;

Here it run 100 time the query:

PERFORM * FROM table_name;

Just replace SELECT by PERFORM



来源:https://stackoverflow.com/questions/164154/is-there-a-sql-server-performance-counter-for-average-execution-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!