The Benefits Of Virtual Machines
Created: 20 January 2008
Virtual machines have been around for a long time but they really have not become
common place in many development shops. It is unfortunate since virtual
machines provide so many benefits to developers and testers alike. This
article will discuss some of the benefits of virtual machines and review two of
the most popular virtual machine software packages available for Windows.
A Virtual Machine?
A virtual machine, simply put, is a virtual computer running on a physical
computer. The virtual machine emulates a physical machine in software.
This includes not only the processor but the instruction set, the memory bus,
any BIOS commands and critical machine hardware such as the system clock and and
DMA hardware. Depending upon the machine peripheral devices are generally
virtualized including storage devices like floppy drives, hard drives and CD
drives. Video, keyboard and mouse support are also common. A virtual
machine must look and act just like the real thing so standard software, like
operating systems and applications, can run without modification.
Emulation software (the term we will use for applications that create and run
virtual machines) generally define a basic machine to emulate rather than
supporting a wide variety of devices. This reduces the amount of work that
must be done and keeps things simple. For Windows-based emulations you can
expect a Pentium 4+ processor with basic SCSI and/or IDE drive support, floppy
disk and basic CD/DVD reading along with all the required hardware. This
is enough to run most applications. So even if you are running a
multiprocessor non-Intel processor the virtual machines will still see a Pentium
4. The emulation software is responsible for mapping the virtual devices
back to the real devices, when appropriate. For example writes to the
virtual hard drive must be written to the backing file for the drive.
Emulation software generally allows for some manipulation of the virtual devices.
At a minimum this would generally include how much memory to make accessible to
the virtual machine, how many (and how large) the hard drives are, whether sound
cards or ports are available, etc. These virtual machine settings are
generally stored in a custom file by the emulation software. Additionally
the virtual hard drives are also generally stored as files. These files
can get really large since they are emulating a real computer.
In emulation software the machine running the virtual machines (in our case
Windows) is known as the host. The virtual machine itself is known as the
guest.
Why Does It Matter To Me?
So what does this mean to developers and testers. Let's look at a few
scenarios that developers and testers find themselves in. For testers it
is important that they test software against the various supported operating
systems that an application runs against. The traditional approach is to
run multiple physical machines, each with a different operating system.
This is bad for several reasons. Space, maintenance, power and feasibility
come to mind. Deployment of the software to these various machines can
also be an issue. Instead a tester can run multiple virtual machines on
one physical machine. Each virtual machine could have a different
operating system. The application can be deployed to the virtual machines
and tested.
Another advantage of virtual machines is reproducibility. Build and test
environments generally need to be well controlled. It would be undo work
to have to wipe out a machine and rebuild it after each build or test run.
A virtual machine allows the environment to be set up once. The
environment is then captured. Any changes made after the capture can then
be thrown away after the build or test run. Most emulation software
packages offer this in some form or another.
Another scenario, your application is currently released as version 1.
Because of how the application is written you can only run a single version of
your application on a machine. When you start development on version 2 you
have to remove version 1. Part way through development an issue is found
in the version 1 software that you need to replicate and fix. You can
uninstall version 2 and install version 1, find and fix the issue and then
revert back but that is a lot of work. A nicer approach is to have a
virtual machine with version 1 installed. When you need to go back to
version 1 you just start up the virtual machine. Even better is that you
can easily compare the behavior of the two versions side by side rather than
having to switch between two computers.
IT departments have already found the benefits of running virtual servers over
having multiple physical servers. Development and testing share many of
the same benefits. Virtualization has become a buzzword in the industry.
Windows is becoming more virtualized so even if you aren't using virtual
machines today you may be in the future.
Which Emulation Software Is Best?
You have decided to try virtual machines out. Now which software to use?
Fortunately, or perhaps not, there are not too many options available. Each
have their strengths and weaknesses. First we'll give a brief overview of each
and then we'll compare them by looking at features important to good emulation
software.
Microsoft Virtual PC
Version used: Virtual PC 2007
Website: http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx
Microsoft purchased Connectix many years back for their virtual machine software.
They rebranded it Microsoft Virtual PC (VPC). There have only beeen two
versions: 2004 and 2007. It comes in either PC or Server edition but we
will only talk about PC.
VPC is the primary mechanism by which Microsoft deploys demo and beta products to
customers. They generate VPC images that can be downloaded and run.
If you do a lot of beta testing for Microsoft then VPC will be a requirement.
VMWare Workstation
Version used: VMWare Workstation 4.5.2
Website: http://www.vmware.com
VMWare has been around for years (since at least the 90s). As with VPC there are either workstation or server editions but we will restrict ourselves to the workstation edition.
A nice feature of VMWare is that it can run, albeit with a reconfiguration, VPC images as well. Once you load it into VMWare though
you will no longer be able to use it in VPC.
Qemu
Version used: Qemu v0.9.1
Website: http://fabrice.bellard.free.fr/qemu/
I have
little experience with Qemu so I will not review it here. It's biggest strengths
are that it is open source, free and can emulate non-Intel processors. Its
weaknesses include it is not as stable or easy to use as the other products and
it does not perform as well, in my experience. It is command-line driven
although there are some addins that give it a user interface. It is
definitely something to watch for down the road.
Feature Comparisons
A caveat is in order before we discuss the features. I used VMWare for many
years in the 90s. I loved all the features it had. When I switched
jobs my new employer would not justify the cost of virtual machines. At
the same time I received a complimentary copy of VPC. I used VPC for
several years since I did not own a copy of VMWare anymore. Beyond 64-bit
support I could not justify the cost of VMWare. Recently VMWare was nice
enough to give me a complimentary copy of VMWare and I now run both versions, at
least for now.
Cost
VPC: Free
VMWare Workstation : $199
For some shops cost does not matter but for many it does. $200 is not much
money for software but for single developers, like myself, it can be hard to
justify free for most situations. VPC wins here. However it is
important to note that VMWare has a program called VMWare Player that
allows you to run virtual machines. It is free but does not allow for
configuration changes.
Performance
Running a virtualized machine on top of a regular machine is going to be slower
in most cases. Therefore performance of both the guest and host are
important. Virtual machines make heavy use of the processor, memory and
hard drive space. A host system must have a really strong processor
(preferably multiprocessor), a lot of memory and a lot of fast hard drive space
to get good performance out of a guest.
VPC and VMWare both run about the same in my experience. VMWare has a slight
performance advantage when running guests when certain device options are set
(discussed later) but otherwise they both run really well. VMWare also seems to
shut down guests faster than VPC. However VPC handles undo faster.
In this category they are basicaDevice Support
Common: Pentium 4, SCSI and IDE drives, CD/DVD drive, network cards, SoundBlaster
card, SVGA
VPC: --
VMWare: USB devices, multiple processors, 64-bit processors
VMWare has superior device support to VPC. Beyond support for USB devices
attached to the host machine VMWare also supports emulating a 64-bit processor.
This is a fundamental feature that may sway many people to VMWare. 64-bit
processors have been around a while. Many people are running 64-bit
versions of Windows as a host. It is therefore logical that people will
want to run a 64-bit guest machine. Only VMWare can do that at this point.
Without question VMWare wins device support.
Operating System Support
VPC: DOS (unsupported), All versions of 32-bit Windows except servers (Servers
work but are unsupported), OS/2 Warp (certain versions), Others (unsupported)
VMWare: DOS, All versions of 32/64-bit Windows, most variants of Linux and
FreeBSD
VPC and VMWare support basically the same operating systems. If it runs
under the virtualized hardware then it will run. Non-Windows operating
systems are unsupported, but work, in VPC. OS/2 Warp is documented as
supported with VPC but I have never gotten it to work properly. To be fair
I have never gotten it to work under VMWare or Qemu either.
The big point here is that, since VMWare emulates a 64-bit processor, you can run
64-bit operating systems. Therefore VMWare takes the win here just for
that. Running a 64-bit guest under 32-bit host can solve many issues when
trying to migrate from 32 to 64-bits. I run this way quite a bit and it
works well.
Cloning Support
Both VMWare and VPC support cloning of existing virtual machines but in different
ways. Cloning is important when you want to set up multiple guests with
the same, or similar, environment. Installing an operating system is time
consuming. With cloning you can set up the environment once and then reuse
the environment in different guests. To understand the differences between
VPC and VMWare's approaches you must understand how cloning works.
The simplest approach to cloning is simply copying the virtual machine directory
and doing a little renaming. This works in both VPC and VMWare.
VMWare actually detects this and offers to make a few adjustments. While
doable this is not the best approach because it wastes a lot of space,
especially if the cloned guest does not change much. We will not refer to
this approach anymore.
The better approach is to difference a base image. With differencing only the
changes made to a guest are stored. With differencing the amount of space a
clone takes is less because it only tracks the changes. However it needs the
base image to run properly. Even more important though is that the base image
cannot change without invalidating the clone.
VPC supports cloning but it is not directly obvious how to do it. Basically
you would set up a new virtual machine with a regular virtual drive. You
would then create a new virtual drive. Within the wizard is an option to
create a differencing disk (off an existing virtual drive). Replacing the
original virtual drive created when the virtual machine was created with the new
virtual drive results in a clone. While not obvious, it works.
VMWare does basically the same thing but it exposes these options easily within
the main UI. The clone option is exposed for each virtual machine.
When you select this option you can chose to do a differencing clone or a full
copy. As with VPC this creates a brand new virtual machine.
For easy of use VMWare wins here but otherwise both products are identical.
Undo Support
Along the same lines as cloning is undo support. After you've made changes
to a guest it is sometimes important to undo those changes. Without direct
undo support you would have to resort to cloning. Both VPC and VMWare
support undo.
VPC exposes this as an option in the virtual machine settings. By default
it is disabled so all changes made to the guest are permanent. When undo
support is enabled VPC tracks the changes made for the current session in a
separate file (a difference disk again). When the session finally ends VPC
asks if you want to save the changes permanently, save them for later or throw
them away. If you decide to save the changes permanently then VPC will
merge the differences in. This can take up to 10 minutes. If you opt
to save the changes until later then the differencing disk is retained.
When the session starts again you will be able to resume from where you left
off. Finally if you decide to throw away the changes then the differencing
disk is deleted.
VMWare does things differently. VMWare uses snapshots instead. With
snapshots VMWare basically uses differencing disks for each snapshot beyond the
first one. Unlike VPC it does not prompt after you close a session.
Instead you snapshot the guest when you want and it tracks changes from there.
Another advantage of snapshots is that you can have multiple versions.
With VPC you have the base image with or without changes. With VMWare you
have the base image along with any number of snapshots containing changes.
For simple undo support VPC wins here but if you want multiple variants then
VMWare is the winner. Personally I cannot decide which is better.
Host-Guest Communication
Another critical area for emulation software is how well it integrates the guest
and the host. At a minimal the guest must be able to transfer files to and
from the host. VPC and VMWare both support this but in different ways.
VPC allows you to identify one or more folders on the host machine to be exposed
to the guest. Each folder is exposed as a separate drive to the guest.
Whether the folder is exposed each time the virtual machine restarts or not is
optional. The guest can have read-only access, if desired.
VMWare also allows you to identify one or more folders on the host machine to be
exposed to the guest. However VMWare exposes all the folders as subfolders
of a single network folder. As with VPC the folders may or may not be
writable and can be persisted or not.
Which approach is better depends upon your preferences. I personally prefer
vPC's approach of using separate drives. While you are limited to 26
shared folders they all look like drives. With VMWare's network folder
approach the drives are accessed using UNC paths. For some applications,
like .NET, this introduces problems. For .NET security of a network
application is different than a local application.
Another host-guest communication features is copying and pasting. It is
very common to want to copy something (other than a file) from the guest to the
host or vice versa. Both VPC and VMWare support copying and pasting using
the clipboard from/to the guest. This is optional in both products but
should generally be left enabled.
Finally there is actually getting to and from the guest. VPC creates a
separate window for each guest. To give control to the guest you need only
move the mouse within the window and click (by default). To
return control to the host a keystroke is used. If a certain keystroke is
pressed while inside the guest the Ctrl+Alt+Del key sequence is generated.
If you accidentally press Ctrl+Alt+Del while the guest is active then VPC will
intercept it and let you know, although the host will still receive it as well.
VMWare follows a similar approach in that moving the mouse within the window and
clicking will give the guest control. It also uses special keystrokes to
send the special Windows keystrokes and detects if you press them while inside
the guest. What is different is that VMWare uses a single, tabbed window
to house the virtual machines. Each guest gets its own tab. Within
the tab you can see either the guest window or the configuration window.
Additions
Each emulation software has tools that it can install into the guest. These
additions generally include optimized video and network drivers and support for
the host-guest communications. Neither product has an advantage here.
VMWare supports an interesting features that VPC lacks. VMWare can install
a Visual Studio addin. This addin allows you to debug code on the guest
directly rather than relying on remote debugging. For developers this is
an excellent feature.
|