Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My experiences and references in SQL server
Browse by Tags · View All
SQL Server 14
#SQLServer 14
SQL Scripts 13
#TSQL 6
TSQL 6
SQL Serevr - Issues and Resolutions 3
SQL Server - Best Practises 3
SQL server - Misconceptions 3
SQL server - Statistics 2
SQL Server - Wait stats and Queues 2

Archive · View All
October 2011 8
March 2011 7
April 2011 4
May 2011 3
November 2011 3
December 2010 3
December 2011 2
June 2008 2
February 2011 2
February 2012 1

SQLZealot's Blog

Study of WAITSTATS(Part 2) - CMEMTHREAD

Oct 25 2011 2:08AM by Latheesh NK   

These wait types are indicative of a shortage of memory objects.This special type of wait occurs when a task is waiting for a thread-safe memory object. The wait time might increase when there is contention caused by multiple tasks trying to allocate memory from the same memory object.This wait type indicates that the rate of insertion of entries into the plan cache is very high and there is contention on the memory object.

A typical case is that the high usage of adhoc queries.Adhoc query execution creates separate plan for each parameter(if its not parameterized.)Here, the case is each entry will have to put in the procedure cache there by a case of bloating the cache.

As a first step, Lets have a look at the objects in the procedure cache:

SELECT objtype AS [CacheType]
        , count_big(*) AS [Total Plans]
        , sum(cast(size_in_bytes as decimal(12,2)))/1024/1024 AS [Total MBs]
        , avg(usecounts) AS [Avg Use Count]
        , sum(cast((CASE WHEN usecounts = 1 THEN size_in_bytes ELSE 0 END) as decimal(12,2)))/1024/1024 AS [Total MBs - USE Count 1]
        , sum(CASE WHEN usecounts = 1 THEN 1 ELSE 0 END) AS [Total Plans - USE Count 1]
FROM sys.dm_exec_cached_plans
GROUP BY objtype
ORDER BY [Total MBs - USE Count 1] DESC
go

The above query will give information how the cache been used for different cache types.Here lets have a close watch on the adhoc queries. How much size been occupied? How many single use plans are created? Whats the size of single use cached plan?

The above will give a good information how our system is being heavily used for adhoc execution.

Okei, now we will have to look at the adhoc plans created to understand the usage(find out the maximum memory used adho queries ordered by size in bytes):

SELECT TOP 500 *, TEXT
FROM sys.dm_exec_cached_plans 
CROSS APPLY sys.dm_exec_sql_text(plan_handle) 
WHERE cacheobjtype ='Compiled Plan' and objtype not in ('proc','trigger') 
--and text like 'SELECT DISTINCT vw.request_code%'
oRDER BY SIZE_IN_BYTES DESC , Usecounts asc

I wonder on the number,you may check in your database the above query to see the number of adhoc plans created with its usecounts. If there are many adhoc queries with single usecounts, do you really wanna be stored in the plan? Why cant we have a parameterized query instead of creating single plan there?

There are few options to avoid/restrict the single usecount plan created in the procedure cache.

1. Avoid dynamic queries from the fornt end as possible as.
2. In certain case where we cant avoid dynamic queries, Try to use sp_executeSQL for dynamic queries.
3. Turn on Optimize for Ad hoc Workloads (Optimize for adhoc will never save the cache plan until it is been used for the second time. First time, it saves only the plan stub in the memeory.Second time execution, it uses the same plan stub and save the cached plan in the memeory.To me this is a very good option that we can think of.)

There would be also an issue of CMEMTHREAD wait type associated with Token and Perm User Store which am not going to cover here. But worthy look at!!!

I would like to hear from you any special cases you have come across and share the knowledge out of it!!!


Republished from SQL - My Best Friend [58 clicks].  Read the original version here [32134 clicks].

Latheesh NK
55 · 3% · 1115
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Study of WAITSTATS(Part 2) - CMEMTHREAD" rated 5 out of 5 by 1 readers
Study of WAITSTATS(Part 2) - CMEMTHREAD , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]