Plan Cache Performance

  • Hi All

    I'm using the below query to investigate plan re-use on my SQL Server

    How accurate are the counters used here?

    Has anyone worked with this query or something similar

    select t1.cntr_value As [Batch Requests/sec],

    t2.cntr_value As [SQL Compilations/sec],

    plan_reuse =

    convert(decimal(15,2),

    (t1.cntr_value*1.0-t2.cntr_value*1.0)/t1.cntr_value*100)

    from

    master.sys.dm_os_performance_counters t1,

    master.sys.dm_os_performance_counters t2

    where

    t1.counter_name='Batch Requests/sec' and

    t2.counter_name='SQL Compilations/sec'

    Thanks

  • Those are valid counters and will show how your system is behaving. They're the same counters you get from running Performance Monitor. You can also look at sys.dm_exec_query_stats to see aggregate information about the queries that are in cache, including how many times they've been used.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Initial Compilation='SQL Compilations/sec'-'SQL ReCompilations/sec'

    plan reuse= ( 'Batch Requests/sec' - 'Initial Compilation')/'Batch Requests/sec'

    this one is more accurate

    Pooyan

  • Grant Fritchey (9/14/2012)


    Those are valid counters and will show how your system is behaving. They're the same counters you get from running Performance Monitor. You can also look at sys.dm_exec_query_stats to see aggregate information about the queries that are in cache, including how many times they've been used.

    Thanks

    Is there a way I can tell whether or not my Cache is bloated and under pressure?

    Thanks

  • pooyan_pdm (9/14/2012)


    Initial Compilation='SQL Compilations/sec'-'SQL ReCompilations/sec'

    plan reuse= ( 'Batch Requests/sec' - 'Initial Compilation')/'Batch Requests/sec'

    this one is more accurate

    Thanks

    How do I incorporate this into the script?

    I keep getting this error

    Operand data type varchar is invalid for subtract operator.

    Thanks

  • You should use the actual counter values from the sys.dm_os_performance counters for the three mentioned counters and for checking wheather the cache is bloating or not you can check the sum of size column from sys.dm_exec_cached_plans where objtype in('prepared','adhoc') and usecount=1 this shows the size of the all adhoc plans that just were used once and cause the cache to bloat.if the size of these plans are considerable you can turn on the 'optimize for adhoc workloads' database option .

    Pooyan

  • pooyan_pdm (9/17/2012)


    You should use the actual counter values from the sys.dm_os_performance counters for the three mentioned counters and for checking wheather the cache is bloating or not you can check the sum of size column from sys.dm_exec_cached_plans where objtype in('prepared','adhoc') and usecount=1 this shows the size of the all adhoc plans that just were used once and cause the cache to bloat.if the size of these plans are considerable you can turn on the 'optimize for adhoc workloads' database option .

    Something like this

    SELECT SUM(size_in_bytes)/1024

    FROM sys.dm_exec_cached_plans AS cp

    where objtype in('prepared','adhoc') and usecounts = 1

    Is this accurate for Megabytes?

    Thanks

  • SQLSACT (9/17/2012)


    Grant Fritchey (9/14/2012)


    Those are valid counters and will show how your system is behaving. They're the same counters you get from running Performance Monitor. You can also look at sys.dm_exec_query_stats to see aggregate information about the queries that are in cache, including how many times they've been used.

    Thanks

    Is there a way I can tell whether or not my Cache is bloated and under pressure?

    Thanks

    Bloated? Not really. Under pressure. Yes. Look at compiles and recompiles. Compare them over time, especially between high volume & low volume times. If you're seeing lots of turnover on the plans, your cache is under pressure.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant Fritchey (9/17/2012)


    SQLSACT (9/17/2012)


    Grant Fritchey (9/14/2012)


    Those are valid counters and will show how your system is behaving. They're the same counters you get from running Performance Monitor. You can also look at sys.dm_exec_query_stats to see aggregate information about the queries that are in cache, including how many times they've been used.

    Thanks

    Is there a way I can tell whether or not my Cache is bloated and under pressure?

    Thanks

    Bloated? Not really. Under pressure. Yes. Look at compiles and recompiles. Compare them over time, especially between high volume & low volume times. If you're seeing lots of turnover on the plans, your cache is under pressure.

    Thanks

  • Grant Fritchey (9/17/2012)


    SQLSACT (9/17/2012)


    Grant Fritchey (9/14/2012)


    Those are valid counters and will show how your system is behaving. They're the same counters you get from running Performance Monitor. You can also look at sys.dm_exec_query_stats to see aggregate information about the queries that are in cache, including how many times they've been used.

    Thanks

    Is there a way I can tell whether or not my Cache is bloated and under pressure?

    Thanks

    Bloated? Not really. Under pressure. Yes. Look at compiles and recompiles. Compare them over time, especially between high volume & low volume times. If you're seeing lots of turnover on the plans, your cache is under pressure.

    Thanks

    Would the following be a fair assessment of how volatile my cache is?

    select top 1 last_execution_time from sys.dm_exec_query_stats

    order by last_execution_time

    Thanks

  • SQLSACT (9/17/2012)


    Grant Fritchey (9/17/2012)


    SQLSACT (9/17/2012)


    Grant Fritchey (9/14/2012)


    Those are valid counters and will show how your system is behaving. They're the same counters you get from running Performance Monitor. You can also look at sys.dm_exec_query_stats to see aggregate information about the queries that are in cache, including how many times they've been used.

    Thanks

    Is there a way I can tell whether or not my Cache is bloated and under pressure?

    Thanks

    Bloated? Not really. Under pressure. Yes. Look at compiles and recompiles. Compare them over time, especially between high volume & low volume times. If you're seeing lots of turnover on the plans, your cache is under pressure.

    Thanks

    Would the following be a fair assessment of how volatile my cache is?

    select top 1 last_execution_time from sys.dm_exec_query_stats

    order by last_execution_time

    Thanks

    Nope, that just says the last time a query was executed in the cache. You could look at the create dates in the cache to get an idea of the age of the plans. That's something of an indicator, but only a very general one.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant Fritchey (9/17/2012)


    SQLSACT (9/17/2012)


    Grant Fritchey (9/17/2012)


    SQLSACT (9/17/2012)


    Grant Fritchey (9/14/2012)


    Those are valid counters and will show how your system is behaving. They're the same counters you get from running Performance Monitor. You can also look at sys.dm_exec_query_stats to see aggregate information about the queries that are in cache, including how many times they've been used.

    Thanks

    Is there a way I can tell whether or not my Cache is bloated and under pressure?

    Thanks

    Bloated? Not really. Under pressure. Yes. Look at compiles and recompiles. Compare them over time, especially between high volume & low volume times. If you're seeing lots of turnover on the plans, your cache is under pressure.

    Thanks

    Would the following be a fair assessment of how volatile my cache is?

    select top 1 last_execution_time from sys.dm_exec_query_stats

    order by last_execution_time

    Thanks

    Nope, that just says the last time a query was executed in the cache. You could look at the create dates in the cache to get an idea of the age of the plans. That's something of an indicator, but only a very general one.

    Thanks

    You could look at the create dates in the cache

    Is this the creation_date in the sys.dm_exec_query_stats DMV ?

    Thanks

  • Yes

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • SQLSACT (9/17/2012)


    pooyan_pdm (9/17/2012)


    You should use the actual counter values from the sys.dm_os_performance counters for the three mentioned counters and for checking wheather the cache is bloating or not you can check the sum of size column from sys.dm_exec_cached_plans where objtype in('prepared','adhoc') and usecount=1 this shows the size of the all adhoc plans that just were used once and cause the cache to bloat.if the size of these plans are considerable you can turn on the 'optimize for adhoc workloads' database option .

    Something like this

    SELECT SUM(size_in_bytes)/1024

    FROM sys.dm_exec_cached_plans AS cp

    where objtype in('prepared','adhoc') and usecounts = 1

    Is this accurate for Megabytes?

    Thanks

    . That gives u the size in KB you should devide it again by 1024

    Pooyan

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply