Boost SQL Server Performance Buffer Pool Extensions & Delayed Durability Manohar Punna President - SQLServerGeeks #509 Brisbane 2016
Agenda SQL Server Memory Buffer Pool Extensions Delayed Durability Analysis - DD with SSDs Dependencies Summary
SQL Server - Reserve Memory VAS Reservation aka MTL Memory To Leave 32 bit MTL = (MaxWorkerThreads * StackSize) + DefaultReservationSize MaxWorkerThreads = ((#Schedulers 4) * 8) + BaseThreadCount StackSize = 512 KB, DefaultReservationSize = 256 MB BaseThreadCount = 256 64 bit MaxWorkerThreads = ((#Schedulers 4) * 16) + BaseThreadCount StackSize = 2048 KB, BaseReservationSize = 256 MB BaseThreadCount = 512 64 bit version has enough VAS No Reservation. Windows Server 2012 R2, Windows 8.1 supports 256 TB of VAS. Let me show
SQL Server Memory Starts with minimum required memory. Grows beyond Min Server Memory Does not release this space Grows up to Max Server Memory Can be trimmed when OS under memory pressure Memory allocations outside Max Server Memory Thread stack, Extended Procedures etc. From SQL 2012 all pages (Large and multi) are done in Buffer Pool. Move to 64 bit NOW AWE is deprecated MTL is not needed
SQL Server More complicated SQL Server 2014 and beyond In-Memory OLTP Buffer Pool Extension Delayed Durability
SQL Server Buffer Pool SQL Server is memory intensive application Works on data Hot dirty pages - small random IOs to disk Physical I/O has limitations Memory has limitations Everyone doesn t have a fortune
BPE Buffer Pool Extension Expand the Buffer Pool cache to nonvolatile storage (usually SSDs) Larger database working set Force paging of IO between RAM and SSDs Offload small random IOs from mechanical disk to SSDs. Significantly improves IO performance. Increased Random IO throughput Reduced IO latency Increased Transaction throughput
BPE Buffer Pool Extension Ref: MSDN
BPE Buffer Pool Extension Can be 32 times of the Max Server Memory Microsoft recommends 1:16 ratio between physical memory and BPE 1:4 or 1:8 may be optimal. Test before you implement in production. Tracking: DMVs: sys.dm_os_buffer_pool_extension sys.dm_os_buffer_descriptors (is_in_bpool_extension) ExtendedEvents: sqlserver.buffer_pool_extension_pages_evicted sqlserver.buffer_pool_extension_pages_read sqlserver.buffer_pool_extension_pages_written sqlserver.buffer_pool_eviction_thresholds_recalculated
DEMO Buffer Pool Extension Configure Test Results
BPE Points to Remember Works best for OLTP workloads, not for OLAP. Feature available only in 64 bit. SQL Server 2014 Standard, BI and Enterprise editions. Altering BPE configuration needs disable and enable the feature. BPE value once set cannot be reduced without restart. Your responsibility to check performance of disk subsystem used for BPE.
All the best with BPE Delayed Durability Let us first thank Jim Grey Image curtesy: Computerworld.com
A C I Durability? W A L Write Ahead Logging Transaction Commit Write Log Client Ack to client Server Write Ack Storage Achieved by logging transactions to disk before commit Committed data will never be lost during server crash Log backups, HA (Replication, Log shipping) have high guarantee of sync
Log Manager Log Buffer (128*60KB = 7.5 MB) Log Manager Asynchronous Log flush COMMIT or ABORT 60 KB of log records IO Requests (512 bytes up to 60KB)
Log Manager Outstanding IO Size limit Prior to 2008: 480 KB SQL Server 2008 and above: 3840 KB Outstanding IO limit: Prior to 2005 SP1: 8 outstanding IOs SQL Server 2005-2008: x86-8 outstanding IOs, x64-32 outstanding IOs SQL Server 2012 and above: 112 outstanding IOs
Demo Log Manager
Delaying the D Delayed Durability Delaying the log writes asynchronous transactions Reduces both latency and contention Control is returned to client skipping Log IO Less log IO contention Increased throughput
Demo Delayed-Durability
What is the Cost? Transaction Commit Write Log Ack to client Write Ack Client Server Storage No Pain, No Gain Data durability is not guaranteed Transactions committed can be lost during a crash or server shutdown Log dependent features are not synchronous Replication, Log shipping, etc.
Use Cases and Feasibility Tolerate some data loss High wait times for WRITELOG wait type Workloads having high contention rate Loads of blocking due to heavy concurrent processing Queries taking longer time waiting on WRITELOG and holding locks on resources for longer duration
Controlling Delayed Durability Database Level ALTER DATABASE SET DELAYED_DURABILITY = DISABLED (Default) Cannot enable Delayed Durability ALLOWED Can be controlled at Transaction Level FORCED Forced and overrides any Transaction level option Atomic Block Level Natively Compiled Stored Procedures CREATE PROCEDURE <ProcName> WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER AS BEGIN ATOMIC WITH ( DELAYED_DURABILITY = ON OFF ) Commit Level Transact-SQL COMMIT TRAN <tranname> WITH DELAYED_DURABILITY = OFF ON
BONUS - Loopholes Log buffer is flushed into disk periodically when the buffer limit is hit Can we control it... Yes How? By forcing a transaction log flush Execute a fully durable transaction that will flush the log buffer to the disk Database level delayed durability setting overrides transaction level durable transaction Cross Database or Distributed transactions are always Durable sp_flush_log Forces all committed delayed durable transaction log records to disk
Demo Delayed-Durability with SSDs
Analysis DD on SSDs Small Transactions Large Transactions HDD More writes More io_stalls High duration Less writes More io_stalls Moderate duration Moderate writes More io_stalls Moderate duration Moderate writes More io_stalls Moderate duration SSD More writes Less io_stalls Moderate duration Less writes Less io_stalls Low duration Moderate writes Less io_stalls Moderate duration Moderate writes Less io_stalls Moderate duration Delayed Durability Disabled Enabled Disabled Enabled
Analysis DD on SSDs Small Transactions Large Transactions HDD SSD More writes More io_stalls High duration IO_Stalls More writes Less io_stalls Moderate duration Writes Less writes More io_stalls Moderate duration Less writes Less io_stalls Low duration Moderate writes More io_stalls Moderate duration IO_Stalls Writes Moderate writes Less io_stalls Moderate duration Moderate writes More io_stalls Moderate duration Moderate writes Less io_stalls Moderate duration Delayed Durability Disabled Enabled Disabled Enabled
Dependencies Data loss Crash recovery, Restart and Failover Clustering Replication, Log Shipping and Log Backups Always-ON Secondaries not in Sync in Synchronous mode No Effect Change Tracking and Change Data Capture are fully durable Cross-database transactions and Distributed transactions are fully durable
Summary SQL Server has improved, expanded and improving its Memory. With 2014 more new features added BPE Buffer Pool Extension and Delayed Durability Increased IO performance with increased buffer pool to faster nonvolatile storage A C I Durability WAL Improved performance at a cost Controlling Delayed Durability DD with SSDs Dependencies of other features
Questions Please make sure you visit our fantastic sponsors. #509 Brisbane 2016
Thank You @ManuSQLGeek #sqlsat509 #509 SQL Saturday Brisbane #509 2016 Brisbane 2016