I’ve just finished 3 chapters for an upcoming Wrox book called Professional SQL Server 2005 Performance Tuning: http://www.amazon.co.uk/Professional-Server-2005-Performance-Tuning/dp/0470176393/ref=sr_1_11/202-3946698-6401428?ie=UTF8&s=books&qid=1191700832&sr=8-11
I joined the author team late so my picture’s not on the cover pic yet. I know its vain but I can’t wait J
Anyway, what I wanted to post on was a section I wrote on Disk Sector Alignment. It seems to be one of those things that you've either been doing for years or you've never heard of. When I left Microsoft some of the guys were trying to get something published “officially” but I don’t know how much interest they managed to get. I've been meaning to blog on it for ages...
Sector Alignment
Sector Alignment is a little known performance optimization tip that documented for Exchange here: http://technet.microsoft.com/en-us/library/aa998219.aspx (but not very well described) and is equally valid for SQL Server. There are a few blog postings that try to measure the performance difference for SQL Server but why it can cause a problem is not detailed very well. It should be performed on any NTFS partition that is created on a RAID array to “avoid misalignment with stripe units and caching which can cause performance degradation”. Let’s look in a bit more detail about what that actually means.
First of all, some disk terminology. What you’re interested in for the purpose of explaining sector alignment are sectors, tracks and blocks.
* A sector is the smallest unit of storage space on disk and is typically 512 bytes.
* A track is the circular path of sectors that sit around a single circumference of the disk. There are 63 sectors per track numbered 1-63 on each track.
* A block is how you usually refer to sectors to make things easier for you. You start at the beginning of the disk and increment until the end of the disk. Blocks start from 0.
Partitions always start at the first sector on a track, so for the first partition that means Track 2 Sector 1 (because the MBR is on Track 1), which equates to Block number 63 (blocks start from 0). Misalignment occurs because the storage vendors define tracks differently. On an EMC Symmetrix, for example, a track is considered to be 64 blocks and the cache is also based on this.
A Symmetrix DMX RAID5 array uses a stripe size of 4 tracks, which totals 256 blocks. 64KB is the largest single write that Windows can make, so using the default partition location means that the first 64Kb write will be fine but the second will straddle 2 “stripes” causing both to be updated.
If you align the partition to 128 blocks (or 64KB as each block is 512bytes) then you don’t cross a track boundary and therefore issue the minimum number of I/Os.
There are 2 methods of aligning your partition and you’ll be pleased to know that it’s quite a simple process. Diskpar is a tool that’s been available for a while to enable you to align partitions but as of Windows 2003 SP1 the preferred method is Diskpart (note the extra ‘t’). The main difference between the two methods is that you specify the alignment value in blocks using Diskpar and in KB using Diskpart.