SQL 2012:                       SQL Server Day
Indirect
Checkpoints                   Parikshit Savjani
                              Premier Field Engineer,
Explained                     Microsoft

          http://www.sqlserverfaq.net
Agenda

                          Current
                          Checkpoint
Checkpoints               Algorithm

                          Indirect
                          Checkpoint
Challenges                Algorithm

     Call to Action
        http://www.sqlserverfaq.net
Update A=C                                                          T
Update B=D                                                          L
commit                                                              O
                                                                    G
             Dirty         Dirty                                    B
BUFFER                                                   Update
POOL                                                                U


 RAM
                                               C D       commit     F
                                                                    F
                                                                    E
                                                                    R
       CHECKPOINT



             Dirty          Dirty
                                               C B
                                               A D
                                                          Insert
                                                          Delete


                     http://www.sqlserverfaq.net
HARD DRIVE                                Userdb.mdf   Userdb.ldf
CURRENT CHECKPOINT ALGORITHM
               Userdb.ldf


                                          Checkpoint            (Flush Dirty Buffers)
        Delete 50 pages
                                                            Recovery Interval = 1 min
        Update 10 pages
        Insert 100 pages

                                         Checkpoint             (Flush Dirty Buffers)
         Update 10000 pages                                 But Recovery is dependent on
                                                            Number Of Dirty Buffers to be
         Insert 1000 pages
CRAS                                                        flushed which is Not Accounted.
 H
         Delete 500 pages
                                          Checkpoint             (Flush Dirty Buffers)




                              http://www.sqlserverfaq.net
Checkpoint IO: Existing Algorithm




            http://www.sqlserverfaq.net
Challenges with the Current Checkpoint Algorithm




                                                                     Checkpoint
  Checkpoint       Recovery Time
                                               Common to see        process takes
    doesn’t             is not
                                               IO spikes at the    time searching
account no. of     predictable and
                                                 Checkpoint       for dirty buffers
dirty buffers to      cannot be
                                                  Operation        while scanning
  be flushed         guaranteed
                                                                   the buffer pool




                       http://www.sqlserverfaq.net
INDIRECT CHECKPOINT ALGORITHM
                                                               LSN 0    Checkpoint
                            MinLSN
                                                                          50
            Userdb.ldf                                         LSN 10    pages
                                             Dirty Page List              10
                                                               LSN 20    pages
  LSN 0: Checkpoint LSN                                        LSN 30   100 pages
                                        Checkpoint
  LSN 10: Delete 50 pages
                                                                  DIRTY_PAGE_POLL
                                                Target Recovery Time = 1 min
  LSN 20: Update 10 pages
                                            Background Recovery Writer
  LSN 30: Insert 100
  pages                                                If Dirty Pages > Threshold
                                       Checkpoint      Then
                                                        Flush Pages()
  LSN 40:Update 10000 pages                             Move MinLSN forward
                                       Target Dirty Buffer Threshold = 60 pages
  LSN 50: Insert 1000
  pages                                      NO Pages Are Flushed during
  LSN 60: Delete 500 pages                   Checkpoint
                                        Checkpoint
                                             Instead it just calculates the
                                             New MinRecoveryLSN



                            http://www.sqlserverfaq.net
Goals of the Indirect Checkpoint Algorithm

 Recovery Time should be predictable and should be guaranteed



 Reduce or Smoothen the IO spikes caused by automatic
 checkpoint




                        http://www.sqlserverfaq.net
http://www.sqlserverfaq.net
POINTS TO REMEMBER

   • Indirect Checkpoints are turned off by default

   • Indirect Checkpoints needs to enabled for each database explicitly using
     the new command syntax
   • ALTER DATABASE … SET TARGET_RECOVERY_TIME = target_recovery_time { SECONDS |
     MINUTES }

   • When Indirect Checkpoint is in effect, the checkpoint background
     thread
   •      Does not perform the FlushCache work
   •      just calculates MinRecoveryLSN and writes it to Tlog

   • A new background thread called RECOVERY WRITER (one per sql
     instance) is available to flush the pages when dirty pages reaches the
     threshold

   • A new internal waitype called DIRTY_PAGE_POLL is introduced as
     RECOVERY WRITER is timed thread to periodically check Dirty Page List

                                http://www.sqlserverfaq.net
CALL TO ACTION

      • Identify the databases in your environment which requires
        predictable and guaranteed RTO


      • Test the IO Performance for the given database before turning it ON
        in production


      • Setting the target_recovery_time too small increases the IO
        workload and causes recovery writer thread to flush aggressively


      • Tune target_recovery_time to strike the right balance between IO
        workload and RTO

      • Use the new perfmon counter SQL Server:Buffer
        ManagerBackground Writer Pages/Sec and Extended Events for
        monitoring

                           http://www.sqlserverfaq.net
http://www.sqlserverfaq.net

Indirect checkpointing

  • 1.
    SQL 2012: SQL Server Day Indirect Checkpoints Parikshit Savjani Premier Field Engineer, Explained Microsoft http://www.sqlserverfaq.net
  • 2.
    Agenda Current Checkpoint Checkpoints Algorithm Indirect Checkpoint Challenges Algorithm Call to Action http://www.sqlserverfaq.net
  • 3.
    Update A=C T Update B=D L commit O G Dirty Dirty B BUFFER Update POOL U RAM C D commit F F E R CHECKPOINT Dirty Dirty C B A D Insert Delete http://www.sqlserverfaq.net HARD DRIVE Userdb.mdf Userdb.ldf
  • 4.
    CURRENT CHECKPOINT ALGORITHM Userdb.ldf Checkpoint (Flush Dirty Buffers) Delete 50 pages Recovery Interval = 1 min Update 10 pages Insert 100 pages Checkpoint (Flush Dirty Buffers) Update 10000 pages But Recovery is dependent on Number Of Dirty Buffers to be Insert 1000 pages CRAS flushed which is Not Accounted. H Delete 500 pages Checkpoint (Flush Dirty Buffers) http://www.sqlserverfaq.net
  • 5.
    Checkpoint IO: ExistingAlgorithm http://www.sqlserverfaq.net
  • 6.
    Challenges with theCurrent Checkpoint Algorithm Checkpoint Checkpoint Recovery Time Common to see process takes doesn’t is not IO spikes at the time searching account no. of predictable and Checkpoint for dirty buffers dirty buffers to cannot be Operation while scanning be flushed guaranteed the buffer pool http://www.sqlserverfaq.net
  • 7.
    INDIRECT CHECKPOINT ALGORITHM LSN 0 Checkpoint MinLSN 50 Userdb.ldf LSN 10 pages Dirty Page List 10 LSN 20 pages LSN 0: Checkpoint LSN LSN 30 100 pages Checkpoint LSN 10: Delete 50 pages DIRTY_PAGE_POLL Target Recovery Time = 1 min LSN 20: Update 10 pages Background Recovery Writer LSN 30: Insert 100 pages If Dirty Pages > Threshold Checkpoint Then Flush Pages() LSN 40:Update 10000 pages Move MinLSN forward Target Dirty Buffer Threshold = 60 pages LSN 50: Insert 1000 pages NO Pages Are Flushed during LSN 60: Delete 500 pages Checkpoint Checkpoint Instead it just calculates the New MinRecoveryLSN http://www.sqlserverfaq.net
  • 8.
    Goals of theIndirect Checkpoint Algorithm Recovery Time should be predictable and should be guaranteed Reduce or Smoothen the IO spikes caused by automatic checkpoint http://www.sqlserverfaq.net
  • 9.
  • 10.
    POINTS TO REMEMBER • Indirect Checkpoints are turned off by default • Indirect Checkpoints needs to enabled for each database explicitly using the new command syntax • ALTER DATABASE … SET TARGET_RECOVERY_TIME = target_recovery_time { SECONDS | MINUTES } • When Indirect Checkpoint is in effect, the checkpoint background thread • Does not perform the FlushCache work • just calculates MinRecoveryLSN and writes it to Tlog • A new background thread called RECOVERY WRITER (one per sql instance) is available to flush the pages when dirty pages reaches the threshold • A new internal waitype called DIRTY_PAGE_POLL is introduced as RECOVERY WRITER is timed thread to periodically check Dirty Page List http://www.sqlserverfaq.net
  • 11.
    CALL TO ACTION • Identify the databases in your environment which requires predictable and guaranteed RTO • Test the IO Performance for the given database before turning it ON in production • Setting the target_recovery_time too small increases the IO workload and causes recovery writer thread to flush aggressively • Tune target_recovery_time to strike the right balance between IO workload and RTO • Use the new perfmon counter SQL Server:Buffer ManagerBackground Writer Pages/Sec and Extended Events for monitoring http://www.sqlserverfaq.net
  • 12.