Honored to receive a Patriot Award

This morning I had the great honor to be presented with a Patriot Award for supporting the U.S. Army Reserve activities of Sergeant First Class Jonathan Kehayias.

It’s an award for me as I’m Jonathan’s supervisor; and for SQLskills as a company, Kimberly signed the statement of continuing support for the Guard and Reserve. I accepted the award from Phil Sanders, the State Vice Chair of the Washington Employer Support of the Guard and Reserve, and we flew Jonathan out to Redmond to be with us for the award ceremony.

Jonathan joined the Army Reserve 19.5 years ago, was mobilized in support of Operation Iraqi Freedom, and deployed to Iraq for a year between 2003 and 2004. Since then he’s continued serving as a Drill Sergeant and is currently a Career Counselor, responsible for helping guide service members on whether to continue serving. Since Jonathan joined SQLskills in March 2011, we’ve supported him in every way possible and encouraged him to continue to serve.

Jonathan, thank you for nominating us for this award, and sincere thanks for your past and future service.

The Curious Case of… very long failover times with a large ad hoc workload

(The Curious Case of… used to be part of our bi-weekly newsletter but we decided to make it a regular blog post instead so it can sometimes be more frequent. It covers something interesting one of us encountered when working with a client, doing some testing, or were asked in a random question from the community.)

Erin worked with a client recently who was experiencing very long failover times with a large ad hoc workload and needed to understand why. By very long, we’re talking more than 30 minutes for an availability group failover, and they’d tested failovers under load before and never had it take more than a few minutes. They wondered if their workload had changed or there was some configuration setting that was off because they’d also recently upgraded.

Obviously Erin didn’t want them to do another failover and take more downtime and luckily they have a process in place to capture wait statistics all the time so Erin could see what waits happened while the failover was in progress. One stood out to her right away: QDS_LOADDB.

The QDS_LOADDB wait happens when a database is bring brought online, Query Store is enabled, and the Query Store data is being loaded from disk. No queries can execute until that data has finished loading. In this case, the client had enabled Query Store after upgrading and with their large workload of ad hoc queries, there was 100GB of Query Store data to load. That was the cause of the long failover time and they didn’t realize that Query Store has this behavior.

Luckily there is a workaround other than disabling Query Store. You can enable documented trace flag 7752 which makes the Query Store data load asynchronous with the database startup. This means that queries can run before the data load completes, but Query Store won’t capture any information about them (Query Store is essentially read-only until the data load completes). Erin discusses this and other Query Store trace flags in her post here, and in general about Query Store settings and data size in this post.

Bottom line: make sure you understand how a feature changes behavior before enabling it, and HA/DR testing should be performed regularly to catch unexpected behaviors such as this.

The Curious Case of… does SQL Server use a read/write thread per LUN?

(The Curious Case of… used to be part of our bi-weekly newsletter but we decided to make it a regular blog post instead so it can sometimes be more frequent. It covers something interesting one of us encountered when working with a client, doing some testing, or were asked in a random question from the community.)

I had a question in email this morning from someone that was basically does SQL Server use a read/write thread per LUN?

The short answer is no.

My friend Bob Dorr from CSS actually debunked this publicly way back in  2007 in the blog post SQL Server Urban Legends Discussed and also explains how some of the wording in earlier versions of Books online led to the myth that SQL Server uses one read/write thread per LUN or per data file. This myth leads people to believe that adding more data files will increase I/O performance because more threads will be used to do the writing. While it’s true that more data files can increase performance, depending on your I/O subsystem and the file/filegroup layout on that I/O subsystem, it’s nothing to do with that myth.

Any thread in SQL Server that’s processing a query can issue an asynchronous read request. When a thread makes a call into the buffer pool to get  a pointer to a data file page copy in memory, if the page isn’t already in memory then it has to issue a read and then wait for the read to complete (called a physical I/O). On the other hand, if the page already is in memory, the thread pops back out to where it came from (usually the Access Methods code) and that’s a logical I/O, with no accompanying wait. Pages can also be read in larger chunks by things like index seek/scan readahead and DBCC CHECKDB‘s readahead.

Pages can be written to disk in a variety of ways, including:

  • Through a regular checkpoint by a checkpoint background thread
  • Through lazy writing when there’s memory pressure on the buffer pool bu a lazy writer background thread
  • Through eager writing, when performing a minimally-logged operation in (guaranteeing that the full result of the operation is durable when it finishes)
  • Through database snapshot real-time maintenance, when a page is first changed after a database snapshot is created, it is synchronously written to the snapshot

There’s one exception though: backup and restore *will* use a separate reader or writer thread per device to aid in I/O parallelism, but backup and restore don’t use the buffer pool and open direct channels to the devices themselves.

Bottom line: for regular operations, the one-thread-per-file/LUN is a big myth that’s still around today.