Upload
chase
View
29
Download
0
Embed Size (px)
DESCRIPTION
Platinum. Learn & Enjoy [Put your phone on Vibrate!]. www.sqlbits.com. Group BY: [Food and Drink at Reading Bowl, see you there!]. Gold. Feedback Forms: [Voucher for £30 book on return of Form]. Silver. Lunch Time Sessions: [Idera in Everest, Quest in Memphis, Grok in Chic 1 and 2]. - PowerPoint PPT Presentation
Citation preview
www.sqlbits.com
Group BY: [Food and Drink at Reading Bowl, see you there!]
Feedback Forms: [Voucher for £30 book on return of Form]
Lunch Time Sessions: [Idera in Everest, Quest in Memphis, Grok in Chic 1 and 2]
Learn & Enjoy [Put your phone on Vibrate!]
Ask The Experts[Sessions need to finish on time, take questions to the ATE area]
Identifying Performance Identifying Performance Problems with SQL ProfilerProblems with SQL Profiler
Martin Bell SQL Server MVPMartin Bell SQL Server MVP
IntroductionIntroduction
SQL Profiler is the most important tool for SQL Profiler is the most important tool for diagnosing poorly performing SQL in a diagnosing poorly performing SQL in a systemsystem
SQL 2005 has improved SQL Profiler to SQL 2005 has improved SQL Profiler to make it even more usefulmake it even more useful
Combined with other tools you can build a Combined with other tools you can build a complete performance monitoring toolkitcomplete performance monitoring toolkit
Perfmon CountersPerfmon Counters
New counters covers areas including CLR New counters covers areas including CLR information, Service Broker, Notification information, Service Broker, Notification ServicesServices
sys.dm_os_performance_counterssys.dm_os_performance_counters and and sys.sysperfinfosys.sysperfinfo
Import perfmon data into SQL ProfilerImport perfmon data into SQL Profiler
Server DashboardServer Dashboard
Perfmon reports release with SP1Perfmon reports release with SP1 Performance at a glance, based on dynamic Performance at a glance, based on dynamic
viewsviews– sys.dm_os_performance_counterssys.dm_os_performance_counters– sys.dm_exec_query_statssys.dm_exec_query_stats
Performance Dashboard Custom Performance Dashboard Custom ReportsReports
Download from Download from http://www.microsoft.com/downloads/details.aspx?FamilyId=1D3A4A0D-7E0C-4730-8204-E419218C1EFC&displaylang=en
Requires SP2Requires SP2 Common performance problems that the Common performance problems that the
dashboard reports may help to resolve dashboard reports may help to resolve include:include:- CPU bottlenecks (and what queries are consuming the most CPU)- CPU bottlenecks (and what queries are consuming the most CPU)- IO bottlenecks (and what queries are performing the most IO).- IO bottlenecks (and what queries are performing the most IO).- Index recommendations generated by the query optimizer (missing - Index recommendations generated by the query optimizer (missing indexes)indexes)- Blocking- Blocking- Latch contention- Latch contention
SQL ProfilerSQL Profiler
Improved interface for creating a profileImproved interface for creating a profile Added filtering capabilityAdded filtering capability Deadlock GraphsDeadlock Graphs Showplan XMLShowplan XML Re-configure trace without loosing dataRe-configure trace without loosing data Include Perfmon DataInclude Perfmon Data
Deadlock GraphsDeadlock Graphs
Better detection of deadlocksBetter detection of deadlocks No need for blocker scripts or other methodsNo need for blocker scripts or other methods Easily identify blocking problemsEasily identify blocking problems
-- Script 1USE PUBS GO
SELECT @@SPID AS [Windows 1 SPID] GO
BEGIN TRANSACTION
SELECT * FROM AUTHORS WITH (UPDLOCK) -- Results Returned immediately
WAITFOR DELAY '000:00:03'
SELECT * FROM TITLES WITH (UPDLOCK) -- Results Returned immediately
ROLLBACK TRANSACTIONGO
-- Script 2USE PUBS GO
SELECT @@SPID AS [Windows 2 SPID] GO
BEGIN TRANSACTION
SELECT * FROM TITLES WITH (UPDLOCK) -- Results Returned immediately
WAITFOR DELAY '000:00:03'
SELECT * FROM AUTHORS WITH (UPDLOCK) -- Results Not Returned Immediately
ROLLBACK TRANSACTION GO
Msg 1205, Level 13, State 51, Line 8
Transaction (Process ID 57) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
Define Profiler TemplatesDefine Profiler Templates
Save your own templates if you frequently Save your own templates if you frequently require to profile certain events/columnsrequire to profile certain events/columns
Changing Events without loosing Changing Events without loosing DataData
Unlike SQL 2000 you can pause the SQL Unlike SQL 2000 you can pause the SQL profile, change what is being logged and profile, change what is being logged and then resume the profile without loosing the then resume the profile without loosing the previous dataprevious data
XML ShowplanXML Showplan
This will help to diagnose query problems, This will help to diagnose query problems, less need to cut/paste into Management less need to cut/paste into Management StudioStudio
Maintain old query plans and able to Maintain old query plans and able to compare current plans to older onescompare current plans to older ones
Importing Perfmon DataImporting Perfmon Data
If you have collected perfmon counters while If you have collected perfmon counters while a trace is running they can be imported into a trace is running they can be imported into the SQL profilerthe SQL profiler
Better collect statement level informationBetter collect statement level information– sp:StatementStartsp:StatementStart– sp:StatementCompletesp:StatementComplete
Do not trace a high number of events for a Do not trace a high number of events for a long period or you may fill up the file system!long period or you may fill up the file system!
GotchasGotchas
Using SQL Profiler on database server can Using SQL Profiler on database server can take resourcestake resources
Uses temp directory to storage – make sure Uses temp directory to storage – make sure this is not on the system disc!this is not on the system disc!
Server Side TracesServer Side Traces
Script from SQL ProfilerScript from SQL Profiler Schedule from SQL AgentSchedule from SQL Agent Specify a durationSpecify a duration Automate the collection and analysisAutomate the collection and analysis Output to a file on different spindles!Output to a file on different spindles!
Running tracesRunning traces
Use fn_trace_setstatus for the given trace id Use fn_trace_setstatus for the given trace id to change the statusto change the status– 0 0 stops the tracestops the trace– 11 starts the tracestarts the trace– 22 closes the tracecloses the trace
Show running tracesShow running traces
Use fn_trace_getinfo to return information on the Use fn_trace_getinfo to return information on the traces loaded and running. Property column:traces loaded and running. Property column:– 11 Trace options.Trace options.
2 – Trace file rolls over2 – Trace file rolls over 4 – Shutdown trace on error4 – Shutdown trace on error 8 – Produce a Blackbox trace8 – Produce a Blackbox trace
– 22 File nameFile name– 33 Max size Max size – 44 Stop time Stop time – 55 Current trace statusCurrent trace status
If you wish to load your own traces into SQL Profiler has the option to save a loaded trace file as a trace table, or you can use the function fn_trace_gettable e.g.
SELECT IDENTITY(bigint, 1, 1) AS RowNumber, * INTO dbo.trc_20061206_1FROM ::fn_trace_gettable('c:\trc_20061206_1.trc', default)
Loading your own tracesLoading your own traces
Analysing the resultsAnalysing the results
Read80Trace (SQL Server 2000)Read80Trace (SQL Server 2000) Manual Loading and AnalysisManual Loading and Analysis ClearTrace utilityClearTrace utility
Manual AnalysisManual Analysis
SELECT LEFT(CAST(TextData AS VARCHAR(8000)),25) AS SELECT LEFT(CAST(TextData AS VARCHAR(8000)),25) AS [Procedure],[Procedure],COUNT(*) AS [Number of Calls],COUNT(*) AS [Number of Calls],SUM([Duration]) AS [Total Duration],SUM([Duration]) AS [Total Duration],AVG([Duration]) AS [Average Duration],AVG([Duration]) AS [Average Duration],SUM([Reads]) AS [Total Reads],SUM([Reads]) AS [Total Reads],AVG([Reads]) AS [Average Reads],AVG([Reads]) AS [Average Reads],SUM([Writes]) AS [Total Write],SUM([Writes]) AS [Total Write],AVG([Writes]) AS [Average Write],AVG([Writes]) AS [Average Write],SUM([CPU]) AS [Total CPU],SUM([CPU]) AS [Total CPU],AVG([CPU]) AS [Average CPU]AVG([CPU]) AS [Average CPU]
FROM dbo.trc_200612031629FROM dbo.trc_200612031629GROUP BY LEFT(CAST(TextData AS VARCHAR(8000)),25)GROUP BY LEFT(CAST(TextData AS VARCHAR(8000)),25)ORDER BY SUM([Duration]) DESCORDER BY SUM([Duration]) DESC
Procedure AnalysisProcedure AnalysisCREATE VIEW CREATE VIEW dbo.dbo.vw_vw_trc_200612031629trc_200612031629ASASSELECT SELECT LEFT(SUBSTRING(CAST(textdata as VARCHAR(8000)),LEFT(SUBSTRING(CAST(textdata as VARCHAR(8000)),
CHARINDEX('CHARINDEX('uspusp', CAST(textdata as VARCHAR(8000)) ),', CAST(textdata as VARCHAR(8000)) ),CASE WHEN CHARINDEX(' ',CAST(textdata as VARCHAR(8000)), CASE WHEN CHARINDEX(' ',CAST(textdata as VARCHAR(8000)), CHARINDEX(‘CHARINDEX(‘uspusp', CAST(textdata as VARCHAR(8000)) ) ) > 0 THEN', CAST(textdata as VARCHAR(8000)) ) ) > 0 THEN
CHARINDEX(' ',CAST(textdata as VARCHAR(8000)), CHARINDEX(' ',CAST(textdata as VARCHAR(8000)), CHARINDEX(CHARINDEX(‘usp‘usp', CAST(textdata as VARCHAR(8000)) ) )', CAST(textdata as VARCHAR(8000)) ) )- CHARINDEX(- CHARINDEX(‘usp‘usp', CAST(textdata as VARCHAR(8000)) ) ', CAST(textdata as VARCHAR(8000)) )
ELSE LEN(CAST(textdata as VARCHAR(8000))) ENDELSE LEN(CAST(textdata as VARCHAR(8000))) END),60)),60) as [Procedure], as [Procedure],
[Duration],[Duration],[Reads],[Reads],[Writes],[Writes],[CPU][CPU]
FROM FROM dbo.trc_200612031629dbo.trc_200612031629WHERE WHERE CHARINDEX(CHARINDEX(‘usp‘usp', CAST(textdata as VARCHAR(8000)', CAST(textdata as VARCHAR(8000)))) ) > 0 > 0
Procedure AnalysisProcedure Analysis
SELECT [Procedure],SELECT [Procedure],COUNT(*) AS [Number of Calls],COUNT(*) AS [Number of Calls],SUM([Duration]) AS [Total Duration],SUM([Duration]) AS [Total Duration],AVG([Duration]) AS [Average Duration],AVG([Duration]) AS [Average Duration],SUM([Reads]) AS [Total Reads],SUM([Reads]) AS [Total Reads],AVG([Reads]) AS [Average Reads],AVG([Reads]) AS [Average Reads],SUM([Writes]) AS [Total Write],SUM([Writes]) AS [Total Write],AVG([Writes]) AS [Average Write],AVG([Writes]) AS [Average Write],SUM([CPU]) AS [Total CPU],SUM([CPU]) AS [Total CPU],AVG([CPU]) AS [Average CPU]AVG([CPU]) AS [Average CPU]
FROM dbo.FROM dbo.vw_vw_trc_200612031629trc_200612031629GROUP BY [Procedure]GROUP BY [Procedure]ORDER BY SUM([Duration]) DESCORDER BY SUM([Duration]) DESC
Cleaning DataCleaning Data
You may also want to clean up the data, this is usually easier if you are using stored procedure as you should not need to use sp_prepare
Andrew Zanevsky wrote an interesting article on Trace Scrubbing article from SQL Server Professional in SQL Server Professional magazine http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlpro04/html/sp04j1.asp
ClearTraceClearTrace
Written by SQL Server MVP - Bill GrazianoWritten by SQL Server MVP - Bill Graziano Download from: Download from:
http://www.cleardata.biz/cleartrace/downloahttp://www.cleardata.biz/cleartrace/download.aspxd.aspx
Replaying TracesReplaying Traces
This can be very useful if you do not have This can be very useful if you do not have the facilities to use a tool such as Visual the facilities to use a tool such as Visual Team Test or you only want to stress the Team Test or you only want to stress the database and not the GUIdatabase and not the GUI
Use standard Replay TemplateUse standard Replay Template Replay from file or table (but can not load Replay from file or table (but can not load
file using fn_trace_gettablefile using fn_trace_gettable Can manipulate trace data in table and Can manipulate trace data in table and
export itexport it
Limitations of Replaying TracesLimitations of Replaying Traces
Not imitating users therefore stress is Not imitating users therefore stress is different to live systemdifferent to live system
May not replay correctly (see considerations May not replay correctly (see considerations for replay in Books Online)for replay in Books Online)
Visual Studio Team SuiteVisual Studio Team Suite
Unit and Load test Web applicationsUnit and Load test Web applications Simulate multiple usersSimulate multiple users Programmable to cater for runtime different Programmable to cater for runtime different
etcetc
Microsoft FiddlerMicrosoft Fiddler
Debugging ProxyDebugging Proxy Save as Visual Studio WebTestSave as Visual Studio WebTest Download from www.fiddlertool.comDownload from www.fiddlertool.com
ResourcesResources
Profiling for Better Performance by Kimberly Tripp, MSDN Profiling for Better Performance by Kimberly Tripp, MSDN webcast atwebcast at http://msevents.microsoft.com/cui/webcasteventdetails.aspx?eventid=1032278616&eventcategory=5&culture=en-us&countrycode=us
MSDN Webcasts MSDN Webcasts http://msdn.microsoft.com/webcasts Using Visual Studio 2005 to Perform Load Testing on a Using Visual Studio 2005 to Perform Load Testing on a
SQL Server 2005 Reporting Services Report Server SQL Server 2005 Reporting Services Report Server http://msdn2.microsoft.com/en-us/library/aa964139.aspx
Using SQL Server 2005 Profiler Brian KnightUsing SQL Server 2005 Profiler Brian Knighthttp://www.jumpstarttv.com/Media.aspx?vid=59
SQL Server Manageability Team Blog http://blogs.msdn.com/sqlrem/default.aspx
ResourcesResources
Troubleshooting Performance Problems in SQL Troubleshooting Performance Problems in SQL Server 2005 documentServer 2005 document http://www.microsoft.com/prodtechnol/sql/2005/tsprfprb.mspx
Jasper Smith MVP - 1 Hour Trace Jasper Smith MVP - 1 Hour Trace http://www.sqldbatips.com/displaycode.asp?ID=7
Simon Sabine’s Taskpad Custom Report http://sqlblogcasts.com/blogs/simons/archive/2007/03/28/Update-to-the-taskpad-custom-report.aspx
Aaron Bertrand’s Show Blocking Custom Report http://sqlblog.com/blogs/aaron_bertrand/archive/2006/12/19/448.aspx
www.sqlbits.comwww.SQLBits.com[Conference Web site]
www.SQLBlogCasts.com[Becoming the premier Blogging site for SQL professionals]
www.SQLServerFAQ.com[UK SQL Server Community Website]
Feedback Forms!!
UK SQL Bloggerscwebbbi.spaces.live.comsqlblogcasts.com/blogs/simonssqlblogcasts.com/blogs/tonyrogerson