views:

30

answers:

2

Let's say I have a piece of code that runs fine on an OS. Now, if I install that OS on a virtual machine (server virtualization), and run that code on that, is it possible that the code behaves differently?

If so, what are the prerequisites for that? For example, does it have to be compiled machine code (in other words, are interpreted languages safe?)? Does it have to be certain OS instructions? Specific virtualization technology (Xen, KVM, VMware..)?

Also, what are the possible different behaviors?

+3  A: 

Yes. Like any machine, the virtual machine is just another computer (implemented in software instead of hardware).

For one, lots of commercial apps will blow up when you run them on a VM due to:

  1. copy protection detecting the VM
  2. copy protection rigging your hardware, using undocumented features of BIOS/Kernel/hardware

Secondly, a VM is just another computer consisting of hardware implemented in assembly instead of circuits/dye/microcode/magic. This means the VM must provide the emulated hardware either through pass-through or emulation. The fact that hardware is very diverse can cause all kinds of different behavior. Also note the possible lack of drivers for or acceleration of the emulated hardware.

But of course a typical business application for example isn't nearly as likely to rely on any hardware details as all it does is call some GUI API.

Interpreted languages are only safe from this to the extent that they are "interpreted", if the interpreted language calls out to some native code, all this is possible again.

For an example of something detecting that it's running under a VM, check this, it's just one of the literally thousands of ways to detect the VM.

Longpoke
A: 

In theory the program should run exactly the same as on a physical machine.

In practice however, there may be differences due to

  • Machine\OS configuration and drivers
  • Load of the virtual machine host.

Differences in machine configuration are similar to difference you would see between any difference physical machine. Depending on how critical you application is to the end user, you should run the same set of tests that you would a physical box to determine whether the environment is acceptable for use.

Depending on the virtualisation technology, the host may not have the ability to guarantee the client resources at specific times. This can lead to weird behavior on the client. Potentially you would see more occurrences of application errors due to IO timeouts an starvation of memory.

To successfully virtualise an application for production use you need to do a bit of work to understand the resource profile of the application\client and virtual host.

Adrian Russell