A virtual machine is an application that emulates a whole computer and runs inside your physical computer. It works as a separate independent machine, but it runs as a process on your host operating system. It’s a convenient way to dedicate a portion of your computer resources to a specific task or software.
Virtual machines are used to dedicate a portion of a host’s resources to a specific task. This machine will run in an isolated environment without any risks of conflicting with the host. If the guest virtual machine crashes, it can be rebooted or recovered without impacting the host.
This article will cover what virtual machines are, and when they should be used, in greater detail.
A virtual machine is a complete operating system and any installed applications running as a process in a physical computer. A hypervisor is used to dedicate a portion of the physical hardware to the virtual machine, allowing this guest machine to run like any other application on the host computer.
Physical machines use a hypervisor to virtualize hardware available to virtual machines.
The virtual machine itself runs as if it was running on its own independent hardware, and is not aware that it is running on virtualized hardware.
There are many reasons to use virtual machines. On a personal computer, you can use a virtual machine to run software that requires a different operating system than the one running on the host computer. This way, a user running a laptop with a Linux OS would be able to run games built for the Windows OS.
For businesses, you can use virtual machines to perform operations that would otherwise be dangerous or risky. For example, a system administrator could try running a virtual machine with a new version of Linux to validate that the web servers used by the enterprise can run without any bugs that would cause service interruptions.
Virtual machines are prevalent in the cloud computing industry. These VMs allow system administrators to take large servers and separate them into smaller entities that cloud providers can then rent out. This has the advantage of isolating any content running in the virtual machine from the physical server. As an example, MongoDB runs tens of thousands of VMs across AWS, Azure, and Google to offer MongoDB Atlas, a database-as-a-service that comes with built-in automation and operational best practices so developers don't have to worry about managing VMs themselves.
Virtual machines are generally classified into two different types: system virtual machines and process virtual machines.
When people use the term "virtual machines," they’re generally referring to system virtual machines, also called full virtualization VMs. A system VM is an entire operating system that runs on virtual hardware inside a host computer. You must use a hypervisor, a software that creates and runs VMs, to allocate resources to the system virtual machines.
A process VM, or application VM, is an abstraction layer that enables code written in a specific programming language to run on any operating system. Popular examples include the Java Virtual Machine and the .NET framework, which use the Common Language Runtime.
Virtualization is the process of taking one or more components of a computer, such as CPUs, RAM, and storage, and tricking a piece of software into thinking those components are their physical counterparts. When discussing virtual machines, we usually refer to an entire computer being virtualized, but many components can be individually virtualized.
Virtualization can take multiple forms but falls under five main types.
Virtual machines can be used whenever you need a different operating system to run an application. A mobile app developer, for example, might want to test out their application, but their computer may be running a Windows operating system. To test out the mobile app, the developer can use a virtual machine running Android OS.
Another everyday use case for virtual machines is to run software in an isolated environment. A duplicate of the production environment can be created to test out a new version of a software application in development. A QA team can then perform tests without conflicting with the actual production environment.
Using virtual machines can provide some advantages over a physical computer. It generally does a better job at managing resources, lowering the overall costs. On the other hand, it also comes at a cost in performance.
Virtual machines are great for splitting physical resources to be used by smaller virtual computers. Instead of having computers with largely unutilized resources, it is possible to distribute the CPU and RAM across multiple virtual computers. When done properly, this can significantly reduce the cost of infrastructure.
Virtual machines can also be part of server provision programs. Because virtual machines are stored on a hard drive, it is easy to copy them to recreate identical environments over and over.
Finally, the isolation provided by the virtualization can let system administrators run riskier operations in a virtual environment that can easily be thrown away.
The main disadvantage of running virtual machines is the performance cost. A VM is slower than a physical machine because it needs to run a host operating system and a hypervisor in the background. This performance hit is especially true when compared to containers.
All major cloud providers offer virtual machines that you can use for personal or business use cases. If you are looking for a virtual machine to run a MongoDB database, MongoDB Atlas abstracts the process of creating a dedicated cluster on virtual machines so that developers don’t have to manage them.
If you would instead prefer to run a virtual machine on your personal computer, many software applications, such as VirtualBox, can help you set up and run virtual machines.
Virtual machines can be a convenient way to manage large clusters of computers, but they also come at a certain performance cost. This is why most enterprises managing large infrastructures will use a mix of physical and virtual machines based on their use cases. If you don’t want to manage your own virtual machines, MongoDB Atlas makes it easier for you to create, run, and manage your cloud-based databases.