My Resume | Contact Me | RSS Feed | Follow Me on Twitter

Code Capers

The Ninja Coding Dojo
RSS Feed Twitter Email

How To Dual Boot with Windows 7 and XP

clock August 31, 2009 by author Michael Ceranski

I am sure by now, that everyone has heard about XP Mode in Windows 7. If not then read this post. Anyway, the one thing XP mode is not good for, is gaming. This is primarily due to the fact that you are running an entire VM in the background (transparent to you) and viewing the application in a RDP window. If you have ever tried to do anything that is graphic intensive over RDP then you know that the performance is horrible. That is the reason that I decided to dual boot my machine with Windows 7 and XP.

Dual booting can be a scary thing. I am warning you up front that configuring a dual boot system can be a long and painful process. Playing around with your boot loader is a quick way to hose up your entire machine. Therefore, if you are not comfortable with the risk then stop reading this article now.

OK, so you are still reading this post, then you are either brave or slightly insane. In any case, here are the instructions:

  1. Start by installing Windows 7 on your desktop.
  2. When Windows 7 is finished you can launch Disk Management. Disk Management  is a built-in utility that can shrinking and expanding partitions and it does not require any 3rd party utilities. To manage your partitions, open Control Panel and type "partitions" or "hard disk" in the search bar on the right corner and you can see the link "Create and Format Hard Disk Partitions" under administrative tools. Alternatively you can use a third party tool like the gparted Live CD if you are more familiar with it.
  3. To shrink a volume, right click on the desired volume and select the Shrink Volume option. This will open up a window and you will need to specify the amount of space to shrink in MB. For my install I entered a value of 30,000 MB or 30 GB.  Hit the Shrink button to start the process.
  4. You should now have two partitions on your disk. Now we can reboot the machine and start the XP install.
  5. Once you finish installing XP you will notice that you will no longer be able to boot into Windows 7. Don't Panic. You just need to restore the bootloader. In order to simplify this task you will need to download EasyBCD.  Easy BCD will allow you to restore your Windows 7 boot entry and also add the XP boot entry as well. However, EasyBCD requires .NET framework 2.0 so you may need to install that first if you do not have it on your XP machine.
  6. After, you launch EasyBCD go to the Add/Remove Entries tab and add a new entry for the XP Install. Make sure the type is Windows NT/2k/XP/2k3. Select the drive and click
    Add Entry
    , followed by Save



    If you installed both operating systems on the same disk but in different partitions then leave the drive letter at C:. This threw me off the first time I did it but luckily I was just able to go right back into Windows XP and fix the mistake. Apparently the dialog is asking where the boot loader is installed and not where the OS is installed.

  7. Finally, go to the Manage Bootloader tab and select the option to Reinstall the Vista Bootloader, click Write MBR and restart the system.

  8. If you followed the steps correctly you should be dual booting!

BTW...the steps for dual booting Windows 7 and XP are the same for Windows Vista and XP.

References:

APC Magazine - How to dual boot Vista and XP (with Vista installed first)
TechSpot - Dual Boot Windows 7 with XP/Vista in three easy steps



How Many Spindles Do You Need?

clock August 27, 2009 by author Michael Ceranski

I am currently working on a project where we are trying to figure out our storage architecture for one of our enterprise systems. One of the biggest challenges is trying to figure out how many spindles we need in order to support our OLTP system. I found a blog post by Bruce Spencer from IBM who had an interesting formula for calculating the spindle count. Although the algorithm has some built in assumptions I found it interesting enough that I wanted to share it with you...

 

IOPS (I/O's per Second)

Data Transfer Rate (MB/sec)

Min # of Disk Drives to Support Workload

Random I/O (10k RPM) 125 0.5 n = (%R + f (%W))(tps)/125
Random I/O (15k RPM) 150 0.5+ n = (%R + f (%W))(tps)/150
Sequential I/O 2000 50 n = (MB/sec)/50

Where:

%R % of disk I/O's that are reads.
%W % of disk I/O's that are writes.
f 1 for ordinary disks, 2 for mirrored disks, 4 for Raid 5 disks.

Using the above formula, here's the minimum number of disks required to support a random I/O workload, at 1000 IOPS, 80% read, 20% write on 10K RPM disk drives.

Ordinary disks: (0.8 + 1*0.2)(1000 IOPS)/(125 IOPS/disk) = 8
Mirrored disks: (0.8 + 2*0.2)(1000 IOPS)/(125 IOPS/disk) = 10
Raid 5 disks: (0.8 + 4*0.2)(1000 IOPS)/(125 IOPS/disk) = 13

 

If you are lazy...

% Reads: The percentage of disk I/O's that are reads.
Target IOPs: The total number of IOPs you need to support.
Disk RPMs: I/O's per Second or iostat "tps"
RAID Level:


Finally, I will throw my two cents in regarding this topic:
  • These formulas will give you high level estimate. They are based on assumptions and you should not use this as the only source of information for your storage solution. If you are upgrading a current system then gather as much data as you can so you can establish a benchmark. Then you can make predictions based on how your company utilizes the system instead of some fictitous numbers produced by a vendor.
  • Do not fix software problems with hardware. If you have a batch process that takes 10 hours, is it really due to a poorly performing I/O subsystem or is it bad code?
  • If you need performance think throughput and not capacity. To accomodate a system that requires a high amount of I/O you will need to buy large amounts of small disks.

Admittedly, I am not an expert on storage. It is something that I am trying to learn more about but I do not have a lot of first hand experience with. If you are an expert then I am very interested in hearing your opinions on this topic. Please comment!



How to Setup Database Mirroring

clock August 25, 2009 by author Michael Ceranski

I have known about SQL database mirroring since SQL 2005 SP1. However, I never really had an occasion to use it until recently. I figured while I was setting it up that I would document the steps in case someone else needed them later on. In my particular case, I setup database mirroring in high performance mode with no witness. Therefore the steps below are specific to my needs. However, they can be slightly modified to accommodate other mirroring modes:

Pre-requisites

  • Check to see if the servers participating in mirroring are running under the same service account. If not you will need to add theservice account for the principal server as a sysadmin on the mirror instance and vice versa.
  • Make sure the instances are running the same edition and patch level of SQL Server. This can be checked with the SQL Statement: select @@version
  • Also make sure that your instance supports database mirroring. For more information review this MSDN article

How to Setup High Performance (asynchronous) Mirroring with No Witness

  1. Principal Instance - Put the database you want to mirror in FULL recovery mode.
    For example:
       1:  BACKUP DATABASE AdventureWorksLT2008 
       2:  TO DISK = 'c:\AdventureWorksLT2008.bak'
       3:   
       4:  BACKUP LOG AdventureWorksLT2008 
       5:  TO DISK = 'c:\AdventureWorksLT2008.trn'
  2. Copy the backups you made on the Principal Instance to the Mirror Instance
  3. Mirror Instance - Restore the database and log with the NORECOVERY option
       1:  RESTORE Database AdventureWorksLT2008 
       2:  FROM DISK = 'c:\AdventureWorksLT2008.bak'
       3:      WITH MOVE 'AdventureWorksLT2008_Data' TO 'E:\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorksLT2008.mdf',
       4:      MOVE 'AdventureWorksLT2008_Log' TO 'E:\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorksLT2008.ldf',
       5:  NORECOVERY
       6:   
       7:  RESTORE LOG AdventureWorksLT2008
       8:      FROM DISK = 'c:\AdventureWorksLT2008.trn' 
       9:  WITH NORECOVERY
  4. On the Principal Instance right click on the database you are going to mirror and select Tasks  Mirror...
  5. Click on the Configure Security... button. This will launch the Configure Database Mirroring Security Wizard.
  6. Click the Next button on the initial screen. On the Include Witness Server dialog select No
  7. On the Principal Server Instance dialog leave the default and click Next
  8. On the Mirror Server Instance dialog enter in the name of the server where you will be mirroring to. Click the Connect... button. Leave the port and endpoint name with the defaults and click on the Next button.
  9. Enter in the names of the accounts used to mirror the data. Since we have a domain I would recommend leaving these boxes empty. Click the Finish button.
  10. If everything goes well you should see a dialog box documenting the different endpoints and mirroring configuration. Click on the Do Not Start Mirroring Button. This way we can review the settings before we start mirroring.
  11. Change the operating mode to High performance (asynchronous)
  12. Click on the Start Mirroring Button. After a few moments you should see the status change to "Synchronized"

Related Resources:



Installing Windows 7 from a Thumb Drive

clock August 24, 2009 by author Michael Ceranski

It is common these days for a computer to ship without a DVD drive, especially when you are dealing with netbooks and laptops. Most of the time this isn’t a problem. You can usually get around these shortcomings by sharing a DVD drive as a network share or by using a virtual DVD drive such as Virtual Clone Drive. The real problem occurs when you need to install a new operating system such as Windows 7. This is when you have to resort to other measures such as booting from a USB thumb drive.

  1. Download the image file for Windows 7 and extract it to a folder using either WinRar or 7-zip. Currently the Windows 7 RTM release is available to TechNet and MSDN subscribers.
  2. Verify that your thumb drive is big enough to hold the Windows 7 image.
  3. Format your thumb drive using NTFS. This can be done by right clicking on the drive in my computer and choosing the Format… option. Once the dialog appears choose the NTFS file system and make sure the Quick Format option is checked.
  4. Navigate to the boot folder in the Windows 7 directory that you extracted in step 1 and look for the file named bootsect.exe. Copy this file to the c: drive on your computer.
  5. Open a command prompt. If you are using Windows Vista then make sure you run the command prompt as an administrator. Once the command prompt is ready, switch to the c: drive and enter in the command bootsect /nt60 <thumb drive drive letter>. For example, if your thumb drive is letter e: then the command would be bootsect /nt60 e:. This will make your thumb drive bootable.
  6. Copy the Windows 7 files to the thumb drive.
  7. Reboot your computer and hopefully you should see the Windows 7 installation menu. If you do not see the menu they you may need to modify your BIOS settings so the thumb drive can be seen as a bootable device.

That's it! Only 7 steps to install Windows 7 from a thumb drive. Wow, weird coincidence!



SQL Performance Tuning Basics

clock August 17, 2009 by author Michael Ceranski

Once you start developing enterprise scale applications you will start to notice that things perform a little bit differently. Dealing with VLDBs (Very Large Databases) force a developer to learn about performance tuning. Therefore, I thought it would be good to outline some of the high level perfmon counters for those developers out there who are new to SQL Server.

Memory Related

Buffer Manager: Buffer Cache Hit Ratio - This is easily one of the most recognized counters in the world of SQL performance tuning. This counter indicates the percentage of data pages found in the buffer cache as opposed to disk. A value of 95% indicates that pages were found in memory 95% of the time. The other 5% required physical disk access. A consistent value below 90% indicates that more physical memory is needed on the server.

If you are using SQL 2005 and above then you can also capture Buffer Cache Hit Ratio using the DMVs. This could be useful if you want to store values in a table and then graph the results.

   1:  SELECT (a.cntr_value * 1.0 / b.cntr_value) * 100.0 [BufferCacheHitRatio]
   2:  FROM (SELECT *, 1 x
   3:       FROM sys.dm_os_performance_counters
   4:      WHERE counter_name = 'Buffer cache hit ratio'
   5:        AND object_name like '%:Buffer Manager%') a
   6:  JOIN
   7:    (SELECT *, 1 x
   8:    FROM sys.dm_os_performance_counters
   9:      WHERE counter_name = 'Buffer cache hit ratio base'
  10:        AND object_name like '%Buffer Manager%') b
  11:  ON a.x = b.x

Buffer Manager: Page Life Expectancy - This counter can be helpful in determining whether you have a memory problem, giving you a reasonably accurate view of whether your server has memory pressure. According to Microsoft, 300 seconds is the minimum target for page life expectancy. If the buffer pool flushes your pages in less than 300 seconds, you probably have a memory problem. Looking at this value is particularly handy when your page life expectancy is significantly higher or lower than 300 seconds. In order for this counter to be useful, you should watch this value over time. 64 bit servers with a large amounts of memory that serve high transaction databases can have extremely high values for page life expectancy. On servers with significant load a value of 300 would be considered low.

I/O Related

Logical Disk: Disk Reads/ sec & Logical Disk: Disk Writes/ sec - Microsoft recommends that the average latency on a disk drive should be 20 milliseconds or less (.020 seconds). However, I typically follow the recommendation of 20 ms or less for data and 10 ms or less for logs.

There is a test which you can run to see how fast you can read the database. This is done by using the Backup to NUL trick. Basically this script backs up the database to "never-land" but it reads each page of the database during the process.

   1:  backup database <db name> to disk = 'NUL:' with stats = 10

Sample output:

Processed 132776 pages for database 'DBA', file 'DBA' on file 1.
100 percent processed.
Processed 1 pages for database 'DBA', file 'DBA_log' on file 1.
BACKUP DATABASE successfully processed 132777 pages 
in 7.968 seconds (136.509 MB/sec).

Two of the most common causes of high latency are partition alignment or improper disk configuration. For more information about Disk Partition Alignment please read this whitepaper. Disk configuration issues tend to be a little more tricky but I can offer some very high level suggestions:

  1. Plan for I/O throughput and not capacity. Make sure you have enough spindles.
  2. Separate the data, logs and tempdb. Create as many tempdb files as you have processors.
  3. Try to separate sequential I/O from random I/O onto different spindles.
  4. Pick good initial sizes for your data and log files. Auto-growth is an expensive operation and it is also prone to fragmentation.

CPU Related

SQL Statistics: Batch Requests/sec - This counter measures the number of batch requests that SQL Server receives per second, and generally follows in step to how busy your server's CPUs are. Generally speaking, over 1000 batch requests per second indicates a very busy SQL Server, and could mean that if you are not already experiencing a CPU bottleneck, that you may very well soon. Of course, this is a relative number, and the bigger your hardware, the more batch requests per second SQL Server can handle. From a network bottleneck approach, a typical 100Mbs network card is only able to handle about 3000 batch requests per second. If you have a server that is this busy, you may need to have two or more network cards, or go to a 1Gbs network card.

SQL Statistics: SQL Compilations/sec - The number of times per second that SQL Server compilations have occurred. This value needs to be as low as possible. If you see a high value such as over 100, then it’s an indication that there are lots of adhoc queries running. One way to identify adhoc or dynamic SQL is to look through your stored procedures for sp_executeSQL or exec() calls. You can do this with the following query:

   1:  select * from syscomments where text like '%sp_executesql%' or
   2:  text like '% exec%'

I would also recommend setting up unattended traces that capture queries over a certain read limit. The use a tool like Clear Trace to aggregate the data by average reads, average writes or CPU. This will allow you to focus on the worst performing queries first, which are typically the ad-hoc queries.

SQL Statistics: SQL Recompilations/sec - This needs to be as low possible. A recompile can cause deadlocks and compile locks that are not compatible with any locking type. These type of issue will generally drive up CPU utilization.

Finally, I want to end this brief introduction with a warning. All counters should be looked at over time. You can not simply go onto a server once over a five day period and notice that the Buffer Cache Hit Ratio is low and tell your system admin to purchase more RAM. Chances are that someone may running a bad query or doing something to the system that flushed the cache. You really need to observe your counters over time. People who give you specific values are just trying to give you a starting point. Every system is unique and you really have to get familiar with each environment to know what "normal" really is.

Related Resources:



About the author

MikeMy name is Michael Ceranski. I am a software developer from Buffalo NY. I have been writing code for over 10 years starting with Borland Delphi and later migrating to the .NET stack. I enjoy blogging about .NET, MVC and jQuery and I hope to spread my enthusiasm for technology by sharing my thoughts and ideas with you.

View my resume

Cumulus

This will be shown to users with no Flash or Javascript.

Sign in