Module 18
Performance and Monitoring
Module Overview
• Extended Events
• Working with Extended Events
• Live Query Statistics
• Optimize Database File Configuration
• Metrics
Lesson 1: Extended Events
• Extended Events, SQL Trace, and SQL Server
Profiler
• Extended Events Architecture
• Packages
• Events, Actions, and Predicates
• Targets and Sessions
• Types and Maps
• Demonstration: Creating an Extended Events
Session
Extended Events, SQL Trace, and SQL Server
Profiler
• SQL Trace and SQL Server Profiler are tools for
collecting trace information about activity on a
SQL Server instance
• Extended Events is the successor to SQL Trace
and will eventually replace it
• SQL Trace and SQL Server Profiler have been marked
for deprecation since SQL Server 2012
• Extended Events is more flexible than SQL Trace
• Support for new features added since SQL Server 2012
• Greater flexibility comes with greater complexity
Extended Events Architecture
• Extended Events engine provides capabilities
• User defines session
• Session collects event
• Event triggers action
• Event is filtered by predicate
• Session writes to target
• A package defines the objects available to a session
Packages
• Executables and executable modules expose
Extended Events packages
• A package is a container for other object types:
• Events
• Predicates
• Actions
• Targets
• Maps
• Types
Events, Actions, and Predicates
• Events are logging points in executable code
• When an event fires, it indicates that the associated
code has been executed
• Returns data in a fixed schema
• Events are compatible with Event Tracing for Windows
• Use predicates to apply rules to filter events
• Comparisons—logical operators (=, <, > and so on)
• Sources—inputs for comparisons
• Complex predicates may be constructed every n events,
or every n seconds
Targets and Sessions
• Targets collect data from Extended Events sessions
• A session may write to multiple targets
• Targets may be synchronous or asynchronous
• An event will only be written once to a target
• A session links events to targets
• Events may include actions
• Events may be filtered with predicates
• Sessions are isolated from one another
• A session has a state (started or stopped)
• A session has a buffer to hold event data as it is
captured
• Use Watch Live Data to view data for a session
without a target
Types and Maps
• Types
• Data type definitions for Extended Events data
• Maps
• Lookup tables to convert integer values to text values
Demonstration: Creating an Extended Events
Session
In this demonstration, you will learn how to:
• Create an Extended Events session
Lesson 2: Working with Extended Events
• Configuring Sessions
• Configuring Targets
• The system_health Extended Events Session
• Usage Scenarios for Extended Events
• Extended Events Best Practices
• Demonstration: Tracking Session-Level Waits
Configuring Sessions
• Session configuration options:
• MAX_MEMORY
• EVENT_RETENTION_MODE
• MAX_DISPATCH_LATENCY
• MAX_EVENT_SIZE
• MEMORY_PARTITION_MODE
• STARTUP_STATE
• TRACK_CAUSALITY
Configuring Targets
• Targets collect data from Extended Events
sessions
• A session may write to multiple targets
• Targets may be synchronous or asynchronous
• An event will only be written once to a target
• A session links events to targets
• Events may include actions
• Events may be filtered with predicates
• Sessions are isolated from one another
• A session has a state (started or stopped)
• A session has a buffer to hold event data as it is
captured
The system_health Extended Events Session
• The system_health Extended Events session is
created by default
• Starts when the SQL Server instance is started
• Captures events useful for troubleshooting
• Ring buffer and file targets
Usage Scenarios for Extended Events
• Usage Scenario
• Execution time-outs
• Troubleshooting ASYNC NETWORK I/O issues
• Tracking error handling in T-SQL code
• Tracking recompilations
• tempdb latch contention
• Lock escalation
• Problematic page splits
• Troubleshooting orphaned transactions
• Tracking session waits
• Tracking database and object usage
Extended Events Best Practices
• Run Extended Events sessions only when you
need them
• Use the SSMS GUI to browse available events
• Understand the limitations of the ring buffer
target
• Consider the performance impact of collecting
query execution plans
• Deadlock graph format
• Xml_deadlock_report
• Database_xml_deadlock_report
Demonstration: Tracking Session-Level Waits
In this demonstration, you will see how to use
Extended Events to report on wait types by
session
Lesson 3: Live Query Statistics
• What Is Live Query Statistics?
• Enabling Live Query Statistics
• Demonstration: Enable Live Query Statistics for a
Session
What Is Live Query Statistics?
• Compatible with SQL Server 2014 and later
• View a query plan live as the query executes
• Gain insight into long-running queries
• Affects query performance and may reduce
speed
• Live Query Statistics is a feature of SSMS
Enabling Live Query Statistics
• Enable for the current session and view statistics
in the results pane
• Enable for all sessions and view with Activity
Monitor
Demonstration: Enable Live Query Statistics for a
Session
In this demonstration, you will see how to:
• Enable Live Query Statistics
• View the query execution plan
• Disable Live Query Statistics
Lesson 4: Optimize Database File Configuration
• Improving Performance with tempdb
• Configuring tempdb
• Optimize Database File Configuration
Improving Performance with tempdb
• Tempdb is:
• Shared between all databases on a SQL Server instance
• A temporary database; recreated at startup
• Used for a variety of tasks such as holding user created
objects, work area for query intermediate results, and
work tables
• For best performance:
• Store separately from data or log files
• Increase the number of tempdb data files to reduce
latch contention
• Store on fast storage media
Configuring tempdb
• Number of tempdb files = number of processors
• Up to eight, then add in increments of four
• 8 MB default initial file size
• All files must be the same size
• Ensure that the initial file size is sufficient for normal
usage
• Autogrowth default: 64 MB
• Data directories
• Local storage
• Shared storage
• SMB file shares
Optimize Database File Configuration
• Consider splitting data files and log files onto
separate storage media
• Use DMVs to understand I/O loading
• Sys.dm_io_virtual_file_stats
• Use in combination with baseline statistics
Lesson 5: Metrics
• Generating Baseline Metrics
• Collecting Data Using DMVs
• Performance Monitor
• Performance Monitor Counters
• Analyzing Performance Monitor Data
Generating Baseline Metrics
• Baseline metrics provide information about the
normal state of a SQL Server instance
• Consider capturing
• Performance Monitor counters
• Dynamic Management View (DMV) output
• Trace data
• Consider data capture frequency by type of data
Collecting Data Using DMVs
• Collect data using DMOs
• Data that should be collected regularly includes:
• Indexes that are used regularly, and missing indexes
• User activity
• Tasks that are waiting for something
• Missing statistics
Performance Monitor
• Windows Performance Monitor is a snap-in for
Microsoft Management Console
• Displays real-time performance data
• Sales performance data to text files or a database
• Enables creation of custom data collector set
• Can respond to alerts
• Start by typing Performance Monitor from the
start screen
Performance Monitor Counters
• Performance Monitor allows you to:
• Monitor real-time system performance
• Collect data in response to events
• Collect scheduled data
• Performance counts include:
• CPU usage
• Memory usage
• Disk usage
• SQL Server statistics
Analyzing Performance Monitor Data
• To analyze performance monitor data you can
use:
• Microsoft Excel
• Use relog to create a csv file
• Apply aggregations in a worksheet
• A database
• Use relog to import the data
• Analyze the data using Transact-SQL
Lab: Monitoring, Tracing, and Baselining
• Exercise 1: Collecting and Analyzing Data Using
Extended Events
• Exercise 2: Implementing Baseline Methodology
Logon Information
Virtual machine: 20762C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd
Estimated Time: 60 minutes
Lab Scenario
You are investigating why a new SQL Server
instance is running slowly. Users are complaining
that their workloads run particularly slowly during
peak business hours. To troubleshoot these
performance issues, and take informed corrective
measures, you decide to establish a baseline for
SQL Server performance.
In this lab exercise, you will set up data collection
for analyzing workloads during peak business
hours, and implement a baseline methodology to
collect performance data at frequent intervals. This
will enable comparisons to be made with the
baseline.
Lab Review
• What advantages do you see in using Extended
Events to monitor your SQL Server databases?
Module Review and Takeaways
• Review Question(s)
Course Evaluation
• Your evaluation of this course will help Microsoft
understand the quality of your learning
experience.
• Please work with your training provider to access
the course evaluation form.
• Microsoft will keep your answers to this survey
private and confidential and will use your
responses to improve your future learning
experience. Your open and honest feedback is
valuable and appreciated.