Presentation is loading. Please wait.

Presentation is loading. Please wait.

MICROSOFT SQL SERVER DATABASE ENGINE I/O by Bob Dorr, Microsoft SQL Server Principle Escalation Engineer, 1994 – Present Built: Jan 2008.

Similar presentations


Presentation on theme: "MICROSOFT SQL SERVER DATABASE ENGINE I/O by Bob Dorr, Microsoft SQL Server Principle Escalation Engineer, 1994 – Present Built: Jan 2008."— Presentation transcript:

1 MICROSOFT SQL SERVER DATABASE ENGINE I/O by Bob Dorr, Microsoft SQL Server Principle Escalation Engineer, 1994 – Present Built: Jan 2008

2 Areas Covered  Write Ahead Logging (WAL) Protocol  Synchronous vs Asynchronous I/O  Scatter / Gather I/O  Sector alignment, Block Alignment  Latching and a page: A read walk-through  SQL Server I/O Sizes  Data cache maintenance  PAE and AWE  Read Ahead  User Mode and Kernel Mode (SYSTRAP)  Sparse Files and Copy On Write (COW) Pages  Locked Pages  Scribbler(s) and Bit flips  Page Protection and Constant Pages  Checksum vs Torn  Stale Read  Stalled I/O

3 WAL Protocol  Write Ahead Logging  ACID (Durability Property)  Log records secured before data  Hardened / Stable Media  Log contains parity bit Commit Rollback Trigger Snapshot

4 Synchronous vs Asynchronous I/O  Sync: Wait for Completion  Async: Post and Continue  Overlapped  Event  Completion Port  SQL Server  98% Async Usage Overlapped and HasOverlappedIoCompleted Network Layers Use Completion Port  Backup/Restore Use Sync – Sequential Patterns dm_io_pending_io_requests Overlapped Structure Async Processing ~= CPU Package vs Phone

5 Scatter / Gather I/O  Consolidates or Distributes  APIs  ReadFileScatter  WriteFileGather  Increases Efficiency  Used by SQL I/O Paths  Used by Windows Page File Old Design: 6.x Sorting AWE Availability WriteMultiple # of 8K Pages Forward and Backward Buffer Pool Ramp-up Disk Memory GatherScatter

6 Sector Alignment Block Alignment  Sector: Log Writes  Block: Performance  Avoid Crossovers  DiskPart/DiskPar Utilities  Discuss with your Vendor Double Touch Rewrites Defragment 4K Sectors Alignment: To verify that an existing partition is aligned, divide the size of the stripe unit by the starting offset of the RAID disk group. Use the following syntax: ((Partition offset) * (Disk sector size)) / (Stripe unit size) Example of alignment calculations in bytes for a 256-KB stripe unit size: (63 * 512) / = (64 * 512) / = (128 * 512) / = 0.25 (256 * 512) / = 0.5 (512 * 512) / = 1 These examples shows that the partition is not aligned correctly for a 256-KB stripe unit size until the partition is created by using an offset of 512 sectors (512 bytes per sector).

7 Latch  Multiple Readers (SH)  One Writer (EX)  Protects In-Memory Data Page  Latch = Physical Protection  Lock = Logical Protection  User Mode  UMS/SQLOS Aware  Optimized FIFO Ordering Flushed & Rollback Latch Timeout Sub-latch BUF Array Memory (Data Pages) BUF Status Latch Database* PageId Hash * … BUF Status Latch Database* PageId Hash * …

8 Reading A Page  Get Free Buffer for Read  Acquire Exclusive (EX) Latch  Is already in-memory/hashed?  Add Entry to Page Hash  Post and Record Asynchronous Read  … Continue Processing ….  Check Status (Scheduler Switch)  Complete: Validate I/O and Release Latch Page Audits Read retry Stalled I/O Warnings Error raised at Acquire Shared (SH) waiters PAGE_IO* vs PAGE* Latch Writing A Page kernel transition – Stuck I/O? ntdll!ZwWriteFile+0xa kernel32!WriteFile+0xf6 sqlservr!DiskWriteAsync+0xee … 0:000> uf ZwWriteFile mov r10,rcx mov eax,5 Syscall  Kernel Transition ret 0:000> uf ZwWriteFile mov r10,rcx mov eax,5 Syscall  Kernel Transition ret

9 Myth: Single Worker Per File Truth: Each Worker Issues I/O Vol #1 Vol #2 Serial Plan select * from dbTest.dbo.tblTest insert into dbTest.dbo.tblTest dbTest.MDF dbTest.NDF dbTest.LDF Parallel Plan select * from dbTest.dbo.tblTest insert into dbTest.dbo.tblTest Create Database Workers Assigned by Volume ID Primary = dbTest.MDF Secondary = dbTest.NDF Log = dbTest.LDF

10 Data Cache Maintenance  Memory Pressure: LazyWriter  Per NUMA Node  Time Of Last Access (TLA)  Recovery Interval: Checkpoint  Queue  I/O Targets .LDF Usage Triggers  Alternate Triggers (Backup, Restore, …)  Scatter/Gather Usage (WriteMultiple) Checkpoint Assignments By Ordinal Sweep Stalled I/O – LW #0 I/O Queue Depth > 2

11 PAE and AWE  Physical Address Extensions  /PAE in Boot.ini  Boots Kernel with 36 bit addressing  Physical Memory > 4GB  Virtual Address Unchanged (/2gb or /3GB)  Automatic for Hot Add Memory Computers  Address Windows Extension  Windows APIs (AllocateUserPhysicalPages)  Physical Memory Allocations  Un/Mapped in or out of Virtual Address Range Data Pages-Only Locked Pages Windows Paging Windows 2000 Bugs 32 Bit Address = (0xFFFFFFFF) 4GB Interlocked Instruction lock xadd dword ptr [ecx],eax 36 Bit Address = (0xFFFFFFFFF) 64GB Multiple Instructions

12 Read Ahead  128 Pages Standard SKU  1024 Pages Enterprise SKU  Uses ReadFileScatter  Plan Based Decisions  Power of Asynchronous I/O Read Over Write Ramp-up

13 Sparse Files – Copy On Write  Usage  Online DBCC  Snapshot Databases  Buffer Pool: PrepareToDirty  File Control Block (FCB) Chaining Sparse Allocation FCB Tracking Windows Limits New Page Allocations

14 Advanced Protection  What is a Scribbler?  Data Page Audits  None  Torn Bits  Checksum  Log Block Checksum  Constant Page  Backup with Checksum DBCC Page Audit Stale Read Check SQLIOSim

15 REFERENCES

16 Overview  SQL Server Always On  SQL Server I/O Basics Chapter 1 /sql/2000/maintain/sqlIObasics.mspx /sql/2000/maintain/sqlIObasics.mspx  SQL Server I/O Basics Chapter 2 /sql/2005/iobasics.mspx /sql/2005/iobasics.mspx

17 Fundamentals and Requirements  KB SQL Server 7.0, SQL Server 2000 and SQL Server 2005 logging and data storage algorithms extend data reliabilitySQL Server 7.0, SQL Server 2000 and SQL Server 2005 logging and data storage algorithms extend data reliability  KB Microsoft SQL Server I/O subsystem requirements for the tempdb databaseMicrosoft SQL Server I/O subsystem requirements for the tempdb database  KB SQL Server databases not supported on compressed volumes (except 2005 read only files)SQL Server databases not supported on compressed volumes

18 Subsystems  KB Key factors to consider when evaluating third- party file cache systems with SQL ServerKey factors to consider when evaluating third- party file cache systems with SQL Server  KB Using disk drive caching with SQL ServerUsing disk drive caching with SQL Server  KB Using hard disk controller caching with SQL ServerUsing hard disk controller caching with SQL Server  KB Description of caching disk controls in SQL ServerDescription of caching disk controls in SQL Server  KB Description of support for network database files in SQL ServerDescription of support for network database files in SQL Server  KB (in progress) - Support for third-party Remote Mirroring solutions used with SQL Server 2000 and 2005Support for third-party Remote Mirroring solutions used with SQL Server 2000 and 2005  KB Support for SQL Server 2000 on iSCSI technology components (applies to SQL Server 2005)Support for SQL Server 2000 on iSCSI technology components

19 Design and Configuration  White paper - Physical Database Layout and DesignPhysical Database Layout and Design  KB Understanding How to Set the SQL Server I/O Affinity OptionUnderstanding How to Set the SQL Server I/O Affinity Option  KB When Dirty Cache Pages are Flushed to DiskWhen Dirty Cache Pages are Flushed to Disk  White paper - Database Mirroring in SQL Server 2005Database Mirroring in SQL Server 2005  White paper - Database Mirroring Best Practices and Performance ConsiderationsDatabase Mirroring Best Practices and Performance Considerations  KB Scalable shared database are supported by SQL Server 2005Scalable shared database are supported by SQL Server 2005  MSDN article - Read-Only FilegroupsRead-Only Filegroups  KB Asynchronous Disk I/O Appears as Synchronous on Windows NT, Windows 2000, and Windows XPAsynchronous Disk I/O Appears as Synchronous on Windows NT, Windows 2000, and Windows XP

20 Diagnostics  KB Additional SQL Server Diagnostics Added to Detect Unreported I/O ProblemsAdditional SQL Server Diagnostics Added to Detect Unreported I/O Problems  KB SQL Server 2000 SP4 diagnostics help detect stalled and stuck I/O operations (applies to SQL Server 2005)SQL Server 2000 SP4 diagnostics help detect stalled and stuck I/O operations  KB Error message 823 may indicate hardware problems or system problems in SQL ServerError message 823 may indicate hardware problems or system problems in SQL Server  KB Understanding Bufwait and Writelog Timeout MessagesUnderstanding Bufwait and Writelog Timeout Messages  KB Use Trace Flag 3505 to Control SQL Server Checkpoint BehaviorUse Trace Flag 3505 to Control SQL Server Checkpoint Behavior  KB Checkpoint resumes behavior that it exhibited before you installed SQL Server 2000 SP3 when you enable trace flag 828Checkpoint resumes behavior that it exhibited before you installed SQL Server 2000 SP3 when you enable trace flag 828  WebCast- Data Recovery in SQL Server 2005Data Recovery in SQL Server 2005

21 Certification Policy  KB Microsoft does not certify that third-party products will work with Microsoft SQL ServerMicrosoft does not certify that third-party products will work with Microsoft SQL Server  KB Overview of the Microsoft third- party storage software solutions support policyOverview of the Microsoft third- party storage software solutions support policy  KB How to use the SQLIOStress utility to stress a disk subsystem such as SQL ServerHow to use the SQLIOStress utility to stress a disk subsystem such as SQL Server

22 Utilities  Download - SQLIO Disk Subsystem Benchmark ToolSQLIO Disk Subsystem Benchmark Tool  Download - SQLIOStress utility to stress disk subsystem (applies to SQL Server 7.0, 2000, and replaced with SQLIOSim and SQL Server 2008 installed in BINN)SQLIOStress utility to stress disk subsystem

23 Blog Content  SQL Server Urban Legends Discussed  How It Works: SQL Server Checkpoint (FlushCache) Outstanding I/O Target  How It Works: SQL Server Page Allocations  How It Works: Shapshot Database (Replica) Dirty Page Copy Behavior (NewPage)  How It Works: SQL Server 2005 I/O Affinity and NUMA Don't Always Mix  How It Works: Debugging SQL Server Stalled or Stuck I/O Problems - Root Cause  How It Works: SQL Server 2005 Database Snapshots (Replica)  How It Works: File Stream the Before and After Image of a File  Using SQLIOSim to Diagnose SQL Server Reported Checksum (Error 824/823) Failures  How to use the SQLIOSim utility to simulate SQL Server activity on a disk subsystem  Should I run SQLIOSim? - An follow-up from SQL PASS  What do I need to know about SQL Server database engine I/O?  SQLIOSim is "NOT" an I/O Performance Tuning Tool  How It Works: SQLIOSim - Running Average, Target Duration, Discarded Buffers...  How It Works: SQLIOSim [Audit Users] and.INI Control File Sections with User Count Options  Understanding SQLIOSIM Output

24 Additional Learning Resources  Inside SQL Server 7.0 and Inside SQL Server 2000 Written by Kalen Delaney – her husband is Paul Randle who wrote the core dbcc checks for SQL 7.0, 2000 and 2005  The Guru’s Guide to SQL Server Architecture and Internals – ISBN Written by Ken after he joined Microsoft SQL Server Support Many chapters reviewed by developers and folks like myself  SQL Server 2005 Practical Troubleshooting ISBN – Ken Henderson Authors of this book were key developers or support team members Cesar – QP developer and leader of the QP RedZone with Keithelm and Jackli Sameert – Developer of UMS and SQLOS Scheduler Santeriv – Developer of the lock manager Slavao – Developer of the SOS memory managers and engine architect Wei Xiao – Engine developer Bart Duncan – long time SQL EE and now developer of the Microsoft Data Warehouse – performance focused Bob Ward – SQL Server Support Senior EE  Advanced Windows Debugging – ISBN Written by Microsoft developers – excellent resource  Applications for Windows – Jeffrey Richter Great details about Windows basics


Download ppt "MICROSOFT SQL SERVER DATABASE ENGINE I/O by Bob Dorr, Microsoft SQL Server Principle Escalation Engineer, 1994 – Present Built: Jan 2008."

Similar presentations


Ads by Google