Mirroring a Large Number of Databases in a Single SQL Server Instance

Rate This
  • Comments 29

Authors: Sanjay Mishra, Prem Mehra


Technical Reviewers: Lubor Kollar, Michael Thomassy, Lindsey Allen, Mike Ruthruff, Kaloian Manassiev, Kevin Cox, Thomas Kejser, Mike Weiner, Mark Souza, Joseph Sack, Glenn Berry (SQL Server MVP)

 

Overview

A frequently asked question regarding database mirroring is: How many databases can be mirrored in a single instance of Microsoft® SQL Server®? This question is often raised by customers who are consolidating many databases into fewer instances and the high availability or disaster recovery service-level agreement (SLA) requires deployment of database mirroring.

Sometimes the question is raised when readers misconstrue the restriction documented in the SQL Server Books Online stating that “On a 32-bit system, database mirroring can support a maximum of about 10 databases per server instance because of the numbers of worker threads that are consumed by each database mirroring session.”

It is important to mention two significant points:

  • The restriction of 10 databases doesn’t apply to 64-bit systems. In SQL Server Books Online, there are no such documented restrictions on the number of databases in a 64-bit system.
  • Various customers have successfully deployed database mirroring with more than 10 databases in a 64-bit environment.

This article explains the number of worker threads required for database mirroring for each database and illustrates the observed performance of an application with many databases. System administrators and database administrators may find this information useful as they examine, test, and deploy systems in the production environment.

 

Threads Used by Database Mirroring in SQL Server 2008

The number of threads used on a server for database mirroring depends upon:

  • The role of the server – principal or mirror
  • The number of databases mirrored in an instance
  • The number of logical processors on the mirror server

The following table summarizes the number of database mirroring threads used.

Role of server

Thread function

Number of threads for the specific function

Principal

Database mirroring communications

1 per instance

 

Event processing

1 per mirrored database

 

Log send

1 per mirrored database

Mirror

Database mirroring communications

1 per instance

 

Event processing

1 per mirrored database

 

Log hardening

1 per mirrored database

 

Redo manager

1 per mirrored database

 

Redo threads

FLOOR ((number of logical processors +3) / 4)

In summary, the number of database mirroring threads:

  • On a principal is equal to (2 * number of mirrored databases) + 1.
  • On a mirror equals ((3 + FLOOR ((number of logical processors +3) / 4)) * number of mirrored databases) + 1.

For example: If your principal and mirror servers have 8 logical processors each, and you are mirroring 20 databases, the total number of database mirroring threads used on the principal will be 41, and the total number of database mirroring threads used on the mirror will be 101.

To view the threads used for database mirroring, query the DMV sys.dm_exec_requests.

SELECT SESSION_ID, STATUS, COMMAND, WAIT_TYPE

FROM SYS.DM_EXEC_REQUESTS WHERE COMMAND = 'DB MIRROR'

Here is sample output from this query on the mirror server with 8 logical processors, and with one mirrored database.

SESSION_ID

STATUS

COMMAND

WAIT_TYPE

 

15

background

DB MIRROR

DBMIRROR_EVENTS_QUEUE

Database mirroring communications

16

background

DB MIRROR

DBMIRROR_EVENTS_QUEUE

Event processing

16

background

DB MIRROR

DBMIRROR_DBM_MUTEX

Redo manager

16

background

DB MIRROR

DBMIRROR_DBM_MUTEX

Redo thread

16

background

DB MIRROR

DBMIRROR_DBM_MUTEX

Redo thread

17

background

DB MIRROR

DBMIRROR_SEND

Log hardening

  

Test Results

To illustrate database mirroring in a consolidated environment, we ran tests with a workload that continuously inserted data into a number of databases. The databases were deployed with synchronous mirroring between two identical servers (for more information, see “Test Hardware and Software” in the Appendix). The application opened 20 connections to each database, and each connection continuously inserted 6,000 rows (one by one) into the database. The insertion rate of the workload scales linearly as we added more databases.

The focus of our tests was to demonstrate the ability to mirror multiple databases in a consolidated database environment. As an aside, we also observed linear scalability of the workload throughput. For more information about database mirroring performance topics, see Database Mirroring Best Practices and Performance Considerations.

We measured the thread counts, percent of CPU used, and application throughput as we increased the number of mirrored databases. For estimating CPU usage and throughput in your environment, we recommend that you test with your workload.

Number of databases mirrored

Transaction throughput (batch requests/sec)

%CPU (principal)

%CPU (mirror)

Number of all threads (principal)

Number of DBM threads (principal)

Number of all threads (mirror)

Number of DBM threads (mirror)

20

2,680

15

13.9

212

41

187

101

40

5,244

27.3

24.4

342

81

296

201

60

7,814

42.1

32.5

603

121

391

301

80

10,251

55.1

38.6

612

161

492

401

100

12,102

63.5

42.9

612

201

592

501

 image

The line “Number of Threads (Mirror)” shows the total number of threads used on the mirror server. This includes the number of threads used by database mirroring represented by the line “Number of DBM Threads (Mirror).”

 

Additional Considerations

There are two additional considerations – one on application throughput, and another on ping traffic.

Impact of Threads on Throughput

As an aside, note that the overall system performance may be impacted by the number of threads available for processing the workload:

  • The database mirroring sessions will consume some number of threads, as discussed above. 
  • The remaining threads are available to service user requests. 
  • If max_worker_threads is not set high enough, user requests might wait on worker threads even though there are adequate CPU and other resources to service those requests.
  • Monitor the wait statistics wait for the worker counter to find out whether you are running low on worker threads, and set max_worker_threads appropriately.

  

Ping Traffic

For the database mirroring session for each database, the servers send and receive a ping from each other. When several databases are mirrored, the servers will send each other many ping messages within a short interval. To keep the database mirroring connection open, a server must receive and send a ping on that connection within the timeout period.

If the database mirroring partner timeout interval has been set too low, false failovers may occur (if a witness is enabled), or the database mirroring session may switch between disconnected and synchronizing states (if there is no witness).

We recommend that you set the timeout interval to a value of 10 seconds (default) or higher, and if you see unexpected timeouts, increase it to a higher value.

 

Recommendations

  • When you set max worker threads (sp_configure option), make sure to accommodate threads needed by database mirroring in addition to the threads needed by your workload.
  • When you set max server memory, make sure to account for the memory consumed by the threads, which is allocated from outside of the buffer pool memory. For more information, see 64-bit Solutions for SQL Server.
  • Set these options to the same value on both partners (principal as well as mirror), so that the experience is consistent after a role change.
  • Ensure that application performance is acceptable with an increased number of databases and the associated workload on the consolidated server.

 

Conclusion

With proper planning, it is possible to mirror hundreds of databases in an instance. Use the information provided in this article for planning, and perform thorough testing with your workload to ensure successful deployment.

 

Appendix A: Test Hardware and Software

All the tests were performed in the following hardware and software environment.

 

Server

Two Dell PE6950 servers (used as principal and mirror), each with:

  • 4-socket, dual-core AMD Opteron™ processor 8220 @2.80 GHz
  • 32 GB RAM

One Dell R805 server (used as client), with:

  • 2-socket, quad-core AMD Opteron™ processor 2354 @2.20 GHz
  • 32 GB RAM

  

Storage

One 3PAR SAN, with:

  • 240 disks, each 147 GB, 10K RPM
  • 12 ports, 2 directly attached per server
  • All LUNs are striped across all disks
  • 16 GB data cache, 4 GB control cache; data cache is dynamically allocated based on I/O patterns

Purpose

Drive

RAID

# LUNs

Total GB

Data

M:

1+0

1

2,000

Log

N:

1+0

1

500

  

Software

  • The 64-bit edition of Windows Server® 2008 Enterprise with Service Pack 1
  • The 64-bit edition of SQL Server 2008 Enterprise with Service Pack 1

 

Further Reading

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Post
  • Pingback from  Mirroring a Large Number of Databases in a Single SQL Server … Mobile

  • Pingback from  Mirroring a Large Number of Databases in a Single SQL Server … | Drakz Free Online Service

  • Nice job Sanjay and Prem. Glad to see this published.

  • Microsoft SQLCAT team members Sanjay Mishra and Prem Mehra have published a new Technical Note called

  • This post was mentioned on Twitter by jameslean: How many DBs can you mirror on a single #sqlserver instance? Probably more than you think, assuming 64 bit: http://bit.ly/dpJkEM

  • This is an excellent write up on mirroring.  Planning the cost of mirroring can be hard and often overlooked until it is a problem.  With these types of articles out there is will help a lot of people questioning the performance and planning needs before they throw mirroring into an environment.  

    Great job Sanjay and Prem!

  • Pingback from  Well Defined Structural Drawings ??? Improve Your Building's Quality | Structural Engineering Addict

  • Pingback from  MikHo Software  » Blog Archive   » SQL Server 2005 Mirroring Limitation – Maximum Mirrors?

  • What would I need to consider for SQL 2005?

  • I don't like the suggestion of increasing max worker threads. People are taking this to mean that they can mirror any number of databases simply by increasing the # of threads.

    Ultimately, the system has to get all of those threads down to a single thread per logical CPU. There's no work-around for that. Adding more worker threads just increases the number of tasks that can be waiting for a CPU thread. It doesn't actually increase the capabilities of the server. Under a light load, it will work fine, but if the server is busy, it's going to cause a lot of waits.

  • Lately I’ve noticed an increasing number of people recommend increasing worker threads. The reasons for the recommendations include things as simple as a troubleshooting step for reports of general system slowness or as complex as a means to mirror very

  • I expanded on my opinion about the worker threads statement above on my blog. I think it makes a nice companion piece to this paper.

    The Toilet Analogy … or Why I Never Recommend Increasing Worker Threads: www.sqlservercentral.com/.../The-Toilet-Analogy-_2620_-or-Why-I-Never-Recommend-Increasing-Worker-Threads.aspx

  • Response to Various Comments by Robert Davis:

    The bottomline is this:

    1) Understand how things work. Know how many threads are used for what purpose.

    2) Test your configuration with your workload. Every configuration and every workload is unique.

    At this point, it is important to warn the readers to NOT follow the guidance on how many databases you can mirror that is based on the assumption that mirroring each database requires 25.6 threads (incorrect interpolation based on a 32-bit recommendation). I have seen a blog floating around that follows this wrong assumption and wrong recommendation. That is misleading the readers.

  • I agree completely Sanjay. I think this paper here is a great paper with a lot of valuable information. I have directed others to this paper to help them understand the cost of planning out large mirroring deployments.

  • How many mirrrored databases can I have on a server? 10 mirrored databases per server is the recommendation for a 32 bit computer WITH 4 processors or less. 64 bit computers have twice as many threads which means, in theory, that you can have twice as

Page 1 of 2 (29 items) 12
Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Post