Microsoft KB Archive/328551

From BetaArchive Wiki

Article ID: 328551

Article Last Modified on 11/2/2007



APPLIES TO

  • Microsoft SQL Server 2000 Developer Edition
  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 2000 Enterprise Edition
  • Microsoft SQL Server 2000 Personal Edition
  • Microsoft SQL Server 2000 Enterprise Edition
  • Microsoft SQL Server 2000 Workgroup Edition
  • Microsoft SQL Server 2000 Desktop Engine (Windows)
  • Microsoft SQL Server 2000 Developer Edition
  • Microsoft SQL Server 2000 Enterprise Edition 64-bit



This article was previously published under Q328551

BUG #: 362099 (SHILOH_BUGS)

SYMPTOMS

When the tempdb database is heavily used, SQL Server may experience contention when it tries to allocate pages.

From the sysprocesses system table output, the waitresource may show up as "2:1:1" (PFS Page) or "2:1:3" (SGAM Page). Depending on the degree of contention, this may also lead to SQL Server appearing unresponsive for short periods.


These operations heavily use tempdb:

  • Repeated create and drop of temporary tables (local or global).
  • Table variables that use tempdb for storage purposes.
  • Work tables associated with CURSORS.
  • Work tables associated with an ORDER BY clause.
  • Work tables associated with an GROUP BY clause.
  • Work files associated with HASH PLANS.

Heavy and significant use of these activities may lead to the contention problems.

CAUSE

During object creation, two (2) pages must be allocated from a mixed extent and assigned to the new object. One page is for the Index Allocation Map (IAM), and the second is for the first page for the object. SQL Server tracks mixed extents by using the Shared Global Allocation Map (SGAM) page. Each SGAM page tracks about 4 gigabytes of data.

As part of allocating a page from the mixed extent, SQL Server must scan the Page Free Space (PFS) page to find out which mixed page is free to be allocated. The PFS page keeps track of free space available on every page, and each PFS page tracks about 8000 pages. Appropriate synchronization is maintained to make changes to the PFS and SGAM pages; and that can stall other modifiers for short periods.

When SQL Server searches for a mixed page to allocate, it always starts the scan on the same file and SGAM page. This results in intense contention on the SGAM page when several mixed page allocations are underway, which can cause the problems documented in the "Symptoms" section of this article.

Note De-allocation activities must also modify the pages, which can contribute to the increased contention.

To learn more about the different allocation mechanisms used by SQL Server (SGAM, GAM, PFS, IAM), see the "References" section of this article.

RESOLUTION

To reduce the allocation resource contention for tempdb that is experiencing heavy usage, follow all these steps:

  1. For servers that are running SQL Server 2000 Service Pack 3 (SP3), apply hotfix 8.00.0765 or the latest security fix 8.00.0818. For servers that are running SQL Server SP2, apply hotfix 8.00.0702.

    These fixes are available from the following locations:

    8.00.0765

    814916 FIX: Merge Agent for a filtered publication might fail

    8.00.0818

    8.00.0702

    328551 FIX: Concurrency enhancements for the tempdb database

  2. Implement trace flag -T1118.
  3. Increase the number of tempdb data files to be at least equal to the number of processors. Also, create the files with equal sizing. For more information, see the "More Information" section.

Note These steps also apply to Microsoft SQL Server 7.0. The only exception is that there is no hotfix for SQL Server 7.0; therefore, step 1 does not apply.

With regards to step 2, the use of trace flag -T1118 for Microsoft SQL Server 7.0, before you use the trace flag, see the following article in the Microsoft Knowledge Base:

813492 FIX: Create index fails on SQL Server 7.0 when trace flag 1118 is enabled


Service pack information

To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

290211 How to obtain the latest SQL Server 2000 service pack


Hotfix information

Hotfix 8.00.0702

The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.

   Date         Time   Version         Size       File name
   ----------------------------------------------------------------
   30-Aug-2002  21:08                    786,432  Distmdl.ldf
   30-Aug-2002  21:08                  2,359,296  Distmdl.mdf
   09-Oct-2002  00:54                        544  Drop_repl_hotfix.sql
   02-Jul-2002  15:35  2000.80.650.0     107,088  Impprov.dll      
   19-Jul-2002  16:56                    774,516  Instdist.sql
   08-Oct-2002  23:56                     12,615  Inst_repl_hotfix.sql
   20-Aug-2002  16:24  2000.80.679.0     111,172  Logread.exe      
   07-Apr-2002  02:08  2000.80.606.0      62,024  Odsole70.dll     
   03-Jan-2002  01:59                     18,185  Qfe356326.sql
   20-Aug-2002  16:47  2000.80.679.0     135,748  Qrdrsvc.exe      
   26-Aug-2002  22:49  2000.80.679.0     406,088  Rdistcom.dll     
   04-Oct-2001  01:36                    437,302  Replcom.sql
   20-Aug-2002  16:33  2000.80.679.0     152,136  Replmerg.exe     
   19-Nov-2001  20:36                    993,945  Replmerg.sql
   05-Nov-2002  23:48  2000.80.700.0     221,768  Replprov.dll     
   04-Oct-2001  01:36                    986,906  Replsys.sql
   04-Oct-2001  01:36                    881,228  Repltran.sql
   26-Aug-2002  22:49  2000.80.679.0     283,208  Rinitcom.dll     
   16-Sep-2002  22:31                    390,045  Securityhotfix.sql
   26-Aug-2002  22:49  2000.80.679.0      28,672  Sqlagent.dll     
   26-Aug-2002  18:39  2000.80.679.0     311,872  Sqlagent.exe     
   28-Aug-2002  16:32  2000.80.679.0      49,152  Sqlagent.rll
   26-Aug-2002  22:49  2000.80.679.0      53,824  Sqlcmdss.dll     
   28-Aug-2002  16:40  2000.80.679.0      12,288  Sqlcmdss.rll
   24-Oct-2002  17:37  2000.80.695.0     176,696  Sqlmap70.dll     
   11-Nov-2002  09:52  2000.80.702.0   7,471,185  Sqlservr.exe     
   11-Nov-2002  09:51                 12,633,088  Sqlservr.pdb
   01-Nov-2002  18:56  2000.80.698.0      45,644  Sqlvdi.dll       
   01-Nov-2002  18:00  2000.80.697.0      82,492  Ssnetlib.dll     
   07-Apr-2002  02:08  2000.80.606.0      70,208  Xplog70.dll      
   07-Apr-2002  02:08  2000.80.606.0      53,828  Xpqueue.dll      
   07-Apr-2002  02:08  2000.80.606.0     156,228  Xprepl.dll       
   12-Jul-2002  01:00  2000.80.658.0     279,104  Xpstar.dll       
   16-Sep-2002  23:12  2000.80.686.0      98,872  Xpweb70.dll   
                

Notes

  • Because of file dependencies, the most recent hotfix or feature that contains the files may also contain additional files.
  • The hotfix 8.00.0702 is for computers where you have applied SQL Server 2000 SP2. If you installed SQL Server 2000 SP3, install SQL Server 2000 SP3 rollup version 8.00.0765.


STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in Microsoft SQL Server 2000 Service Pack 4.

MORE INFORMATION

How Hotfix 8.00.0702 reduces contention

Hotfix 8.00.0702 introduces a round-robin algorithm for mixed page allocations. With the fix, the starting file will now be different for each consecutive mixed page allocation (if more than one file exists). This avoids the contention problem by breaking up the train that went through the SGAMs in the same order every time with the same starting point. The new allocation algorithm for SGAM is pure round-robin, and does not honor the proportional fill to maintain speed. Microsoft recommends that you create the tempdb data files with the same size.

How implementing trace flag -T1118 reduces contention

Here is list of how use of -T1118 reduces contention:

  • -T1118 is a server-wide setting.
  • Include the -T1118 trace flag in the Startup parameters for SQL Server so that the trace flag remains in effect even after SQL Server is recycled.
  • -T1118 removes almost all single page allocations on the server.
  • By disabling most of the single page allocations, you reduce the contention on the SGAM page.
  • With -T1118 turned ON, almost all new allocations are performed from a GAM page (for example, 2:1:2) that allocates eight (8) pages (1 extent) at a time to a object as opposed to a single page from an extent for the first eight (8) pages of an object, without the trace flag.
  • The IAM pages still use the single page allocations from the SGAM page, even with -T1118 turned ON. However, when combined with hotfix 8.00.0702 and increased tempdb data files, the net effect is a reduction in contention on the SGAM page. For space concerns, see the "Disadvantages" section of this article.

Note When the trace flag 1118 is turned on for your instance of SQL Server 2000, you may not be able to successfully restore a SQL Server 7.0 database. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

837938 You may receive an error message when you try to restore a SQL Server 7.0 database backup on an instance of SQL Server 2000


Increase the number of tempdb data files with equal sizing

If the data file size of tempdb is 5 GB, and the Log file size is 5 GB, the recommendation is to increase the single datafile to 10 (each of 500 MB to maintain equal sizing), and leave the log file as is. Having the different data files on separate disks would be good. However, this is not required and they can co-exist on the same disk.

The optimal number of tempdb data files depends on the degree of contention seen in tempdb. As a starting point, you can configure the tempdb to be at least equal to the number of processors assigned for SQL Server. For higher end systems (for example, 16 or 32 proc), the starting number could be 10. If the contention is not reduced, you may have to increase the number of data files more.

Note A dual-core processor is considered to be two processors.

The equal sizing of data files is critical because the proportional fill algorithm is based on the size of the files. If data files are created with unequal sizes, the proportional fill algorithm tries to use the largest file more for GAM allocations instead of spreading the allocations between all the files, thereby defeating the purpose of creating multiple data files.

The auto-grow of tempdb data files can also interfere with the proportional fill algorithm. Therefore, it may be a good idea to turn off the auto-grow feature for the tempdb data files. If the auto-grow option is turned off, you must make sure to create the data files so that they are large enough to prevent the server from experiencing a lack of disk space with tempdb.

How increasing the number of tempdb data files with equal sizing reduces contention

Here is a list of how increasing the number of tempdb data files with equal sizing reduces contention:

  • With one data file for the tempdb, you only have one GAM page, and one SGAM page for each 4 GB of space.
  • Increasing the number of data files with the same sizes for tempdb effectively creates one or more GAM and SGAM pages for each data file.
  • The allocation algorithm for GAM gives out one extent at a time (eight contiguous pages) from the number of files in a round robin fashion while honoring the proportional fill. Therefore, if you have 10 equal sized files, the first allocation is from File1, the second from File2, the third from File3, and so on.
  • The resource contention of the PFS page is reduced because eight pages are marked as FULL at a time because GAM is allocating the pages.

Disadvantages

The only downside to the recommendations mentioned earlier is that you may see the size of the databases increase when the following conditions are true:

  • New objects are created in a user database.
  • Each of the new objects occupy less than 64 KB of storage.

If these conditions are true, you may allocate 64 KB ( 8 pages * 8 KB = 64 KB ) for an object that only requires 8 KB of space, thus wasting 56 KB of storage. However, if the new object uses more than 64 KB (8 pages) in it's lifetime, there is no downside with the trace flag. Therefore, in a worst case scenario, SQL Server may end up allocating seven (7) additional pages during the first allocation only for new objects that never grow beyond one (1) page.

REFERENCES

For more information about GAM, SGAM, PFS, and IAM, see the following SQL Server 2000 Books Online topics:

  • "Managing Space Used by Objects"
  • "Managing Extent Allocations and Free Space"
  • "Table and Index Architecture"
  • "Heap Structures"


Keywords: kbbug kbfix kbqfe kbsqlserv2000presp4fix kbhotfixserver KB328551