30.06.2013 Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6: Physical Disk Statistics and Utilization<br />

A certain amount of physical I/O is inevitable. It will occur when data modifications,<br />

written to the data cache in memory, need to be "hardened" to disk. The write-ahead<br />

logging mechanism used by <strong>SQL</strong> <strong>Server</strong> means that the details of INSERT, UPDATE and<br />

DELETE transactions are always first written to the transaction log (LDF) file on disk.<br />

A data page that contains data that has been committed to the transaction log file but<br />

not to the data (MDF) file is referred to as a "dirty page." A process called the "lazy writer"<br />

manages the writing of dirty pages to physical disk when there is time, or when no more<br />

data can be placed into the cache, while another process, called the "checkpoint" process,<br />

makes sure the number of dirty pages is kept to a level such that, if you needed to recover<br />

the database, a relatively small number of pages would need to be read from the log.<br />

In addition, physical I/O will occur each time a requested data page is not found in the<br />

data cache, and so needs to be first read into memory from the underlying disks. Logical<br />

I/O is a less expensive operation than physical I/O, so the DBA will want as many queries<br />

as possible to be served from the cache. This often means having as much RAM as can<br />

be afforded, up to and perhaps slightly over the amount of data on the server. However,<br />

this is frequently an unrealistic proposition. Even medium-sized organizations can store<br />

hundreds of gigabytes of data, and their appetite for data is growing rapidly. While RAM<br />

costs start out cheap, we aren't likely to have terabytes of cheap RAM any time soon.<br />

While the focus of this chapter is disk (i.e. physical) I/O, it's worth remembering that<br />

logical I/O, while cheaper, is far from free. Logical I/O occurs when a data request (read)<br />

can be satisfied by serving up a page residing in memory, in the data cache. Writes are also<br />

first written to the data cache, before later being written to disk. If your query workload<br />

results in unnecessarily high logical I/O, then your performance will suffer. The best way<br />

to ensure that as many data requests as possible are served from memory is to avoid all<br />

unnecessary I/O. This means tuning the query workload so that each query returns the<br />

minimum necessary data, reads the data as few times as possible, and uses solid, set-based<br />

logic to manipulate the data set.<br />

One of the most effective ways to minimize both logical and physical I/O is to create an<br />

appropriate set of indexes, as discussed in Chapter 5. A scan of even a moderately-sized<br />

table could easily result in reading 100,000 pages, even if you only need to return a small<br />

219

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!