How does tempdb contention affect the performance of applications that heavily rely on temporary tables, and what strategies help mitigate this?
Short answer
Since all temporary tables and table variables across an entire SQL Server instance are stored in the shared tempdb system database, a busy server creating and dropping many temporary tables can experience contention specifically around tempdb's internal system pages, which can…
Advertisement
AModel answer
Since all temporary tables and table variables across an entire SQL Server instance are stored in the shared tempdb system database, a busy server creating and dropping many temporary tables can experience contention specifically around tempdb's internal system pages, which can be mitigated by properly configuring multiple tempdb data files and minimizing unnecessary temporary table creation in extremely high frequency code paths.
-- Properly sized and multiple tempdb files help reduce contention
-- from heavy temporary table usage across many concurrent sessions
ALTER DATABASE tempdb ADD FILE (NAME = tempdev2, FILENAME = 'D:\tempdb2.mdf', SIZE = 512MB);Real-world example
A high traffic application experiencing tempdb related contention during peak hours resolves much of the issue by properly configuring multiple equally sized tempdb data files, following Microsoft's recommended best practices for a busy server.
Likely follow-ups
- How do you identify tempdb contention as the actual root cause of a performance problem?
- What other tempdb best practices help reduce this kind of contention?
Related topics