Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright Sammamish Software Services 2013. All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.

Similar presentations


Presentation on theme: "Copyright Sammamish Software Services 2013. All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning."— Presentation transcript:

1 Copyright Sammamish Software Services 2013. All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning

2 Copyright Sammamish Software Services 2013. All rights reserved. 2 Performance Monitoring Tools  Optimizing queries using Execution Plans  DETA (Database Engine Tuning Advisor)  SQL Server Profiler  Activity Monitor  SQL Server Stored Procedures  System Monitor (Perfmon)/SQL Performance Counters

3 Copyright Sammamish Software Services 2013. All rights reserved. 3 SS2012 Performance Tips setup  SQL Server 2012 supports named instances of SQL Server. You can run up to 16 concurrent instances of SQL Server 2012 on the same server. Each running instance of SQL Server takes up server resources. Some resources are shared by multiple running instances, i.e., MSDTC and Search services, but most aren’t. Because of this, each additional instance of SQL Server running on the same server has to fight for available resources, hurting performance  For best performance, don't mix production databases and development (test or staging) databases on the same physical server. This not only serves to better separate the two functions (production and development), but prevents developers from using up server resources that could be better used by production users.

4 Copyright Sammamish Software Services 2013. All rights reserved. 4 Disk IOs: Reads vs Writes  Find out if the disk I/O of your servers (and the databases on it) are mostly reads or mostly writes. This info can be used to calculate the ratio of writes to reads of your server If your server is heavy on writes, then you should avoid RAID 5, and use RAID 10 instead. RAID 10 is more efficient for writes. Vice versa if your system is Read heavy then RAID 5 is likely a better choice  To find out the ratio of reads to writes run Task Manager and look at the sqlservr.exe process (this is the mssqlserver or sqlserv service);view the total number of I/O Read Bytes and I/O Write Bytes. (If you don't see this in Task Manager, check the “Show processes from all users box” then go to View|Select Column, and add these two columns.) The results you see tell you how many bytes of data have been written and read from the SQL Server service since it was last restarted. Because of this, you don't want to read this figure immediately after starting the SQL Server service, but after several days of typical use.

5 Copyright Sammamish Software Services 2013. All rights reserved. 5 SS2012 Performance Tips: Dev  Use Truncate table instead of Delete. Truncate is “minimally logged” ; then you must run Update Statistics!  If you must allow users to access to your data, e.g. using Excel or Access, instead point them to a replicated reporting server i.e., a DM or DW, rather than your OLTP  Use consistent coding style and format  Instead of SELECT COUNT(*) from A much faster, and more efficient, way of counting rows in a table is to run the following query: SELECT rows FROM sysindexes WHERE id = OBJECT_ID(' ') AND indid < 2

6 Summary of query performance tips in this course  Good db design = better performance  Use joins instead of subqueries when possible  The “like” operator (pattern matching) is a performance hit – if you can substitute with a range then do so.  Limit nesting of objects like views, sprocs  Limit use of triggers since the rollback is expensive Copyright Sammamish Software Services 2013. All rights reserved. 6  Use of stored procedures and views are better than scripts for performance since SS can store execution plans and use caching  Limit use of functions in large queries to enable caching

7 Copyright Sammamish Software Services 2013. All rights reserved. 7 How SQL Processes queries  A SELECT statement is nonprocedural; it does not state the exact steps that the database server should use to retrieve the requested data. This means that the database server must analyze the statement to determine the most efficient way to extract the requested data.  This is referred to as optimizing the SELECT statement. The component that does this is called the query optimizer.  The input to the optimizer consists of the query, the database schema (table and index definitions), and the database statistics. The output of the optimizer is a query execution plan

8 Copyright Sammamish Software Services 2013. All rights reserved. 8 Using Execution Plans  In SQL Server 2012, you can display execution plans by using the following methods: SQL Server Management Studio Displays either an estimated graphical execution plan (statements do not execute) or an actual graphical execution plan (on executed statements), which you can save and view in Management Studio. Transact-SQL SET statement options When you use the Transact-SQL SET statement options, you can produce estimated and actual execution plans in XML or text. SQL Server Profiler event classes Icons: http://msdn.microsoft.com/en- us/library/ms175913(v=SQL.10 5).aspx

9 Copyright Sammamish Software Services 2013. All rights reserved. 9 SQL Server system stored procedures  sp_who/sp_who2 Reports snapshot information about current SQL Server users and processes, including the currently executing statement and whether the statement is blocked.  sp_lock Reports snapshot information about locks, including the object ID, index ID, type of lock, and type or resource to which the lock applies.  sp_spaceused Displays an estimate of the current amount of disk space used by a table (or a whole database).  sp_monitor Displays statistics, including CPU usage, I/O usage, and the amount of time idle since sp_monitor was last executed.

10 Copyright Sammamish Software Services 2013. All rights reserved. 10 Query optimizer hints:  Set Transaction Isolation Level Read Uncommitted select TesterContextID, o.Name Operation, elTester.Name Tester, ts.ComputerName, elGroup.Name TesterGroup, elLine.Name Line, s.Name Factory FROM dbo.TesterContext tc join dbo.Operation o with (nolock) on o.OperationID = tc.OperationID left JOIN dbo.TesterStation ts with (nolock) on ts.TesterStationID = tc.TesterStationID join dbo.EquipmentLocation ElTester with (nolock) on ElTester.equipmentLocationID = tc.equipmentLocationID left join dbo.EquipmentLocationHierarchy elh1 with (nolock) on elh1.childLocationID = elTester.equipmentLocationID left join dbo.EquipmentLocation ElGroup with (nolock) on ElGroup.equipmentLocationID = elh1.ParentLocationID left join dbo.EquipmentLocationHierarchy elh2 with (nolock) on elh2.childLocationID = elGroup.equipmentLocationID left join dbo.EquipmentLocation ElLine with (nolock) on ElLine.equipmentLocationID = elh2.ParentLocationID left join dbo.Site s with (nolock) on s.SiteID = ElTester.SiteID

11 Copyright Sammamish Software Services 2013. All rights reserved. 11 Performance Monitor  Perfmon (Performance Monitor)  You can view SQL Server objects, performance counters, and the behavior of other objects processors, memory, cache, threads, processes.

12 Copyright Sammamish Software Services 2013. All rights reserved. 12 Activity Monitor

13 Copyright Sammamish Software Services 2013. All rights reserved. 13 SQL Server Profiler  SQL Server Profiler is a graphical user interface to SQL Trace for monitoring an instance of the SQL Server Database Engine or Analysis Services. You can capture and save data about each event to a file or table to analyze later. For example, you can monitor a production environment to see which stored procedures are affecting performance by executing too slowly.

14 Copyright Sammamish Software Services 2013. All rights reserved. 14 Database Engine Tuning Advisor Details (DETA)  Database Engine Tuning Advisor evaluates more types of events and structures, and provides higher quality recommendations  DTA provides two interfaces: A standalone graphical user interface tool for tuning databases, and viewing tuning recommendations and reports A command-line utility program, dta.exe

15 Copyright Sammamish Software Services 2013. All rights reserved. 15 The database engine tuning advisor  Database Engine Tuning Advisor analyzes the performance effects of workloads run against one or more databases. A workload is a set of Transact-SQL statements that executes against databases you want to tune.  DTA provides recommendations to add, remove, or modify physical design structures: physical clustered indexes, nonclustered indexes, indexed views, and partitioning.

16 Copyright Sammamish Software Services 2013. All rights reserved. 16 Workloads  Database Engine Tuning Advisor requires a workload. A workload consists of a Transact-SQL script or a SQL Server Profiler trace saved to a file or table.  Database Engine Tuning Advisor is designed to handle the following workload types: Online transaction processing (OLTP) queries alone Online analytical processing (OLAP) queries alone Mixed OLTP and OLAP queries Query-heavy workloads (more queries than updates) Update-heavy workloads (more updates than queries)  You can create Workloads using the Tuning Template in SQL Server Profiler. After the trace has captured a representative sample of normal database activity, Database Engine Tuning Advisor analyzes the workload and then recommends an optimal configuration of indexes, indexed views, or partitions that improve database performance. You can also use as workloads: Problem queries that take a long time to run.

17 Copyright Sammamish Software Services 2013. All rights reserved. 17 SQL 2012 Walk throughs  Exercise: DETA Walk-through

18 Copyright Sammamish Software Services 2013. All rights reserved. 18 Top 5 Performance techniques 1. For best performance, don't mix production databases and development (test or staging) databases on the same physical server. 2. Index for performance 3. All dev’s must understand DB design techniques and all the tools available 4. Understand Disk IO (reads vs. Writes) 5. Understand and utilize available tools: Perfmon, Profiler, DETA, Execution Plans, good coding practices

19 Copyright Sammamish Software Services 2013. All rights reserved. 19 References  Excellent Technet article: http://social.technet.microsoft.com/wiki/contents /articles/5957.sql-server-performance-survival- guide.aspx http://social.technet.microsoft.com/wiki/contents /articles/5957.sql-server-performance-survival- guide.aspx  SQL Server performance web site: http://www.sql-server-performance.com/  An expensive but useful book: SQL Tips and Techniques:  http://www.amazon.com/Tips-Techniques- Miscellaneous-Konrad- King/dp/1931841454/ref=sr_1_1?ie=UTF8&qi d=1369327498&sr=8- 1&keywords=sql+tips+and+tricks http://www.amazon.com/Tips-Techniques- Miscellaneous-Konrad- King/dp/1931841454/ref=sr_1_1?ie=UTF8&qi d=1369327498&sr=8- 1&keywords=sql+tips+and+tricks


Download ppt "Copyright Sammamish Software Services 2013. All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning."

Similar presentations


Ads by Google