Timing random disk seeks

Posted at 2007-05-17 14.34

I asked an interviewee how long it takes for a disk seek, and he replied that he thought it was between 4 and 8 milliseconds. Speaking with colleagues, the conventional wisdom was that it was around 10 ms. I was unsatisfied so I thought I would try it for myself.


time sudo perl -we '$disk="/dev/sda"; $n=1500; $blocks=`blockdev --getsz $disk`; if (!$blocks) {print "Enter capacity in manufacturer GB\n: "; $blocks=1953125*(<>)}; use Time::HiRes "time"; open DISK, $disk; $start=time; for (0..$n) {seek DISK, int(rand($blocks))*512, 0; sysread DISK, $x, 512 || die; $now=time; $times[int(($now-$start)*1000)]++; $x=$now-$start; $s2+=$x**2; $s+=$x; $start=$now}; for (0..$#times) {if ($t=$times[$_]) { $tot+=$t; $median||=$_ if $tot>=$n/2; printf "%3d %s\n", $_, "x" x ($t/2) . ($t%2?":":"")}}; printf "\nTook %3.4gs for %d seeks of %s (%d GB)\n", $s, $n, $disk, $blocks/2097152; printf "Mean: %2.03gms; Median: %d-%dms; Std dev: %2.03gms\n", 1000*$s/$n, $median-1, $median, 1000*sqrt($s2/$n - ($s/$n)**2);'

It should be obvious that before you run this, you should check for yourself that it doesn't do anything dangerous. Or at least check that $disk is set appropriately for your hardware and operating system. If you don't have blockdev, estimate the number of 512-byte blocks and set $blocks to that value. (There are 1953125 blocks in a hard disk manufacturer’s "Gigabyte".)

The graph it produces prints an 'x' for two seeks of a given number of milliseconds and a trailing ':' if there was one left over. For me, on my one year old Linux 2.6.18 workstation with a 160 "GB" Western Digital (WDC WD1600JS — quoted seek time 8.9 ms) the typical output is:

  0 :
  3 :
  4 :
  5 x:
  6 xxxx:
  7 xxxxxxx
  8 xxxxxxxxxxx:
  9 xxxxxxxxxxxxxxxxx
 10 xxxxxxxxxxxxxxxxxxxxxxx
 11 xxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 12 xxxxxxxxxxxxxxxxxxxxxxxxx
 13 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 14 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 15 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 16 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 17 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 18 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 19 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 20 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 21 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 22 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 23 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 24 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 25 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
 26 xxxxxxxxxxxxxxxxxx
 27 xxxxxxxxxxxxxxx
 28 xxxxxx:
 29 xxxxx:
 30 xxxx
 31 :
 32 :
 34 x
 35 :
 57 :

Took 27.69s for 1500 seeks of /dev/sda (149 GB)
Mean: 18.5ms; Median: 17-18ms; Std dev: 5.24ms

real    0m27.859s
user    0m0.116s
sys     0m0.044s

Why might I care? 18 milliseconds is almost a lifetime compared with anything else a modern PC does. It’s slower than my monitors' refresh period! I can read around 1 MB from disk, 10 MB over a GigE link or 20 MB from RAM in this time. I can ping from Ireland to England, crossing 40 routers there and back, in the time it takes for my disk head to seek.

Every time you read something from a previously unread file, it costs on average EIGHTEEN MILLISECONDS even before it starts reading. That’s just 55 in a second. This has obvious implications for I/O program performance, i.e. that of most servers.

If anyone has a concern about my method, I'd be interested to hear it.

I'd also like to see the timings for different disks. Either post the whole histogram or just the stats, plus the make and model of the disk. On Linux you can get this from dmesg or hdparm -I device.

Update: I've made the script more robust under non-existence of blockdev.

— ads
Filed under: Computing
New appartment

Posted at 2007-03-06 15.43

I am no longer even nearly homeless, having just started renting an appartment. Because I'd be lonely on my own, I'm sharing with another Googler, Carlo Contavalli.

Here’s the weird thing. We were chatting over lunch and it turns out that, unbeknown to either of us, we are both Debian Developers. Only in Google could this happen.

— ads
Filed under: Misc
Airport security

Posted at 2007-03-01 08.02

I have long felt that many airport security measures are just for show — "security theatre", as Bruce Schneier puts it — but I now have some anecdotal evidence to back it up.

I fly frequently: from Dublin to my family in Durham, and I make the occasional transatlantic flight too. Before I realised it last week, I had taken a travel sewing kit in my hand luggage on seven flights, both short-haul and long. In Chicago, I even had my luggage hand-checked; they still didn't notice it.

Maybe they'd have been more thorough if I'd been wearing a turban.

— ads
Filed under: Misc
Nearly homeless

Posted at 2007-02-28 02.59

Okay, perhaps it’s a little exaggeration to say that I'm nearly homeless, since I have a perfectly nice house in Durham. However, since I'm working in Dublin this is not especially helpful for my weekday accommodation.

If any reader has a room they could rent me near Grand Canal Dock, for around €400-450, please get in touch, perhaps by email. I don't keep cigarettes or pets.

— ads
Filed under: Me
Laphroaig quarter-cask

Posted at 2007-02-24 01.32

We went to Scotland on a family holiday this week (brave or stupid, answers on a postcard). You would not believe the number of puns you can get from the simple town of Ayr. For example, R: "You should have turned right there!" Me: "Oh well. To Ayr is human." I shall spare you the rest: if your mind isn't already overflowing with similar appalling jokes, you're no friend of mine.

Whilst in Ayr, I came across a marvellous whisky shop, Robbie’s Drams, and bought a bottle of Laphroaig quarter-cask and another of Smokehead. This article, or what remains of it, is to describe the Laphroaig quarter-cask whisky.

Should you wish to avoid the Flash-animated website, here’s a precis. Tales are told of a time when the business of Laphroaig was carried on less than legally and it was useful to carry away smaller casks when the Excise men were coming than the more conventional full-size casks.

Over the past few years, they have tried their best to recreate the whisky that would have been drunk as Laphroaig a couple of centuries ago: quarter-sized casks, slightly higher strength and an older filtration model.

The effect of the smaller barrels is to increase the surface area to volume ratio substantially, so more flavour will enter the whisky from the barrel. Thus, they bottle it much younger than their standard ten-year-old offering.

To smell it, a sweet smell hits the nose — perhaps toffee apple. On the taste, there is an initial earthy sensation followed quickly by a brief flash of kedgeree, leaving the smoky aftertaste of turmeric at the back of the throat. This is a much more subtle whisky than Laphroaig’s ten-year-old: thinner and less oily, and with a much more delicate, though still substantial, peaty hit.

Because it’s not chill-filtered, the whisky becomes delightfully cloudy when water is added. I recommend that you try it both with and without additional water: many of the flavours become more muted with water, but a creamy taste comes to the fore.

In summary: if you can get your hands on a bottle or two of this, it’s well worth doing so. An excellent whisky. I should also say that even if you've disliked other Laphroaigs in the past, give this a shot. It may just be your way into the other delights from the Laphroaig distillery.

— ads
Filed under: Whisky
Words and punctuation

Posted at 2007-02-15 00.45

I don't generally post whilst annoyed — which could explain why my postings are generally of a whimsical nature and (hint hint) don't get enough comments. However, this post is different.

I am angry that people see fit to write things for public consumption or wide dissemination when they obviously have little regard for the language in which they are writing. As a general principle, if you don't know the right spelling, punctuation or grammar, ask someone who does know!

People who don't know where apostrophes belong: this means you!

Another hint: the word "momentary" does not mean, "in a moment". It means "for a moment". Big difference. If "the power will resume momentarily", I'm going to unplug my delicate electronics. If it will resume shortly I will cheer and lo! there will be great rejoicing.

— ads
Filed under: Misc
Ryanair strangeness

Posted at 2007-02-09 09.55

We have a couple of low-cost airlines in England and Ireland, Easyjet and Ryanair. They are interesting because they optimise for low turn-around time and general cheapness. Optimisations include making the passengers walk to the aeroplane then up both sets of on-board steps to halve loading time, and putting quite a steep charge on all checked luggage. This all makes sense.

However, today, I came across a measure that makes very little sense indeed. Ryanair have added a surcharge for checking in online. So rather than go through their computerised process that (I should expect) costs virtually nothing to administer, I will be pestering the check-in staff in person today.

No matter. At least I'm going home today to see my family.

— ads
Filed under: Me
Dublin and the absence of jet-lag

Posted at 2007-02-08 14.46

I'm back in Dublin, trying madly to lose the Californian mannerisms. Starting sentences with 'So …' is the most pernicious. It’s excellent to be back; there’s a great sense of camaraderie here, and people are easier to approach. It’s also good to have easy access to daylight — even though there’s less of it, I get to look out of a window.

I had been intending to go straight from the airport to where I'm living temporarily, but I forgot its address so went to work instead. I'm so grateful to B and his wife for putting me up for the time being, but of course I'm now looking for somewhere in Dublin to live — preferably close to the Google office. So if anyone out there has a room to spare in Dublin for a non-smoker with simple needs, get in touch.

I seem to have found the key to avoiding jet-lag. Stay up the night before you fly, so you sleep on the plane. When you wake up, your body clock will be so disoriented that it’s easy to persuade it to re-sync to wherever you are.

It’s great to see colleagues again, but of course I'm now missing friends and colleagues from California. On the whole, however, Dublin is an upgrade. I'm even enjoying the rain. It gets so tedious in California, to know that the whole week will be 22-25°C, with no rain.

Of course, the great benefit of Dublin is that it’s only an hour’s flight from Durham and the family. I'm seeing them on Friday!!

— ads
Filed under: Misc and Me
dpkg-repack

Posted at 2007-02-07 19.57

I was on a friend’s machine looking to copy some of his software.

$ dpkg-repack <pkg>
bash: dpkg-repack: command not found

So, here’s a hacky and woefully incomplete replacement for dpkg-repack.

#! /bin/sh

set -eu
[ 0 != $(id -u) ] && { echo "Must be run as (fake)root" 1>&2; exit 1; }

pkg=$1; pkgdir=$(mktemp -d "$pkg.XXXXXX")
mkdir "$pkgdir"

dpkg -L $pkg | tar cf - –no-recursion –files-from - | (cd "$pkgdir" && tar xvf -)

install -d -m 755 "$pkgdir/DEBIAN"
dpkg -s "$pkg" |sed '/^Status: /d' > "$pkgdir/DEBIAN/control"

dpkg-deb -b "$pkgdir" .
rm -rf "$pkgdir"

Works For Me ™.

Update: it was pointed out that wordpress had prettified the code, turning pairs of dashes into em-dashes and other atrocities. so I've uploaded the script: [fake-repack]

— ads
Filed under: Computing
Haskell

Posted at 2007-01-24 20.55

Independently from my decision to revisit Haskell, some colleagues here have just started a discussion group to learn the language. I hope I'll have time: I enjoyed my brief dalliance with it in 2003.

One of my Dublin colleagues has a copy of Thompson’s book, Haskell: The Craft of Functional Programming so I'll steal that when I return, and astound my friends with my new-found Haskell brilliance.

— ads
Filed under: Computing
ok