简体   繁体   中英

SQL Server Profiler discrepancy

I am struggling with a strange problem using Sql Profiler. While running some performance testing scripts, I run profiler to find bottlenecks. One particular statement seems to be taking a lot of time - with CPU 1407, Reads 75668 and Duration of 175.

However when I run the same statement in Management Studio, SQL Profiler returns CPU 16, Reads 4 & Duration 55.

Can anyone point me towards what I am doing wrong, as I am completely baffled by this.

Thanks, Susan.

You may have a scalar user defined function that has table access.

The resources used are only picked up by profiler: SSMS won't show the internal IO or CPU of the scalar udf.

Example:

CREATE FUNCTION dbo.MyUdf (
    @param int
)
AS
RETURNS int
BEGIN
    RETURN (SELECT MAX(foo) FROM dbo.MyOtherTable WHERE Key = @param)
END
GO


SELECT
    col1, col2, dbo.MyUdf(col3)
FROM
    dbo.MyFirstTable

However, this may not explain duration...

是Java /休眠问题。

If you run the query in enterprise manager directly after the profiling, all pages it needs will be cached in memory. This can lead to drastic improvements.

If you right-click the server in Enterprise Manager and select Properties, you can change the amount of memory available to the server. If you change this number even one step, SQL server will flush its cache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM