Wednesday, 29 July 2015

Virtualization for Techies and Non-Techies

What is virtualization, really?

In this post, I will write about virtualization, its omnipresence, and its impact.

A First Example.

I am sure we all know about the Phantom from the comics. And we all know he stands for justice. He doles out punishment to the the wrong-doers, and evil bad persons. However, none of that is as interesting as the fact that his legend never dies. The readers of the comics are actually not put in a suspense about how this is accomplished. When the Phantom of current generation dies, his successors dons on the suit (Phantom Suit) to carry on the legacy. The antagonists of the comic are never able to figure out that in-spite of all their machinations, Phantom keeps coming back to take down their wicked designs. This is our first exposure to the virtual or in more sophisticated terms logical Phantom, who never dies being realized by every-day mortal, a physical human being, who just lives out life to its maximum expectancy. We see an interface of virtue virtualized, and the physical form which perpetuates the notion of continuity through generations.

So we see that attributes can be separated out from the entities. The logical is separated from the physical. And the virtual isolated from the real, to provide an illusion of continuity and capacity which is strictly not possible only with the real entity.

Another Example

From time immemorial mankind has engaged in commerce, which we can loosely define as some form of exchange. Prehistoric commerce was mostly a physical exchange. Commodities could be exchanged for other commodities: e.g 5 Apples for 8 Oranges. Commodities could be exchanged for services: e.g 1 bucket of rice for 1 day of labour. Services could be exchanged for services: e.g 1 day of working in the field for 1 hour of teaching martial arts. This was known as the barter system. It had its merits and it demerits. Commerce was possible but it was simply, not that convenient. What if I wanted apples and could teach you martial arts, but you had oranges and wanted to learn martial arts? So some form of token evolved to virtualize the barter system or physical-commerce. You could learn martial arts from me in exchange for equivalent amount of tokens that could be exchanged for the amount of apples I wanted. The assignment of the value to a unit of certain commodity or service, would depend on the demand-and-supply. The value of all things that can be exchanged therefore could be mapped to the number of tokens, which greatly simplified doing commerce. What I call tokens, is what is known in the modern world as money. If tokens are different, an exchange value for that has to be agreed upon, and this is known as foreign exchange or FOREX. Commerce today is synonymous with virtual commerce. E-commerce is a form which does not require a physical market-place. This can be seem as the virtualization of the physical shop or place of commerce.

Examples from Computer Technology

This point onwards, I will talk about how different physical components of the computer was virtualized.

Virtual Memory

One of the notable examples of virtualization is the concept of Virtual Memory. The computers execute programs from the RAM (Random Access Memory). The physical capacity of RAM is limited (typically 1GB, 4GB , 16GB etc.) What if the program size and the memory needed by the program itself (dynamic and static memory) exceeds that of the physical RAM? This is precisely the problem Virtual Memory aims to solve. The Virtual Memory provides an illusion of a memory of capacity many more times to the program (64GB of virtual memory as compasred to 512MB of RAM). This is achieved by the system providing a bigger address space to the process (running instance of the program), than the physical address space of the RAM. The Operating System's (OS) responsibility is to map virtual addresses to the physical addresses of the RAM. What about the other chunks of virtual address space? They are simply stored in the designated swap-space in the hard-disk. The OS fragments the virtual and physical address spaces into pages, and swaps out pages from RAM to swap and back on demand.

Virtual FileSystem

The physical persistent storage space of the hard disks is vitualized with a virtual filesystem (VFS) interface. Hence the disk can be partitioned into different logical volumes each giving the illusion of a single system drive. VFS also makes it simple to access data from different physical storage (hard disk, network attached storage (NAS), usb drives) using a single virtual file system, by mounting them in the root file system.

Multitasking: Virtual Computing

A single core microprocesser is only cable of running a single stream of machine instructions. Single stream execution is virtualized to provide an illusion of multitasking by interleaving streams of instructions from different processes into one stream. In other words a single cpu is time-sliced to provide shared access to multiple processes. When a running process relinquishes control of the CPU, its process state (whatever is needed to resume execution) is saved to the memory or disk. The context of the process selected to run is restored and control handed over to it by the OS for the duration of its slice. The process may voluntarily give up the CPU back to the OS before it time slice (epoch) finishes, if it terminates, or blocks waiting for IO, or is interrupted by a higher priority process.

Virtual CPU

I had to make this a distinct entry to distinguish it from multitasking. Intel hyperthreading allows two threads of execution to run within the a single physical CPU by duplicating execution states inside the CPU. However all other resources are shared. Hence, Intel provides two logical CPU using resources of the single underlying physical CPU.

Virtual Private Network

There are a lot of examples of virtualization from computer networking like Virtual Routing, but we'll talk about Virtual Private Network as it is more interesting. Internet is a public infrastructure, which means any computer is accessible from any other computer connected to the internet. Usually a private (Local Area Network) LAN is implemented by building a LAN using private networking address space and interfacing with the internet through a gateway. The gateway controls what gets into the network and what gets out. The computers inside the LAN do not have public IP (Internet Protocol) addresses, and hence is not directly accessible by the computers in the public internet. If a bunch of computers on the internet having a public IP address wish to behave as if inside a particular LAN, then (Virtual Private Networking) VPN is the solution.

Virtual Hosts

This is how a server serving internet traffic is virtualized. Suppose a physical machine (server) is accessible using different domain names, e.g blog.example1.com and wiki.example2.com. Usually a Domain Name Server (DNS) would resolve both the names to the same IP address of the machine. Depending on what domainname was used to access the server, the server could hand out different content, e.g blog.example1.com would be a blog from company example1, and wiki.example2.com would be a wiki system from company example2, both being hosted in a single server. This is also known as shared hosting.

Virtual Machine

This is a fascinating concept. We usually have a host OS on the computer e.g. linux or windows. Lets assume we have a windows system, and we want to run various linux versions in our machine. Also we do-not want to physically partition the machine Hard Disk Drive (HDD). In some cases we may not even have that privilege. The solution is Virtual Machine(VM). This is a software which provides the entire machine interface to us. This means we can run whatever OS we want to run inside it. We can run multiple instances of VM within a single physical machine. Ofcourse, the resources will need to be divided among the running instances of the VM. Examples are VMware and VirtualBox.

Virtual OS: Containers

Docker is the state-of-the-art technology disruption. The OS rather than machine gets virtualized by providing a namespace and process isolation to the container. The container shares the OS of the host machine, so the overhead is lower than that of the VM. VM has to do machine emulation. Within the container the running processes can only see the allocated resources of the container. It cannot see the processes of the other container, or directly access its resources.

No comments:

Post a Comment