Wednesday, February 2, 2011

Bandwidth versus Latency, a common misconception

As an electronics engineer I came to understand the difference between bandwidth and latency.  Bandwidth is the amount of objects that can travel across a medium per unit time e.g. Megabytes per second from a hard disk (HDD).  Latency is the amount of time each object takes to get to its destination.  Taking again the example of a HDD this is usually governed by the seek time.  For those that don't know, the seek time is the time the hard disk takes to physically move the head across the platter of the magnetic disk to find the right track and then the time for the right part of the disk to spin under the head.  For a 7200RPM hard disk the data comes around every 60/7200 seconds or 8.3ms.

Consider a computer program trying to access a single byte of data from a disk.  Imagine we have a modern computer with a processor running at 3GHz.  This means (as an order of magnitude) it can process 3,000,000,000 instructions per second.  It issues a command to request the byte from the hard disk.  The processor in the hard disk electronics calculates where to move the disk head to, moves it and waits for the data to come under the head.  12 ms later the byte is handed over to the processor.  In this time the processor could have executed 3.6 million instructions but instead did nothing because it was waiting for the hard disk.  If programmers were foolish enough to write programs that randomly accessed many small pieces of data, you can imagine that this program would run extremely slowly no matter how fast the processor was.
Once the data is under the disk read head, it streams off the disk extremely quickly; at circa 100 Mbytes per second.  Imagine the computer program wanted to read 1 Mbyte instead of 1 Byte. Now we still wait 12ms for the first bit of data but then we get 1Mbyte of data in only 10ms.  The throughput of the program is increased hugely to 45Mbytes per second.  We see that the thing that we care about i.e. the work done, the throughput, is a function of both bandwidth and latency.

All very interesting I hear you say, but why publish all this on an eco-musing blog?  Well, there is another parameter that comes into play, and that is the effort expended per amount of work done.  The CPU in the above example did not do nothing for 12ms, it sat there "spinning its wheels", generating heat.  The rest of the computer is also alive; The hard disk itself spins its platters and moves its heads, the display lights its backlight etc.  Even in the second example the computer spends half of its time doing nothing but warm the planet.  This is why over the last year I have been steadily replacing the main hard disks of my computers with solid state HDDs (SSDs) aka flash disks.
SSDs have no moving parts which makes their seek times around 0.1ms; 2 orders of magnitudes quicker than traditional HDDs.  As they have no motors or moving parts they also use less power.  The only drawback is that they are expensive, or are they?  The machine I am typing on has 120Mbyte SSD and a 1Tbyte HDD.  The OS, Windows 7 and programs are on the SSD and all my data is on the HDD.  It turns out that Windows, being nearly 20 years old, was designed when computer memories were small and so is made up of lots of small files, 69,534 small files in my case, which is why it takes forever to boot. The boot time of this machine before I installed the SSD used to be about 2.5 minutes; now it is about 35 seconds. Given I use it daily that soon adds up to a lot of time; 700 minutes per year.  As a consultant I charge of the order of €1 per minute for my time, so that's a €2000 saving over the SSD's three year lifespan versus an initial outlay of €200.

It is not only my time during the latency of boot-up that is saved.  Toms Hardware found that computers with SSDs were on average 15% faster than their HDD counterparts.  As I work with computers about 9 hours a day, that's a potential saving of 1.35 hours daily.  Of course the bottleneck is not always the computer - after all, I can only type at a certain speed, but let's say it saves 2% of my time and 5% of the electricity used by the computer overall.  Over 3 years that equates to ~150kWh of electricity or €22 worth plus another €1200 in terms of my time. Another way to look at it is that the SSD pays for itself in about 3 months and saves carbon too!
Of course to do a full analysis of the carbon footprint I would have to calculate the embodied carbon in the manufacture of the SSD + HDD versus the just the HDD.  That might not look so good. But then what is the carbon cost of my time - heating, lighting, food, clothing etc?  That is, perhaps, going a little too far for this humble little blog.

Bandwidth and latency are interesting parameters to analyse.  They can also be applied to roads that allow objects i.e. you and me to travel from A to B. But that is for another blog  ... 

No comments: