A deep dive into SQL Server Plan Cache Management.

Slides:



Advertisements
Similar presentations
SAP Memory Management (an Overview)
Advertisements

Paging: Design Issues. Readings r Silbershatz et al: ,
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Virtual Memory Operating System Concepts chapter 9 CS 355
15 Copyright © 2004, Oracle. All rights reserved. Monitoring and Managing Memory.
1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Paging Design.
1 - Oracle Server Architecture Overview
Memory Management 2010.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Process Description and Control A process is sometimes called a task, it is a program in execution.
Module 8: Monitoring SQL Server for Performance. Overview Why to Monitor SQL Server Performance Monitoring and Tuning Tools for Monitoring SQL Server.
Module 8: Server Management. Overview Server-level and instance-level resources such as memory and processes Database-level resources such as logical.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Lecture 11: DMBS Internals
2 Avoiding Stored Procedure Recompiles Dr Greg Low Managing Director Solid Q Australia Session Code: DAT454.
Some VM Complications Extra memory accesses Page tables are huge
Module 10: Monitoring ISA Server Overview Monitoring Overview Configuring Alerts Configuring Session Monitoring Configuring Logging Configuring.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Chapter 4 Memory Management Virtual Memory.
The Self-Managing Database: Automatic SGA Memory Management Tirthankar Lahiri Senior Manager, Distributed Cache & Memory Management Oracle Corporation.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
DMBS Internals I. What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the database concurrently.
Virtual Memory 1 1.
Memory Hierarchy Adaptivity An Architectural Perspective Alex Veidenbaum AMRM Project sponsored by DARPA/ITO.
SQL Server Memory Architecture Sumit Sarabhai Microsoft Corp.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
20 Copyright © 2008, Oracle. All rights reserved. Cache Management.
TOP 10 Thinks you shouldn’t do with/in your database
DMBS Internals I February 24 th, What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the.
DMBS Internals I. What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the database concurrently.
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
Maciej Pilecki Consultant Project Botticelli Ltd. DAT404.
Connect with life Praveen Srivatsa Founder and CEO – AstraSoft.NET Vinod Kumar Technology Evangelist – Databases and BI.
Query Performance Tuning in SQL Server 2014 #devconnections.
Execution Plans for Mere Mortals A beginners look at execution plans. Mike Lawell, Teammate, Linchpin People.
What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the database concurrently and safely. Provide.
Improve query performance with the new SQL Server 2016 query store!! Michelle Gutzait Principal Consultant at
This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information.
Database Forensics Paresh Motiwala - SQL Solutions Architect at
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
Are You There, DBA? It’s Me, The App Developer.
Stored Procedures – Facts and Myths
Lecture 16: Data Storage Wednesday, November 6, 2006.
FileSystems.
Things You Can Find in the Plan Cache.
Dynamic Hashing (Chapter 12)
Microsoft Dumps Question Answer - Dumps4download
Lecture 11: DMBS Internals
Capriccio – A Thread Model
Configuring SQL Server
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Predictive Performance
Page Replacement.
Configuring SQL Server
Translation Buffers (TLB’s)
Last section! Project 4 + EC due tomorrow Today: Project 4 questions
CSE451 - Section 10.
COMP755 Advanced Operating Systems
Inside the Database Engine
Inside the Database Engine
Virtual Memory 1 1.
Inside the Database Engine
Presentation transcript:

A deep dive into SQL Server Plan Cache Management

 Decrease in throughput or an increase in query response time  Out-of-memory errors or connection timeout errors  Query executions and/or query compiles timeout errors  WAITs  CMEMTHREAD wait type  RESOURCE_SEMAPHORE_QUERY_COMPILE  High CPU usage in SQL Server 2012 or 2014 due to plan cache contention  This is a result of  Large number of memory pressure events  Memory contention  Large number of compilations

 The plan cache is used to save all the execution plans in case they can be reused  Plan caching enables SQL Server to reuse plans to avoid recompilation  The total size of memory is dynamic by default, and the space used for query plans is also very fluid Plan Cache

The content of the plan cache, cache object types and caching mechanisms

 4 stores contain query plans:  Object Plans (CACHESTORE_OBJCP)  SQL Plans (CACHESTORE_SQLCP)  Bound Trees (CACHESTORE_PHDR)  Extended Stored Procedures (CACHESTORE_XPROC)  Stores and their sizes  sys.dm_os_memory_objects  sys.dm_exec_cached_plans  sys.dm_os_memory_cache_counters 6

 Determining the Cache Store Pressure Limit value SQL Server 2005 SP1 on a 64-bit SQL Server 28 GB TM The single cache store pressure limit:(75% of 8 GB) + (50% of 20GB) = 6GB + 10GB =16 GB SQL Server 2012 RTM 64-bit with 28 GB TM The single cache store pressure limit : (75% of 4 GB) + (10% of 24 GB)= 3GB + 2.4GB = 5.4 GB

 Local  When any single cache store grows too big  A cache store reaches 62.5 percent of it’s cache store pressure limit value  Global  External global pressure (from OS)  Internal global memory pressure can occur  when virtual address space is low  when the memory broker predicts that all cache stores combined will use more than 80 percent of the plan cache pressure limit SQL Server 2012 RTM 64-bit with 28 GB TM Internal Memory Pressure Event triggers at: 62.5% of The plan cache pressure limit =62.5%*5.4 GB=3.375GB. SQL Server 2012 RTM 64-bit with 28 GB TM The single cache store pressure limit : 5.4 GB Internal memory pressure is triggered at: 62.5*5.4GB=3.375GB

 Eviction policy Algorithm  zero-cost plans are removed from cache  the cost of all other plans is reduced by half  One cycle updates the cost of at most 16 entries for every cache store  Costing of cache entries  Adhoc plans  cost is considered to be zero, increased by 1 every time the plan is reused  Non-adhoc queries  based on three factors: I/O, context switches, and memory  On plan re-use the cost is reset to the original cost

Detecting memory pressure

 The number of plans in a store exceeds four times the hash table size for that store, regardless of the actual size of the plans - 160,036 plans in a specific cache store  Heavy contention for the SOS_CACHESTORE spinlock and high CPU usage on SQL Server 2012/2014  Resolution  Apply hotfix  Fixed in SQL Server 2012 SP1 CU 14  Fixed in SQL Server 2014 CU 6  To apply the change: -T174  Optimize for AdHoc=True  Also: -T8032 (be careful) - Reverts the cache limit parameters to the SQL Server 2005 RTM setting

 SQL Server: Plan Cache/Cache Pages(_Total)  SQLServer: BufferManager/Database pages  Detecting excessive compiles and recompiles:  SQL Statistics\SQL Compilations/sec  SQL Statistics\SQL Re-Compilations/sec  Memory Manager\Target Server Memory (KB)  Memory Manager\Total Server Memory (KB)

 Always specify Optimize for AdHoc=true  Always configure MAX SERVER MEMORY Setting  Monitor the size and usage of your plan cache  Know your thresholds  Check for wasted space amount on a regular basis  Be aware of some situations that cause multiple query plans for the same procedure to be saved in cache  A difference in certain SET options  A need to go trough the implicit name resolution process

 Apply CU and fixes for SQL Server 2012/2014 if you encounter high CPU due to spinlock contention problems  Apply –T8032 only after careful analysis, monitor the buffer pool after that  Sometimes periodically cleaning the Adhoc plan cache could work better if the problem is located in SQLPlans cache store  DBCC FREESYSTEMCACHE('SQL Plans') for usecount=1 and objtype IN ('Adhoc', 'Prepared')  Change the application (Yes, I know )

Questions?   

Explore Everything PASS Has to Offer Free SQL Server and BI Web Events Free 1-day Training Events Regional Event Local User Groups Around the World Free Online Technical Training This is CommunityBusiness Analytics Training Session Recordings PASS Newsletter