A magazine where the digital world meets the real world.
On the web
- Browse by date
- Browse by topic
- Enter the maze
- Get our RSS feed
- Follow us on Twitter
- Resources for teachers
What is cs4fn?
- About us
- Contact us
- Privacy and cookies
- Copyright and contributions
- Links to other fun sites
- Complete our questionnaire and get a free magic download
Getting off the beach, fast
Paul Curzon goes on holiday and sees how a car park can work like a computer.
Computers get faster and faster every year. How come? Because computer scientists and electronic engineers keep thinking up new tricks, completely new ways to make them go faster. One way has been to shrink the components so signals don't have as far to go. Another is to use the same trick they were using in a beach car park I came across on holiday.
Woolacombe Sands in Devon is one of the most popular beaches around. There is a great expanse of beautiful sand as well as rocks for kids to climb on and good surfing too. The weather is even good there - well most of the time. The car park, right on the edge of the beach fills in the morning. Since most people arrive early and stay all day it's a standard price of £5.50 for the day. Entry and exit barriers control the numbers. The entry barrier only allows a car to go in if there is a space and another allows people out when they have paid.
That's where there is a problem though. The vast majority of people leave around 5pm as the ice cream vans pack up and it's time to look for dinner. The machine only takes coins, and you insert the money from your car at the barrier. Each driver has to fumble with 5 one-pound coins and a 50p and that takes time. Once the current car moves on out there is then another delay as the driver behind pulls forward to get into a position to put their money in. Without some thought it would lead to long queues behind. Not only that it wouldn't be very green. Cars are at there worst pumping out pollution when in a jam.
The last thing you want to do to a family who've had a great day on your beach is then irritate them by clogging them up in a traffic jam when they try to leave. So what do you do? How can you speed things up (and make sure you aren't just moving the queue to the morning or to some other ticket machine somewhere else)?
The problem is similar to one in designing a computer chip. Think of the cars as data waiting to be processed (perhaps as part of a calculation) and the barrier as a processing unit where some manipulation of that data is needed. Data waiting to be processed has to be fetched before it can be used, just as the cars have to move up to the barrier before the driver can pay. The fact that the problems are so similar suggests that a solution to one may also be a a solution to the other.
Speed it up
There are lots of ways you could change the system to improve the speed of cars being processed in the car park. This speed that data passes through a system is called the 'throughput' of the system. Woolacombe have thought of a simple way to improve their throughput. They put a person with a bit of change next to the barrier to help the drivers. This allows them to keep the relatively simple barrier system they have. It also has advantages in keeping the money in one place and being a foolproof way of ensuring there is a space for everyone who enters. It still maintains all the safeguards of the ticket barrier though. How can that one person speed things up?
What would you do?
So what would YOU do if you were that person? Would you speed things up? Or would you just stand there powerless watching the misery of all those families?
The first thing you could do is to stand by the machine and take the change off the driver and insert it yourself. That will speed things up a little bit because it takes longer for drivers to put the money in as they have to stretch out the window of a car. Also if the driver only has a five pound note you can take it and just insert coins from your change bag rather than wasting time passing it back to the driver to then insert. Similarly if the driver only has 50 pence pieces say, rather than wasting time inserting 10 of them you can take them and insert 5 one-pound coins.
You've done some good, and removed problems of the slow people inserting coins but you haven't really solved the bad problems. Cars aren't moving at all while you are inserting the 6 coins, and after each car moves through the barrier you are doing nothing but waiting for the next car to pull forward. In an ideal system, with the best throughput, the cars barely stop at all and you are constantly busy.
A Pipeline of Cars
It turns out you can do something about that. It's called pipelining. There is a way you can be busy dealing with the next car even before it's got to you. You just have to get ahead of yourself!
How? Before the first car arrives, insert 5 pound coins into the machine and wait. As the driver gets to you and gives you the money, insert his or her 50p, keeping the rest. The barrier opens immediately for the driver who barely has to stop. Better still you are now holding 5 pound coins that you can insert as the next car arrives, leaving you back in an identical situation. That means the next car can drive straight through too, and you are constantly busy as long as there are cars arriving.
So you've helped the families leaving the beach, but how might a similar trick speed up a computer? Well you can do a similar thing in the way you get a computer processor to execute the instructions from a program. Suppose your program requires the processor to get some numbers from storage, process them (perhaps multiplying the numbers together) and then store the result somewhere else for later use. Typically a program might do that over and over again, varying where the data comes from and how it is processed.
Early computers would do each instruction in turn – doing the fetching, processing and storing of one instruction before starting the next. But that is just like a car in our car park coming to the barrier, being processed and leaving before the next one moves. Can we pull off the same trick to speed things up? Well, yes of course.
All you need to do is overlap the separate parts. Just as at any time in the car park a car will be driving out, a second will be handing over money and a third pulling forward, the same can happen in the computer. As the first instruction's result is being stored, the next instruction can already be being processed and the data from the one after that can be fetched from memory. Just by reorganising the way the work is done, we have roughly tripled the speed of our computer as now three things are happening at once.
What we have done is set up a 'pipeline' – with a series of instructions all flowing through it, being executed, at the same time. Woolacombe has a pipeline of cars, but in a computer we pipeline data. Either way things get done faster and people are happier.
Computer science happens in some unexpected places – even at the beach – but then perhaps that isn't so surprising given computers are made of sand!