Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

7.4 (2 of 2): Virtual environments: good and bad

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Twenty servers or four?

A company has 20 old servers. Each one uses power, takes space and needs cooling. Most of them are busy for only an hour a day.

The company moves them into virtual machines. A virtual machine is a computer made of software. Now four strong computers do the work of twenty. Is it always a good idea? No. By the end of this lesson: I can weigh the benefits of a virtual environment against its drawbacks.

Key words

WordWhat it meansExample
Virtual machineA computer made of software, running inside a real one.A server in a file
VirtualisationMaking computers and their parts in software.Four hosts, twenty servers
Disaster recoveryGetting systems working again after a big failure.Start the VMs at another site
Carbon footprintThe carbon dioxide an activity makes.Fewer machines, less power
HypervisorSoftware that makes and runs virtual machines.The software that starts each guest
SnapshotA saved copy of a virtual machine at one moment, to go back to.Before a risky change
OverheadExtra work done only to run the virtual layer.CPU used by the hypervisor
Test environmentA safe copy of a system for trying changes before they go live.A copy of the website
ContainerA light, fast way to run one program in its own space, sharing the host's operating system.A Docker container
Operating systemThe main program that runs a computer.Windows, Linux
ResilienceKeeping working, or recovering fast, when something fails.Move a VM to another host
CPUThe processor, which runs a program's instructions.The brain of a computer

The cells students fill in are left blank in this preview.

Match the situation to the benefit

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Seven benefits

BenefitWhy
Cost effective for large environmentsFewer machines to buy, house, power and cool
Easy to manageOne tool makes, copies, moves and removes many VMs
ResilienceA VM can move to another host if one host fails
Potentially lower carbon footprintFewer machines use less power. This depends on how well they are used.
Improved disaster recoveryA VM is a set of files, so it is easy to copy to another place and start again
Better testing environmentsMake a copy, test, throw it away. Use snapshots to go back.
Education and trainingEach learner has a safe machine of their own

The cells students fill in are left blank in this preview.

Three drawbacks

DrawbackWhy
Extra hardware loadThe hypervisor and each guest operating system use CPU, memory and storage. The host must be strong.
Slower executionThe program runs more slowly, because an extra layer sits between it and the hardware
A false picture of performanceA test in a VM may not match the real machine, because VMs share hardware and the layer adds delay

The cells students fill in are left blank in this preview.

Quick check: good or bad?

Have a go

Quick check: good or bad?

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Good point or bad point?

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Worked example: is it cheaper?

Here are the numbers for the company in the hook. They are made up for this example.

Each old server costs 600 pounds a year to run: power, space and cooling. A strong host costs 1500 pounds a year to run. One host holds 5 virtual machines.

Worked example: the sums

StepSumAnswer
Hosts needed for 20 servers20 divided by 5 (20 / 5)4 hosts
Cost of the old way20 times 600 (20 x 600)12000 pounds
Cost of the new way4 times 1500 (4 x 1500)6000 pounds
Saving each year12000 take away 6000 (12000 - 6000)6000 pounds

The cells students fill in are left blank in this preview.

Try it: the saving

Code: python
old_servers = 20
old_cost = 600
vms_per_host = 5
host_cost = 1500

hosts = old_servers // vms_per_host
old_total = old_servers * old_cost
new_total = hosts * host_cost
print("Old way:", old_total, "New way:", new_total)
print("Saving each year:", old_total - new_total)

# Change host_cost to 3000. Is it still cheaper?

Make a free account to save your work and track your progress.

Your turn: hosts and savings

Write two functions.

  1. hosts_needed(vms, vms_per_host) gives back how many hosts you need. If some VMs are left over, you need one more host. For example, 21 VMs at 5 for each host: 21 // 5 is 4, and 21 % 5 is 1 left over. So you need 5 hosts.
  2. yearly_saving(old_count, old_cost, new_count, new_cost) gives back the money saved in a year: the old total take away the new total.

Press Run Tests to check.

Code: python
def hosts_needed(vms, vms_per_host):
    # How many hosts do we need? Each host holds vms_per_host virtual machines.
    # 21 virtual machines at 5 for each host need 5 hosts, because 4 hosts hold only 20.
    return 0


def yearly_saving(old_count, old_cost, new_count, new_cost):
    # The old way: old_count machines, each costing old_cost a year.
    # The new way: new_count hosts, each costing new_cost a year.
    # Give back how much money is saved in a year.
    return 0

Make a free account to save your work, or press Start lab to work through the whole lesson.

Extra: A lighter cousin: containers

A container runs one program in its own space. It shares the operating system of the host.

So it starts in seconds and uses less memory than a VM. The isolation is not as strong as a VM, because the operating system is shared.

Extra: See three containers

Command
docker ps -a

A command for the lesson’s lab terminal. It is shown here and not run.

Extra: Read what one container said

Command
docker logs worker

A command for the lesson’s lab terminal. It is shown here and not run.

Extra: What the lab shows

Note

Three containers run side by side. One of them has stopped, and its log says why. A VM would need a whole operating system for each one. The containers share one.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Final check

Have a go

Final check

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.