Performance SQL Server PDF
Performance SQL Server PDF
Best Practices:
Establish a
baseline
Repeat
(if desired)
Measure
performance
Optimize for
real-world
workloads
Identify
bottlenecks
Monitor/review
performance
regularly
Make one
change at a time
Focus on
specific issues
System/OS
SQL
Server
QueryLevel
Activity Monitor
Windows
Performance Monitor
Database Engine
Tuning Advisor
Dynamic
Management Views
(DMVs)
Query Execution
Plans
Category
Largest single database
Largest table
Biggest total data 1 application
Highest database transactions
per second 1 db (from Perfmon)
Fastest I/O subsystem in
production (SQLIO 64k buffer)
Fastest real time cube
data load for 1TB
Largest cube
Metric
70 TB
20 TB
88 PB
130,000
18 GB/sec
5 sec latency
30 minutes
12 TB
Company Profile
Business Requirements
Project Description
Maintains US Equities and Options trading data
Data at this scale require breaking things down into manageable units:
Separate data into different logical areas:
A database per subject area (17)
A database per subject area per year (last 7 years)
Table and Index Partitioning:
255 partitions per database
25,000 filegroups
Filegroup to partition alignment for easier management/less impact moving data
Filegroup backups
Taking advantage of compression:
Compression per partition
Backup compression
Hardware
Operating
System
Sql Server
Database
Design
Application
Sector Alignment
Basic MBR Partition Example
Commands
Diskpart
Select disk 0
List partition
Sector Alignment
Basic MBR Partition Example
Sample Output
Large Pages:
ONLY dedicated 64-bit servers with more than 8GB or
RAM!
Enabled with TF834 see KB920093
Server sloooooooow to start be warned!
Parallelism is good:
Gives you query results faster
But at a cost of using a lot more CPU resources
Often overlooked:
sp_configure cost threshold for parallelism (default 5)
MaxDOP
CPU ms
Duration ms
7344
7399
9797
5997
15845
5451
Best Practice:
Allocate at least on additional filegroup and set
this to the default.
Do not place objects in Primary
Microsoft Confidential
TRACE FLAGs
DBCC TRACEON
Use -1 to turn on trace flag globally
DBCC TRACEOFF
DBCC TRACESTATUS
-T startup flag
Use T# separated by semi-colon (;)
Trace flag 610 controls minimally logged inserts into indexed tables
Allows for high volume data loading
Less information is written to the transaction log
Transaction log file size can be greatly reduced
Introduced in SQL Server 2008
Very fussy
Documented:
Data Loading Performance Guide white paper
http://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspx
Trace flag 1224 disables lock escalation based on the number of locks
Memory pressure can still trigger lock escalation
Database engine will escalate row or page locks to table locks
40% of memory available for locking
sp_configure locks
Non-AWE memory
Scope: Global | Session
Documented: BOL
Note: This list, and the following lists, are not designed to be all inclusive.
Triggers.
Snapshot isolation or read-committed snapshot
isolation (uses less TEMPDB than snapshot
isolation).
MARS (when multiple active result sets are
used).
2. Online-Index-Build Version Store:
2.
3.
Allocation Page
Contention:
2:1:1 = PFS Page
2:1:2 = GAM Page
2:1:3: = SGAM Page
RAM Modules. Validate with the servers manufacturer lowlatency recommendations on CPU and memory SIMMs
combinations, as well as memory SIMMs location on multiple
memory channels per processor.
RAM per CPU Core. For OLTP systems, use 2GB-4GB RAM
per CPU Core.
practices
Disk Host Bus Adapter (HBA). Insert the HBA adapter into the
fastest PCI-E slot.
Fast Track v3 (DW) Disks. For data files (*.MDF, *.NDF) use
multiple SAN/DAS storage enclosures that have multiple RAID10 groups each one with at least 4-spindles, but dedicate one
RAID-10 group on each storage enclosure for log files (*.LDF).
In Fast Track v3 tempdb is mixed with user databases.
Disk Volumes. Ratio #1. Be sure that the division result of Disk
Partition Offset (ex. 1024KB) RAID Controller Stripe Unit Size
(ex. 64KB) = equals an integer value. NOTE: This specific ratio
is critical to minimize disk misalignment.
Disk Volumes. Assign a unique disc volume to the MS DTC log file.
Also, before installing a SQL Server Failover Cluster, create a
separate resource dedicated to MS DTC.
the
instances
Data and Log Files Initial Size. Pre-allocate data and log files
sizes. This will helps to minimize disk block fragmentation and
consuming time increasing file size stopping process until it
ends.
Object
Counter
Value
Notes
Paging
$Usage
<70%
Processor
% Processor
Time
<= 80%
Processor
% Privilege
Time
<30% of
%
Processo
r Time
Process(sqlservr)
Process(msmdsrv
)
% Processor
Time
< 80%
System
Processor
Queue Length
<4
Description
IOPS
Latency
Block Size
Outstanding or
waiting IOPS
Throughput or
Aggregate Throughput
Object
Counter
Value
Notes
Physical Disk
Avg Disk
Reads/sec
<8
Physical Disk
Avg Disk
Writes/sec
< 8 or <1
Memory
Available Mbytes
>100
SQL Server:
Memory Manager
Memory Grants
Pending
~0
Page Life
Expectancy
>=300
Free List
Stalls/sec
<2
SQL Server:
Memory Manager
SQL Server: Buffer
Manager
Object
Counter
Value
Notes
:Access Methods
Forwarded
Records/sec
<10*
:Access Methods
Page Splits/sec
<20*
:Databases
Log Growths/sec;
Percent Log used
< 1 and
<80%,
resp
:SQL Statistics
Batch
Requests/sec
:SQL Statistics
Compilations/sec
;Recompilations/
sec
:Locks
Deadlocks/sec
<1
Targets
Types
Maps
Write to a file
File Targets
Event File
ETW File
In-Memory Targets
Ring Buffer
Event Bucketing
Event Pairing
Synchronous Event Counting
Generate a mini-dump
Defined in ADD/ALTER EVENT clause
Packages
Events and Actions
Filters and Predicates
Sessions
Targets