Upload
jeremiaspala
View
231
Download
0
Embed Size (px)
Citation preview
8/19/2019 Performance SQL Server.pdf
1/81
Maximiliano Damian AccottoMVP en SQL Server
http://www.triggerdb.com
http://blog.maxiaccotto.com
http://www.triggerdb.com/http://blog.maxiaccotto.com/http://blog.maxiaccotto.com/http://www.triggerdb.com/
8/19/2019 Performance SQL Server.pdf
2/81
8/19/2019 Performance SQL Server.pdf
3/81
Best Practices:Optimize forreal-worldworkloads
Monitor/reviewperformanceregularly
Focus onspecific issues
Establish abaseline
Identifybottlenecks
Make onechange at a time
Measureperformance
Repeat(if desired)
8/19/2019 Performance SQL Server.pdf
4/81
System/OS
WindowsPerformance Monitor
Alerts (Performance-Based)
SQLServer
Activity Monitor
SQL Profiler / SQLTrace
Database EngineTuning Advisor
DynamicManagement Views
(DMVs)
Query-Level
Database EngineTuning Advisor
Query ExecutionPlans
8/19/2019 Performance SQL Server.pdf
5/81
8/19/2019 Performance SQL Server.pdf
6/81
Category Metric
Largest single database 70 TB
Largest table 20 TB
Biggest total data 1 application 88 PB
Highest database transactionsper second 1 db (from Perfmon)
130,000
Fastest I/O subsystem in
production (SQLIO 64k buffer)
18 GB/sec
Fastest “real time” cube 5 sec latency
data load for 1TB 30 minutes
Largest cube 12 TB
8/19/2019 Performance SQL Server.pdf
7/81
Company Profile• World’s largest publicly listed online gaming platform• 20 million registered customers in more than 25 core markets
>14,000 bets offered simultaneously on more than 90 sports~ 90 live events with videos every day – bwin world’s largestbroadcaster of live sports>70,000 payment transactions (PCI Level 1 and ISO 27001 certified)
per day
Business Requirements• Failure is not an option
• 100% transactional consistency, zero data loss• 99.998% availability...even after loss of a data center
• Performance critical• Must scale to handle every user and and give them a great experience
• Protect users privacy and financial information• Provide a secure PCI compliant environment for all customers
8/19/2019 Performance SQL Server.pdf
8/81
SQL Server Environment• 100+ SQL Server Instances
• 120+ TB of data
• 1,400+ Databases
• 1,600+ TB storage
• 450,000+ SQL Statements per second on a single server
• 500+ Billion database transactions per day
Core component in solutions designated for:
• Financial transactions
• Gaming environments
• Tracking user state throughout the system
Solutions primarily scale-up using commodity hardware
8/19/2019 Performance SQL Server.pdf
9/81
SQL Server Infrastructure• Almost 200 production SQL Server instances
8/19/2019 Performance SQL Server.pdf
10/81
Single High Transaction throughput system provides:
Mission critical to the business in terms of performance andavailability
8/19/2019 Performance SQL Server.pdf
11/81
Project DescriptionMaintains US Equities and Options trading data
Processing 10’s of billions of transactions per day Average over 1 million business transactions/sec into SQL Server Peak: 10 million/sec
Require last 7 years of online dataData is used to comply with government regulations
Requirements for “real-time” query and analysis Approximately 500 TB per year , totaling over 2PB of uncompressed data
Largest tables approaching 10TB (page compressed) in size
Early Adopter and upgrade to SQL Server 2014 in-order-to:Better manage data growthImprove query performanceReduce database maintenance time
8/19/2019 Performance SQL Server.pdf
12/81
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
8/19/2019 Performance SQL Server.pdf
13/81
Hardware OperatingSystem
Sql Server DatabaseDesign
Application
8/19/2019 Performance SQL Server.pdf
14/81
8/19/2019 Performance SQL Server.pdf
15/81
Use Disk Alignment at 1024KB
Use GPT if MBR not large enoughFormat partitions at 64KB allocation unit size
One partition per LUN
Only use Dynamic Disks when there is a need tostripe LUNs using Windows striping (i.e. AnalysisServices workload)
Tools:
Diskpar.exe, DiskPart.exe and DmDiag.exeFormat.exe, fsutil.exe
Disk Manager
8/19/2019 Performance SQL Server.pdf
16/81
Here is a graph of performance improvement fromMicrosoft’s white paper:
8/19/2019 Performance SQL Server.pdf
17/81
Sector Alignment
Basic MBR Partition Example
Commands
Diskpart
Select disk 0
List partition
8/19/2019 Performance SQL Server.pdf
18/81
Sector Alignment
Basic MBR Partition Example
Sample Output
8/19/2019 Performance SQL Server.pdf
19/81
RAID-1 is OK for log files and datafiles but you can dobetter…
RAID-5 is a BIG NO! for anything except read-only or read-
mostly datafilesRAID-10 is your best bet (but most expensive)
NEVER put OLTP log files on RAID-5!
If you can afford it:
Stripe And Mirror Everything (SAME) – one HUGERAID-10
SSD is even better – consider for tempdb and/or log files
If adventurous, use RAW partitions (see BOL)
8/19/2019 Performance SQL Server.pdf
20/81
As much as you can get…
…and more!64-bit is great for memory-intensive workloads
If still on 32-bit, use AWE
Are you sharing the box? How much memoryneeds to be set aside? Set max/min servermemory as needed.
Observe where all this memory goes:
Data Cache vs. Procedure Cache vs. Lock Managervs. Other
Keep an eye for „ A significant part of sql serverprocess memory has been paged out” error in theerrorlog.
8/19/2019 Performance SQL Server.pdf
21/81
Min/max server memory – when needed.
Locked pages:32-bit – when using AWE
x64 Enterprise Edition – just grant „Lock Pages inMemory” privilege
X64 Standard Edition – must have hotfix and enableTF845 (see KB970070 for details)
Large Pages:ONLY dedicated 64-bit servers with more than 8GB orRAM!
Enabled with TF834 – see KB920093
Server sloooooooow to start – be warned!
8/19/2019 Performance SQL Server.pdf
22/81
CPU is rarely the real bottleneck – look for WHYwe are using so much CPU power!
Use affinity mask as needed:Splitting the CPUs between applications (or SQLinstances)
Moving SQL Server OFF the CPU that serves NICIRQs
With a really busy server:Increase max worker threads (but be careful – it’s notfor free!)Consider lightweight pooling (be SUPER careful – noSQLCLR and some other features – see KB319942and BOL).
8/19/2019 Performance SQL Server.pdf
23/81
Parallelism is good:Gives you query results faster But at a cost of using a lot more CPU resources
MAXDOP setting is your friend:On server level (sp_configure „max degree ofparallelims”)
On Resource Governor workload group
On a single query (OPTION (MAXDOP 1))
Often overlooked:sp_configure „cost threshold for parallelism” (default 5)
8/19/2019 Performance SQL Server.pdf
24/81
Data file layout matters…
Choose your Recovery Model carefully:Full – highest recoverability but lowest performance
Bulk-logged – middle ground
Simple – no log backups, bulk operations minimallylogged
Always leave ON: Auto create statistics
Auto update statistics
Always leave OFF:
Auto shrink
8/19/2019 Performance SQL Server.pdf
25/81
8/19/2019 Performance SQL Server.pdf
26/81
Optimizes processing times RebuildUses more CPU cores
ALTER INDEX ALL ON Person.Person
REBUILD WITH (MAXDOP= 4)
8/19/2019 Performance SQL Server.pdf
27/81
MaxDOP CPU ms Duration ms
1 7344 7399
2 9797 5997
4 15845 5451
8/19/2019 Performance SQL Server.pdf
28/81
Designing High Performance I/O systemsSQL Server’s View of I/O
8/19/2019 Performance SQL Server.pdf
29/81
High rate of allocations to any data files can result in scaling
issues due to contention on allocation structuresImpacts decision for number of data files per file group
Especially a consideration on servers with many CPU cores
PFS/GAM/SGAM are structures within data file which managefree space
Easily diagnosed by looking for contention on PAGELATCH_UPEither real time on sys.dm_exec_requests or tracked insys.dm_os_wait_stats
Resource description in form of DBID:FILEID:PAGEID
Can be cross referenced withsys.dm_os_buffer_descriptors to determine type of page
8/19/2019 Performance SQL Server.pdf
30/81
More data files does not necessarily equal better
performanceDetermined mainly by 1) hardware capacity & 2) access patterns
Number of data files may impact scalability of heavy write
workloads
Potential for contention on allocation structures (PFS/GAM/SGAM
Mainly a concern for applications with high rate of page allocations
on servers with >= 8 CPU cores
Can be used to maximize # of spindles – Data files can be
used to “stripe” database across more physical spindles
8/19/2019 Performance SQL Server.pdf
31/81
Provides less flexibility with respect to mapping datafiles into differing storage configurations
Multiple files can be used as a mechanism to stripedata across more physical spindles and/or serviceprocessors (applies to many small/mid range arrays)
A single file prevents possible optimizations related tofile placement of certain objects (relatively uncommon)
Allocations heavy workloads (PFS contention) mayincur waits on allocation structures, which aremaintained per file.
8/19/2019 Performance SQL Server.pdf
32/81
The primary filegroup contains all systemobjectsThese CANNOT be moved to anotherfilegroup
If using file group based backup, you mustbackup PRIMARY as part of regular backups
If not, you cannot restore!Primary must be restored before other filegroups
Best Practice: Allocate at least on additional filegroup and setthis to the default.Do not place objects in Primary
8/19/2019 Performance SQL Server.pdf
33/81
Microsoft Confidential
8/19/2019 Performance SQL Server.pdf
34/81
Virtual LOG Files & PerformanceSQL Server’s View of I/O
8/19/2019 Performance SQL Server.pdf
35/81
8/19/2019 Performance SQL Server.pdf
36/81
TRACE FLAGsSQL Server’s View of I/O
8/19/2019 Performance SQL Server.pdf
37/81
DBCC TRACEONUse -1 to turn on trace flag globally
DBCC TRACEOFF
DBCC TRACESTATUS-T startup flag
Use –T# separated by semi-colon (;)
8/19/2019 Performance SQL Server.pdf
38/81
8/19/2019 Performance SQL Server.pdf
39/81
Trace flag 610 controls minimally logged inserts into indexed tables
Allows for high volume data loadingLess information is written to the transaction logTransaction log file size can be greatly reducedIntroduced in SQL Server 2008“Very fussy”Documented:
Data Loading Performance Guide white paperhttp://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspx
http://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspxhttp://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspx
8/19/2019 Performance SQL Server.pdf
40/81
Trace flag 1224 disables lock escalation based on the number of locksMemory pressure can still trigger lock escalationDatabase engine will escalate row or page locks to table locks40% of memory available for lockingsp_configure ‘locks’Non-AWE memoryScope: Global | SessionDocumented: BOL
8/19/2019 Performance SQL Server.pdf
41/81
Forces all files to auto-grow at the sametime
8/19/2019 Performance SQL Server.pdf
42/81
Trace flag 1118 directs SQL Server to allocate fullextents to each tempdb objects (instead of mixedextents)Less contention on internal structures such asSGAM pages
Story has improved in subsequent releases of SQLServer
8/19/2019 Performance SQL Server.pdf
43/81
8/19/2019 Performance SQL Server.pdf
44/81
Local and global temporary tables (andindexes if created)
User-defined tables and indexes
Table variablesTables returned in table-valued functions
Note: This list, and the following lists, are not designed to be all inclusive.
8/19/2019 Performance SQL Server.pdf
45/81
Work tables for DBCC CHECKDB and DBCCCHECKTABLE.
Work tables for hash operations, such as joins andaggregations.
Work tables for processing static or keyset cursors.
Work tables for processing Service Broker objects.
Work files needed for many GROUP BY, ORDER BY,UNION, SORT, and SELECT DISTINCT operations.
Work files for sorts that result from creating or rebuilding
indexes (SORT_IN_TEMPDB).
8/19/2019 Performance SQL Server.pdf
46/81
The version store is a collection of pages used to storerow-level versioning of data.
There are two types of version stores:1. Common Version Store: Examples include:
Triggers.
Snapshot isolation or read-committed snapshotisolation (uses less TEMPDB than snapshotisolation).
MARS (when multiple active result sets are
used).2. Online-Index-Build Version Store:
Used for online index builds or rebuilds. EEedition only.
8/19/2019 Performance SQL Server.pdf
47/81
TEMPDB is dropped and recreated every time the SQLServer service is stopped and restarted.
When SQL Server is restarted, TEMPDB inherits many ofthe characteristics of model, and creates an MDF file of8MB and an LDF file of 1MB (default setting).
By default, autogrowth is set to grow by 10% withunrestricted growth.
Each SQL Server instance may have only one TEMPDB,although TEMPDB may have multiple physical files.
8/19/2019 Performance SQL Server.pdf
48/81
Many TEMPDB database options can’t be changed (e.g.Database Read-Only, Auto Close, Auto Shrink).
TEMPDB only uses the simple recovery model.
TEMPDB may not be backed up, restored, be mirrored,have database snapshots made of it, or have many
DBCC commands run against it.TEMPDB may not be dropped, detached, or attached.
8/19/2019 Performance SQL Server.pdf
49/81
TEMPDB logging works differently from regular logging.Operations are minimally logged, as redo information is notincluded, which reduces TEMPDB transaction log activity.
The log is truncated constantly during the automaticcheckpoint process, and should not grow significantly,
although it can grow with long-running transactions, or ifdisk I/O is bottlenecked.
If a TEMPDB log file grows wildly:Check for long-running transactions (and kill them if necessary).
Check for I/O bottlenecks (and fix them if possible).
Manually running a checkpoint can often temporally reduce awildly growing log file if bottle-necked disk I/O is the problem.
8/19/2019 Performance SQL Server.pdf
50/81
Generally, there are three major problems yourun into with TEMPDB:1. TEMPDB is experiencing an I/O bottleneck, hurting server
performance.
2. TEMPDB is experiencing contention on various global allocation
structures (metadata pages) as temporary objects are being created,populated, and dropped. E.G. Any space-changing operationacquires a latch on PFS, GAM or SGAM pages to update spaceallocation metadata. A large number of such operations can causeexcessive waits while latches are acquired, creating a bottleneck(hotspot), and hurting performance.
3. TEMPDB has run out of space.Ideally, you should be monitoring all these on aproactive basis to identify potential problems.
8/19/2019 Performance SQL Server.pdf
51/81
Use Performance Monitor to determine how busy the disk is whereyour TEMPDB MDF and LDF files are located.
LogicalDisk Object: Avg. Disk Sec/Read: The average time, inseconds, of a read of data from disk. Numbers below are a generalguide only and may not apply to your hardware configuration.
Less than 10 milliseconds (ms) = very good
Between 10-20 ms = okayBetween 20-50 ms = slow, needs attention
Greater than 50 ms = serious IO bottleneck
LogicalDisk Object: Avg. Disk Sec/Write: The average time, inseconds, of a write of data to the disk. See above guidelines.
LogicalDisk: %Disk Time: The percentage of elapsed time that theselected disk drive is busy servicing read or write requests. A generalguideline is that if this value > 50%, there is a potential I/O bottleneck.
8/19/2019 Performance SQL Server.pdf
52/81
Use these performance counters to monitor allocation/deallocationcontention in SQL Server:
Access Methods:Worktables Created/sec: The number of work tablescreated per second. Work tables are temporary objects and are used tostore results for query spool, LOB variables, and cursors. This numbershould generally be less than 200, but can vary based on your hardware.
Access Methods:Workfiles Created/sec: Number of work files createdper second. Work files are similar to work tables but are created byhashing operations. Used to store temporary results for hash and hashaggregates. High values may indicate contention potential. Create abaseline.
Temp Tables Creation Rate: The number of temporary tablescreated/sec. High values may indicate contention potential. Create a
baseline.Temp Tables For Destruction: The number of temporary tables orvariables waiting to be destroyed by the cleanup system thread. Shouldbe near zero, although spikes are common.
8/19/2019 Performance SQL Server.pdf
53/81
Minimize the use of TEMPDBEnhance temporary object reuse
Add more RAM to your server
Locate TEMPDB on its own array
Locate TEMPDB on a fast I/O subsystem
Leave Auto Create Statistics & Auto Update Statistics on
Pre-allocate TEMPDB space – everyone needs to do this
Don’t shrink TEMPDB if you don’t need to
Divide TEMPDB among multiple physical files
Avoid using Transparent Data Encryption (2008)
8/19/2019 Performance SQL Server.pdf
54/81
8/19/2019 Performance SQL Server.pdf
55/81
If latches are waiting to be acquired on TEMPDB pages forvarious connections, this may indicate allocation pagecontention.
Use this code to find out:
SELECT session_id, wait_duration_ms, resource_descriptionFROM sys.dm_os_waiting_tasks
WHERE wait_type like 'PAGE%LATCH_%' AND resource_description like
'2:%'
Allocation Page
Contention:
2:1:1 = PFS Page2:1:2 = GAM Page2:1:3: = SGAM Page
8/19/2019 Performance SQL Server.pdf
56/81
8/19/2019 Performance SQL Server.pdf
57/81
Installation & Configuration Best Practices for Performance Server Role. Server should be a member server of a Microsoft
Active Directory network, and dedicated only to SQL Server.Windows File, Print, and Domain Controller services should beleft for other machines.
System Architecture. Use 64-bit architecture server.
32-Bit Systems. Include de /PAE parameter inside the boot.inif ile on Windows Server 2003 on servers with more than 4GBRAM.
SQL Server Edition. Use the DEVELOPER edition ondevelopment and test servers. Use the ENTERPRISE edition on
QA and Production servers.
CPU Cache. Use servers with CPUs that has L3 memorycache.
Whitepapers. Look for Low-Latency best practicesconfigurations on server manufacturer’s websites.
BIOS. Disable CPU Hyper-Threading (or “Logical Processor”) atthe BIOS level. Use Intel’s Processor ID utility to verify it.
BIOS. Disable CPU Turbo Mode (or Turbo Boost Optimization).
BIOS. Disable CPU C-States (or C-3, C6, etc.).
BIOS. Disable CPU C1E.
BIOS. Change Power Management to Maximum Performance.
BIOS. Disable QPI Power Management.
BIOS. Change Power Profile to Maximum Performance.
BIOS. Change Power Regulator to High Performance Mode.
RAM Modules. Validate with the server’s manufacturer low-latency recommendations on CPU and memory SIMMscombinations, as well as memory SIMMs location on multiplememory channels per processor.
RAM per CPU Core. For OLTP systems, use 2GB-4GB RAM
per CPU Core.
RAM per CPU Socket in Fast Track v3 (Data Warehousing).
For 2-CPU Socket use minimum of 96 GB RAM. For 4-CPUSocket use minimum of 128 GB RAM. For 8-CPU Socket useminimum of 256 GB RAM.
Processor Scheduling. Be sure that in Computer properties,Performance Options, the Processor Scheduling parameter isconfigured for “Background Services”.
Network Interface Cards. Have, at least, two network interface
cards connected to two different networks in order to divideapplication load from administrative load.
8/19/2019 Performance SQL Server.pdf
58/81
Installation & Configuration Best Practices for Performance Network Interface Cards. Configure each network interface
adapter for “Maximize data throughput for network applications”.
Network Interface Cards. For OLAP systems (DataWarehouses and Cubes), Database Mirroring, Log Shipping,and Replication… evaluate using Jumbo Frames (9-Mbps) onall devices that interact with each other (switches, routers, andNICs).
Disk Volumes. Use Solid-State (SSD) disks or 15K disks.
Disk Volumes. Use RAID-10 (or RAID-1) arrays when possible.Use RAID-5 as last option. Never use RAID-0. RAID-5 is
excellent for reading, but not best for writ ing (specially bad inrandom write). On direct-attached systems (DAS), if you needto balance performance and space between solid-state disks(SSD) and 15K disks (SAS), one strategy is to have solid-statedisk at RAID-5 and 15k disks at RAID-10.
RAID Controller. In virtual disks, indicate cache configurationin Write Policy = Write-Through (instead of Write-Back). Theobjective is to acknowledge the operating system thecomplet ion of the transaction when is written to the storagesystem instead of the RAID controller’s cache. Otherwise, is a
consistency risk if the controller’s battery is not working andenergy goes down.
Fast Track v3 (DW) – Disks. For Windows operating system
and SQL Server binary f iles, use a 2-Disk Spindles RAID-1local disks array.
Disk Volumes. Assign separate virtual disks (ex. SAN LUNs)for SQL Server data, log, tempdb, backups.
Disk Host Bus Adapter (HBA). Insert the HBA adapter into thefastest PCI-E slot.
PCIe x4 v2.0 delivers up to 2GB/sec.
PCIe x4 v1.0 delivers up 1GB/sec.
PCIe x1 v2.0 delivers up to 500MB/sec.
PCIe x1 v1.0 delivers up to 250MB/sec.
Disk Host Bus Adapter (HBA). Configure the HBA’s QueueDepth parameter (in Windows Registry) with the value thatreports the best performance on SQLIO tests (x86 and x64only) or SQLIOSIM (x86, x64, and IA64).
Fast Track v3 (DW) – Disks. For data files (*.MDF, *.NDF) usemultiple SAN/DAS storage enclosures that have multiple RAID-10 groups each one with at least 4-spindles, but dedicate oneRAID-10 group on each storage enclosure for log files (*.LDF).In Fast Track v3 tempdb is mixed with user databases.
Disk Volumes. Have each operating system disk partitioned asone volume only. Don’t divide each disk into multiple logicalvolumes.
8/19/2019 Performance SQL Server.pdf
59/81
Installation & Configuration Best Practices for Performance Disk Volumes. Partition each disk volume with Starting Offset
of 1024K (1048576).
Disk Volumes. Do NOT use Windows NTFS File Compression.
Disk Volumes. Format disk volumes using NTFS. Do not useFAT or FAT32.
Disk Volumes. Use Windows Mount Point Volumes (folders)instead of drive letters in Failover Clusters.
Disk Volumes. Format each SQL Server disk volume (data,log, tempdb, backups) with Allocation Unit of 64KB, and do aquick format if volumes are SAN Logical Units (LUNs).
Disk Volumes. Ratio #1. Be sure that the division result of DiskPartition Offset (ex. 1024KB) ÷ RAID Controller Stripe Unit Size(ex. 64KB) = equals an integer value. NOTE: This specific ratiois critical to minimize disk misalignment.
Disk Volumes. Ratio #2. Be sure that the division result of RAID Controller Stripe Unit Size (ex. 64KB) ÷ Disk Partit ion Allocation Unit Size (ex. 64KB) = equals an integer value.
Fast Track v3 (DW) – Multi-path I/O (MPIO) to SAN. Installand Multi-Path I/O (MPIO), configure each disk volume to havemultiple MPIO paths defined with, at least, one Active path, andconsult SAN vendor prescribe documentations.
Disk Volumes. Assign a unique disc volume to the MS DTC log file.
Also, before installing a SQL Server Failover Cluster, create aseparate resource dedicated to MS DTC.
Windows Internal Services. Disable any Windows service notneeded for SQL Server.
Windows Page File. Be sure that Windows paging is configure to useeach operating system disk only. Do not include paging file on any of SQL Server disks.
Antivirus. The antivirus software should be configure to NOT scanSQL Server database, logs, tempdb, and backup folders (*.mdf, *.ldf,*.ndf, *.bak) .
SQL Server Engine Startup Flags for Fast Track v3 (Data
Warehousing). Start the SQL Server Engine with the -E and -T1117startup flags.
SQL Server Service Accounts. Assign a different Active Directoryservice account to each SQL Server service installed.
Service Account and Windows Special Rights. Assign the SQLServer service account the following Windows user right policies: 1)Lock pages in memory, and 2) Perform volume maintenance tasks.
Address Windows Extensions (AWE). If the SQL Server serviceaccount has the Lock pages in memory Windows user right, thenenable the SQL instance AWE memory opt ion. ( Note: AWE wasremoved from SQL Server 2012; use 64-bit! ).
8/19/2019 Performance SQL Server.pdf
60/81
Installation & Configuration Best Practices for Performance Instance Maximum Server Memory. If exist only one (1) SQL
Database Instance and no other SQL engines, then configurethe instance’s Maximum Server Memory option with a value of 85% the global physical memory available.
Tempdb Data Files. Be sure that the tempdb database has thesame amount of data files as CPU cores and with the samesize.
Startup Parameter T1118. Evaluate the use of trace flag T1118as a startup parameter for the RDBMS engine to minimizeallocation contention in tempdb.
Maximum Degree of Parallelism (MAXDOP). For OLTP
systems, configure the instance’s MAXDOP=1 or higher (up to8) depending on the number of physical CPU chips. For OLAPsystems, configure MAXDOP=0 (zero).
Maximum Worker Threads. Configure the instance’sMaximum Worker Threads = 0 (zero).
Boost SQL Server Priority. Configure the instance’s BoostSQL Server Priority=0 (zero).
Database Data and Log Default Locations. Configure theinstance database default locations for data and log files.
Backup Files Default Location. Configure the instance backuplocation.
Backup Compression. In SQL Server 2008, enable the
instance backup compression option.
Filegroups. Before creating any database object (tables,indexes, etc.), create a new default filegroup (NOT PRIMARY)for data.
Data and Log Files Initial Size. Pre-allocate data and log filessizes. This will helps to minimize disk block fragmentation andconsuming time increasing file size stopping process until i tends.
Fast Track v3 (DW) – Compression. For Fact Tables use
Page Compression. In the other hand, compression for Dimension tables should be considered on a case-by-casebasis.
Fast Track v3 (DW) – Index Defragmentation. Whendefragmenting indexes, use ALTER INDEX [index_name] on[schema_name].[table_name] REBUILD (WITH MAXDOP = 1,SORT_IN_TEMPDB = TRUE) to improve performance andavoid filegroup fragmentation. Do not use the ALTER INDEXREORGANIZE statement. To defrag indexes specially on FACTTABLES from data warehouses, include
DATA_COMPRESSION = PAGE.
Tools. Use the Microsoft SQL Server 2008 R2 Best Practices Analyzer (BPA) to determine if something was left or notconfigured vs. best practices.
8/19/2019 Performance SQL Server.pdf
61/81
Installation & Configuration Best Practices for Performance Tools. Use Microsoft NT Testing TCP Tool (NTttcp) to
determine networking actual throughput.
Tools. Use Microsoft SQLIO and Microsoft SQLIOSim to stresstest storage and validate communication errors.
Tools. Use CPUID CPUz to determine processor information,specially at which speed is currently running.
Tools. Use Intel Processor Identification to determine processor information, specially if Hyperthreading is running.
8/19/2019 Performance SQL Server.pdf
62/81
8/19/2019 Performance SQL Server.pdf
63/81
Object Counter Value Notes
Paging $Usage
8/19/2019 Performance SQL Server.pdf
64/81
Logical Disk Counter Storage Guy’s term Description
Disk Reads / Second
Disk Writes / Second
IOPS Measures the Number of I/O’s per second
Discuss with vendor sizing of spindles of different
type and rotational speeds
Impacted by disk head movement (i.e. short stroking
the disk will provide more I/O per second capacity)
Average Disk sec / read
Average Disk sec / write
Latency Measures disk latency. Numbers will vary, optimal
values for averages over time:
1 - 5 ms for Log (Ideally 1ms or better)
5 - 20 ms for Data (OLTP) (Ideally 10ms or
better)
8/19/2019 Performance SQL Server.pdf
65/81
Object Counter Value Notes
Physical Disk Avg DiskReads/sec
< 8> 20 is poor,
8/19/2019 Performance SQL Server.pdf
66/81
Object Counter Value Notes
:Access MethodsForwarded
Records/sec
8/19/2019 Performance SQL Server.pdf
67/81
8/19/2019 Performance SQL Server.pdf
68/81
• DON’T RUN SQL Profiler in the server.• Then what?
• Run SQL Profiler in your computer.
• Connect to the server.
• Indicate the events and columns wanted.
• Filter by the database to be evaluated.• Run the trace for 1 second, then stop it.
• Export the trace as script.
• Optimize the script.
• And then and only then, run the SQL Trace Script in the server.
• And to evaluate?• Use the fn_trace_gettable() function to query the content of the
SQL Trace file(s).
• You can use the SQL Trace file(s) with SQL Server – DatabaseEngine Tuning Advisor to evaluate for the creation of new indexes.
8/19/2019 Performance SQL Server.pdf
69/81
8/19/2019 Performance SQL Server.pdf
70/81
General event handlingGoal is to make available well-defined datain XML format from execution points in code
Baked into SQL Server codeLayers on top of Event Tracing for Windows
Used by• SQL Trace, Performance Monitor and SQL
Server Audit
• Windows Event Log or SQL Error Log
• As desired by users in admin or development
Introduced in SQL Server 2008
8/19/2019 Performance SQL Server.pdf
71/81
Superset of Extended EventsCan be used in conjunction
with Extended Events
Can be a consumer ortarget of Extended
Events
Kernel level facility
8/19/2019 Performance SQL Server.pdf
72/81
8/19/2019 Performance SQL Server.pdf
73/81
Built in set of objects in EXE or DLL (aka Module)SQL Server has three types of packages• Package0
• SQLServer
• SQLOSPackages one or more object types
Event Targets
Actions Types
Predicates Maps
8/19/2019 Performance SQL Server.pdf
74/81
Monitoring point of interest in code of amodule
Event firing implies:• Point of interest in code reached
• State information available at time event fired
Events defined statically in packageregistration
Versioned schema defines contentsSchema with well-defined data types
Event data always has columns in same order
Targets can pick columns to consume
8/19/2019 Performance SQL Server.pdf
75/81
Targets are event consumersTargets can
• Write to a file
• Aggregate event data
• Start a task/action that is related to anevent
Process data synchronously or
asynchronouslyEither file targets or In-memory targets
8/19/2019 Performance SQL Server.pdf
76/81
File Targets• Event File• ETW File
In-Memory Targets• Ring Buffer • Event Bucketing
• Event Pairing
• Synchronous Event Counting
8/19/2019 Performance SQL Server.pdf
77/81
Executed on top of events before event infostored in buffers (which may be later sent tostorage)
Currently used toGet additional data related to event
TSQL statement
User
TSQL process info
Generate a mini-dump
Defined in ADD/ALTER EVENT clause
8/19/2019 Performance SQL Server.pdf
78/81
Logical expression that gate event to firePred_Compare – operator for pair of values
Value Compare Value
Example: Severity < 16
Example: Error_Message = ‘Hello World!’
Pred_Source – generic data not usually inevent
Package.Pred_Source Compare ValueExample: SQLServer.user_name = ‘Chuck’
Example: SQLOs.CPU_ID = 0
Defined in ADD/ALTER EVENT clause
8/19/2019 Performance SQL Server.pdf
79/81
8/19/2019 Performance SQL Server.pdf
80/81
Real-time data capture
No performance penalty
Based on Event Tracing for Windows (ETW)Full programmability support
8/19/2019 Performance SQL Server.pdf
81/81
Packages
Events and Actions
Filters and PredicatesSessions
Targets