Measuring plan eviction



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
5
down vote

favorite
1












We have a SQL Server 2016 SP1 with max memory set to 24GB.

This server has a high numbers of compiles, only 10% of these compiles are from Ad-Hoc queries. So the newly compiled plans should be stored in the plan cache but the size of the plan cache is not increasing (approx 3.72GB).


I suspect that there is local memory pressure that lead to removal of plans from the cache. The plan cache pressure limit is 5GB. (75% of visible target memory from 0-4GB + 10% of visible target memory from 4GB-64GB + 5% of visible target memory>64GB). When a cachestore reaches 75% of the pressure limit, plans should be removed from the cache. In my case 75% of 5 GB is 3.75GB. So it is plausible this is the cause of the high compiles.


Is there a way to measure (perfmon, extended events, ...) the removal from plans out of the cache? So I can be certain local memory pressure is really the cause of the high compiles?










share|improve this question



























    up vote
    5
    down vote

    favorite
    1












    We have a SQL Server 2016 SP1 with max memory set to 24GB.

    This server has a high numbers of compiles, only 10% of these compiles are from Ad-Hoc queries. So the newly compiled plans should be stored in the plan cache but the size of the plan cache is not increasing (approx 3.72GB).


    I suspect that there is local memory pressure that lead to removal of plans from the cache. The plan cache pressure limit is 5GB. (75% of visible target memory from 0-4GB + 10% of visible target memory from 4GB-64GB + 5% of visible target memory>64GB). When a cachestore reaches 75% of the pressure limit, plans should be removed from the cache. In my case 75% of 5 GB is 3.75GB. So it is plausible this is the cause of the high compiles.


    Is there a way to measure (perfmon, extended events, ...) the removal from plans out of the cache? So I can be certain local memory pressure is really the cause of the high compiles?










    share|improve this question























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      We have a SQL Server 2016 SP1 with max memory set to 24GB.

      This server has a high numbers of compiles, only 10% of these compiles are from Ad-Hoc queries. So the newly compiled plans should be stored in the plan cache but the size of the plan cache is not increasing (approx 3.72GB).


      I suspect that there is local memory pressure that lead to removal of plans from the cache. The plan cache pressure limit is 5GB. (75% of visible target memory from 0-4GB + 10% of visible target memory from 4GB-64GB + 5% of visible target memory>64GB). When a cachestore reaches 75% of the pressure limit, plans should be removed from the cache. In my case 75% of 5 GB is 3.75GB. So it is plausible this is the cause of the high compiles.


      Is there a way to measure (perfmon, extended events, ...) the removal from plans out of the cache? So I can be certain local memory pressure is really the cause of the high compiles?










      share|improve this question













      We have a SQL Server 2016 SP1 with max memory set to 24GB.

      This server has a high numbers of compiles, only 10% of these compiles are from Ad-Hoc queries. So the newly compiled plans should be stored in the plan cache but the size of the plan cache is not increasing (approx 3.72GB).


      I suspect that there is local memory pressure that lead to removal of plans from the cache. The plan cache pressure limit is 5GB. (75% of visible target memory from 0-4GB + 10% of visible target memory from 4GB-64GB + 5% of visible target memory>64GB). When a cachestore reaches 75% of the pressure limit, plans should be removed from the cache. In my case 75% of 5 GB is 3.75GB. So it is plausible this is the cause of the high compiles.


      Is there a way to measure (perfmon, extended events, ...) the removal from plans out of the cache? So I can be certain local memory pressure is really the cause of the high compiles?







      sql-server-2016 database-internals plan-cache






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 13:34









      Frederik Vanderhaegen

      575315




      575315




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          There's an XEvent for that:




          query_cache_removal_statistics



          Occurs when a query plan is removed from the plan cache and the
          historical statistics for the object are about to be destroyed




          So something like:



          CREATE EVENT SESSION [PlanCacheEvictions] ON SERVER 
          ADD EVENT sqlserver.query_cache_removal_statistics(
          ACTION(sqlserver.sql_text))


          Also if your plan cache has a large number of single-use plans consider setting optimize for ad hoc workloads.






          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "182"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f222091%2fmeasuring-plan-eviction%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            6
            down vote



            accepted










            There's an XEvent for that:




            query_cache_removal_statistics



            Occurs when a query plan is removed from the plan cache and the
            historical statistics for the object are about to be destroyed




            So something like:



            CREATE EVENT SESSION [PlanCacheEvictions] ON SERVER 
            ADD EVENT sqlserver.query_cache_removal_statistics(
            ACTION(sqlserver.sql_text))


            Also if your plan cache has a large number of single-use plans consider setting optimize for ad hoc workloads.






            share|improve this answer
























              up vote
              6
              down vote



              accepted










              There's an XEvent for that:




              query_cache_removal_statistics



              Occurs when a query plan is removed from the plan cache and the
              historical statistics for the object are about to be destroyed




              So something like:



              CREATE EVENT SESSION [PlanCacheEvictions] ON SERVER 
              ADD EVENT sqlserver.query_cache_removal_statistics(
              ACTION(sqlserver.sql_text))


              Also if your plan cache has a large number of single-use plans consider setting optimize for ad hoc workloads.






              share|improve this answer






















                up vote
                6
                down vote



                accepted







                up vote
                6
                down vote



                accepted






                There's an XEvent for that:




                query_cache_removal_statistics



                Occurs when a query plan is removed from the plan cache and the
                historical statistics for the object are about to be destroyed




                So something like:



                CREATE EVENT SESSION [PlanCacheEvictions] ON SERVER 
                ADD EVENT sqlserver.query_cache_removal_statistics(
                ACTION(sqlserver.sql_text))


                Also if your plan cache has a large number of single-use plans consider setting optimize for ad hoc workloads.






                share|improve this answer












                There's an XEvent for that:




                query_cache_removal_statistics



                Occurs when a query plan is removed from the plan cache and the
                historical statistics for the object are about to be destroyed




                So something like:



                CREATE EVENT SESSION [PlanCacheEvictions] ON SERVER 
                ADD EVENT sqlserver.query_cache_removal_statistics(
                ACTION(sqlserver.sql_text))


                Also if your plan cache has a large number of single-use plans consider setting optimize for ad hoc workloads.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 14:04









                David Browne - Microsoft

                9,676725




                9,676725



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f222091%2fmeasuring-plan-eviction%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                    Crossroads (UK TV series)

                    ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế