Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Backup and copy warm-standby (log shipped) databases in SQL ServerUse alter table alter column to change datatypes for a column in SQL Server »
    comments

    In order to figure out if you need more memory for a SQL Server you can start by taking a look at Buffer cache hit ratio and Page life expectancy.

    Buffer cache hit ratio

    Here is what Books On Line has to say about Buffer cache hit ratio
    Buffer cache hit ratio
    Percentage of pages found in the buffer cache without having to read from disk. The ratio is the total number of cache hits divided by the total number of cache lookups over the last few thousand page accesses. After a long period of time, the ratio moves very little. Because reading from the cache is much less expensive than reading from disk, you want this ratio to be high. Generally, you can increase the buffer cache hit ratio by increasing the amount of memory available to SQL Server.

    Basically what this means is what is the percentage that SQL Server had the data in cache and did not have to read the data from disk. Ideally you want this number to be as close to 100 as possible.

    In order to calculate the Buffer cache hit ratio we need to query the sys.dm_os_performance_counters dynamic management view. There are 2 counters we need in order to do our calculation, one counter is Buffer cache hit ratio and the other counter is Buffer cache hit ratio base. We divide Buffer cache hit ratio base by Buffer cache hit ratio and it will give us the Buffer cache hit ratio.
    Here is the query that will do that, this query will only work on SQL Server 2005 and up.

    1. SELECT (a.cntr_value * 1.0 / b.cntr_value) * 100.0 as BufferCacheHitRatio
    2. FROM sys.dm_os_performance_counters  a
    3. JOIN  (SELECT cntr_value,OBJECT_NAME
    4.     FROM sys.dm_os_performance_counters  
    5.     WHERE counter_name = 'Buffer cache hit ratio base'
    6.         AND OBJECT_NAME = 'SQLServer:Buffer Manager') b ON  a.OBJECT_NAME = b.OBJECT_NAME
    7. WHERE a.counter_name = 'Buffer cache hit ratio'
    8. AND a.OBJECT_NAME = 'SQLServer:Buffer Manager'




    Page life expectancy

    Now let's look at Page life expectancy.
    Page life expectancy is the number of seconds a page will stay in the buffer pool, ideally it should be above 300 seconds. If it is less than 300 seconds this could indicate memory pressure, a cache flush or missing indexes.

    Here is how to get the Page life expectancy

    1. SELECT *
    2. FROM sys.dm_os_performance_counters  
    3. WHERE counter_name = 'Page life expectancy'
    4. AND OBJECT_NAME = 'SQLServer:Buffer Manager'

    What I currently get for the queries is a Page life expectancy of 470333 and the Buffer cache hit ratio is 100. What I would like you to do is run these 2 queries on your systems and leave me the results in a comment so that we can compare

    Also take a look at how to capture this info if you prefer to run perfmon (or if you are still running SQL Server 2000) by reading this excellent article by Brent Ozar here: SQL Server Perfmon (Performance Monitor) Best Practices




    *** Remember, if you have a SQL related question try our Microsoft SQL Server Programming forum or our Microsoft SQL Server Admin forum

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    10342 views
    InstapaperVote on HN

    7 comments

    Comment from: Ted Krueger (onpnt) [Member]
    Ted Krueger (onpnt) Nice Denis! Detailed and to the point on the two topics and what to check into as a starting point.

    Others can get an idea of difference between SQL Server configurations and setups from a few runs on my own instances
    OLTP
    1.557336 and 99.535
    2.26879 and 99.859
    3.91764 and 99.863 -- this server obviously has the lowest work going on
    4.19682 and 99.854 -- largest db server I have. around 1K tran per sec and TB total DBs


    OLAP
    1.91764 and 99.863
    2.23959 and 97.878 -- 14 users running reports at this time
    3.20147 and 95.877 -- caught it while processing a cube

    Job Server
    1.3307429 and 100.000 -- this is due to handling the job functions correctly and managing resources right. This is also the entire reason you should have a job server to prevent poor paging on the main prod servers

    Dedicated Mirror -- this one is expected to be lower on page
    1.20367 and 99.82

    DR Log Shipped Warm -- this will always be the lowest page life due to log copy events
    1.16421 and 99.865


    And others have also posted here

    It would be nice to see other readers of this post their own results sense installation to installation is so unique in many cases
    01/22/10 @ 08:26
    Comment from: SQLDenis [Member] Email
    SQLDenis Show me your numbers man..I don't expect anything less than 99.5% Buffer cache hit ratio from you :-)
    01/22/10 @ 08:28
    Comment from: Ted Krueger (onpnt) [Member]
    Ted Krueger (onpnt) >>99.5% Buffer cache hit ratio

    You won't get that from me on a typical OLTP instance but there are times it isn't a bad thing when it drops into the 95 to 97 range :-)
    01/22/10 @ 08:32
    Comment from: Alex Ullrich [Member] Email
    Alex Ullrich Ted, I think that your breakdown there (with a bit more discussion on the differences observed between install types / reasons) would make a pretty good follow-up post of its' own.

    Of course you would need to add some pictures though :)
    01/22/10 @ 09:50
    Comment from: Rousseau Arulsamy [Visitor] Email
    Rousseau Arulsamy Hi,

    This is very helpful. Here we are only getting the counters related to the SQL instance.I have a new requirement, i need to retrive some system related/custom counters and should display in my application. As my application is fully configurable module i would like to do the same like the previous approach so that i no need to touch my application for this.

    Is there any way to get system related/custom counter details other then SQL Server counters from system views?

    Please guide me on this.

    Regards,
    Rousseau Arulsamy
    03/23/10 @ 03:34
    Comment from: David Forck (thirster42) [Member]
    From some of the more recent stuff I've been reading there's been a move away from relying on buffer cache hit ratio.
    10/19/11 @ 07:07
    Comment from: Crazy Adam [Visitor]
    Crazy Adam Loved the article. I wanted to share a variation on each query:

    SELECT base.cntr_value * 1.0 / rat.cntr_value * 100.0 AS [Buffer Cache Hit Ratio]
    , base.cntr_value AS [Buffer cache hit ratio base]
    , rat.cntr_value AS [Buffer cache hit ratio]
    FROM sys.dm_os_performance_counters base CROSS JOIN sys.dm_os_performance_counters rat
    WHERE base.counter_name = 'Buffer cache hit ratio base'
    AND rat.counter_name = 'Buffer cache hit ratio'
    GO

    SELECT counter_name
    , cntr_value AS [PLE in sec]
    , cntr_value / 60 AS [PLE in min]
    FROM sys.dm_os_performance_counters
    WHERE counter_name = 'Page life expectancy'
    AND OBJECT_NAME LIKE '%:Buffer Manager%'
    GO

    The changes are pretty intuitive.
    02/13/13 @ 07:26

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)