Day 20 — CS Fundamentals December — Intro to Virtual Machines and Virtualization
The power of virtualization and virtual machines (and containers :P) is ruling the software world now a days, so it can’t be enough emphasized as to how important it is for a software engineer to know about the virtualization and the mechanics behind it.
So, this article is going to hit the topic.
Let’s dive in!
In 1960, IBM Mainframe was constructed and it was just used to work for single application at a time which led to a lot of wastage of resources and time.
Then, a support got added to it, which allowed multiple users to share the batch-oriented system.
Then, in 1980, the big technology “boom” came up which led to a spiked traffic for technology and that, in turn, led to incur high server maintenance costs, infrastructure costs, administrative costs, etc.
And that led to an alarming need for virtualization technology.
And finally, in the late 1990s, with the availability of the Intel’s high performant processors, computer researchers were able to research and play around with virtualization technology on their computers.
So, that led to the big rise of the usage of virtual machines and virtualization in general.
What is a virtual machine?
It is an emulation of computer. Yeah, it is just that. If you’re running a virtual machine on your computer, it would seem like you’re running another entire operating system as a software.
For example, if you’re running a Windows 8 image as a VM (virtual machine) on your Windows 10 computer, then it would seem as if that Windows 8 is running like a software on a separate window.
So, in this example:
- Windows 8 -> Guest OS (Virtual Machine)
- Windows 10 -> Host OS (over which virtual machines are running)
Why are virtual machines so cool?
Say, you have say 10 computational tasks to be performed and every task requires almost 5GBs of RAM.
And 5 of them are dedicated to run on linux and 5 of them are dedicated to run on Windows.
So, you can do one thing, that is,
- Buy 10 different computers
- Arrange a big place to keep those 10 computers.
- Assemble and fit those computers with each having, say 5 GB RAM, for performing the task.
- Install Linux on 5 of them, one by one
- Install Windows on 5 of them, one by one
- And finally, allocate the tasks to the rightful computers.
Now, this is extremely tedious. What if there were 1000 such tasks to perform.
So, to deal with that, enter “Virtualization”
With the power of Virtualization, you can do this entire thing under the umbrella of just one computer.
So, in that case,
- You need to buy just one computer, that’s it.
- That computer should have at least 50GB RAM because there are 10 tasks and each task requires 5GB RAM.
- Now, install “any” operating system on that computer as per your convenience.
- Then, just start 10 virtual machines — 5 Linux VMs and 5 Windows VMs.
- And each VM will have access to 5GB RAM from the host computer (having 50GB RAM)
- And then, you just have to allocate the respective task to the rightful VM just the same way you would have allocated it to a real computer
- And that’s it!
Now, just look at the benefits of using virtualization approach
- You just have to buy one computer, only one computer, no matter how many tasks are there to perform.
- No need to arrange a big place because the entire processing and tasks will be physically happening under one computer and that can be accommodated even in your bedroom.
- No need to separately install Linux and Windows on every VM. You just have to install it once, then you can copy and create clones of Linux VMs. So, this means, you can create even 1000s of Linux VMs by “manually” installing Linux just once and then, making a few more clicks.
- The electricity cost would be times 10 times less because instead of running 10 computers, you would be running just 1 computer.
- Managing the 10 VMs will be much easier, convenient, quick and reliable than managing the 10 different computers.
But how are the things like memory and stuff managed on VMs?
So, for making the rightful working of virtual machines possible, there is a thing called hypervisor which exists.
So, hypervisor is an agent which manages the entire virtualization lifecycle and functionalities of virtual machines. It is the middleman between virtual machines and host OS (and host hardware).
It deals with:
- Allocating right amount of RAM, processing power, storage and network to the virtual machines.
- Starting the virtual machine.
- Cleaning up resources after stopping the virtual machines.
- Ensuring isolation for non-conflicting working amongst the virtual machines.
- Management of virtual machines.
And many more.
One of the very famous hypervisors is “VMWare Workstation” which is just a simple software (and behind the scenes, a hosted hypervisor) with which you can, in a matter of seconds, create and start virtual machine on your laptop/computer.
It has a very friendly user interface which makes the spinning up and management of virtual machines very very easy at an individual level.
But what exactly happens behind the scenes of VMs?
=> The traditional way:
So, to explain that I’ll first of all simply explain how applications are run on normal un-virtualized computers.
It is called the pre-virtualization stage.
For that, let’s say, I have to perform two tasks:
- one task on linux
- one task on windows
So, with the un-virtualized approach, there would be two physical computers. One would run linux and hence, the corresponding task. Other would run Windows and hence, the corresponding task.
So, the steps are simple:
- Operating system is told to run the task/application
- Operating system spins up the binaries and libraries required by that task.
- Finally, it executes the respective task/application on it.
- Whenever, the task requires some certain amount of RAM or processing power, the operating system (windows/linux) is the one which provides it.
=> The cool virtualization way:
Here, the hypervisor gets introduced.
Here, everything is almost same,
- Whenever the task on a VM requires some RAM or processing power, natively, it would request its OS (Guest OS) for that.
- And the guest OS is going to talk to hypervisor about getting it the required amount of RAM and processing power.
- And then, hypervisor talks to the host OS about these hardware requirements and then, returns back to the guest OS with the provided resources.
- And finally, the guest OS provides the access for the hardware resources, to that task.
So, that’s how it works, behind the scenes!
Thank you for reaching till here!
I hope you got the idea and knowledge the article intended to convey.
If you liked the article, do give it some claps :)
Stay tuned for another article which is going to come tomorrow associated with some other interesting CS fundamental.
Email — firstname.lastname@example.org