a blog by Marius Gedminas

Measuring disk speed

A friend of mine told me yesterday that he got a significant disk access speed improvement by moving his Linux partition from the end to the beginning of the disk. The theory being that lower disk sectors are located on the outer rim, and are faster, because the disk rotates at a constant angular speed. I didn't believe this could give a 50% improvement, so I decided to do some benchmarking.

hdparm -t /dev/hda on my disk gives me transfer speeds between 20 to 24 MB/s on my 40 GB laptop disk. I hacked hdparm.c to seek to the end of the device, minus the number of sectors hdparm reads to determine disk speed, and ran it. I got a read error instead of a speed estimate. My 40 GB disk has an inaccessible Host Protected Area of about 4 GB at the end, and although the kernel claims it disabled the HPA, reading it gives me I/O errors.

I then changed my hack to skip the HPA as well, ran it, and got 3.5 MB/s. Wow, I thought. I never thought the difference could be so significant. I ran the regular hdparm to double-check, and got 3.5 MB/s again. Wait a minute... It turned out that the kernel saw disk I/O errors from the HPA, and decided to disable DMA. After a quick hdparm -d 1 /dev/hda, I once again saw 24 MB/s at the beginning of the disk, and almost the same value at the end:

mg@perlas:~/src/apt-sources/hdparm-5.8 $ for i in 1 2 3; do sudo hdparm -T -t /dev/hda; done

/dev/hda:
 Timing cached reads:   844 MB in  2.01 seconds = 420.80 MB/sec
 Timing buffered disk reads:   74 MB in  3.07 seconds =  24.13 MB/sec

/dev/hda:
 Timing cached reads:   852 MB in  2.01 seconds = 424.79 MB/sec
 Timing buffered disk reads:   74 MB in  3.08 seconds =  24.04 MB/sec

/dev/hda:
 Timing cached reads:   804 MB in  2.00 seconds = 401.46 MB/sec
 Timing buffered disk reads:   74 MB in  3.02 seconds =  24.50 MB/sec

mg@perlas:~/src/apt-sources/hdparm-5.8 $ for i in 1 2 3; do sudo ./hdparm -T -t /dev/hda; done

/dev/hda:
 Timing cached reads:   848 MB in  2.01 seconds = 422.38 MB/sec
 Seeking to the end of device: 35573459456
 Timing buffered disk reads:   74 MB in  3.03 seconds =  24.43 MB/sec

/dev/hda:
 Timing cached reads:   856 MB in  2.00 seconds = 427.21 MB/sec
 Seeking to the end of device: 35573459456
 Timing buffered disk reads:   74 MB in  3.03 seconds =  24.39 MB/sec

/dev/hda:
 Timing cached reads:   800 MB in  2.01 seconds = 398.67 MB/sec
 Seeking to the end of device: 35573459456
 Timing buffered disk reads:   72 MB in  3.04 seconds =  23.69 MB/sec

Conclusion: physical location of a partition does not change the linear transfer speed significantly.

Multi Disk System Tuning HOWTO has a section on physical track positioning. It mentions another optimisation: if you position your partition in the middle of the disk, you will reduce average seek time by 50%. Benchmarking that is, however, more difficult than just adding an lseek call to hdparm.c, so I didn't.

Zope 3 request recorder

Zope 3 has this notion of functional doctests: functional tests (in the form of standalone doctest files) that pretend to perform HTTP requests to your Zope 3 server, and look at the response. Here's an example test from SchoolBell.

You can create functional doctests by using your browser and recording your session with TCPWatch, and then running a Python script that comes with Zope 3: dochttp. For some reason I found this method too cumbersome and usually just cloned existing doctests and changed the requests and responses by hand.

I now have a working prototype of a request recorder as a plug-in of Zope 3. You can set up a RecordingHTTP server on a separate port, and then go to /++etc++process/RecordedSessions.html to look at all requests you've made, filter them, and create a functional doctest.

Screenshot of /++etc++process/RecordedSessions.html

Planet Mg: foray into JavaScript land

I have tried a number of desktop feed aggregators, but I found that I liked reading planets in Firefox best. Recently, hearing all the buzz about DHTML applications taking over the world, I decided to try and learn some JavaScript, and also make my planet more useful.

The result: Planet Mg now lets you collapse stories you have read, and remembers collapsed stories in a cookie. You can also move around stories with the keyboard (press ? for a list of key bindings). There are also unit tests for the JavaScript code.

Not everything works in Internet Explorer, though. I don't really need MSIE compatibility on Planet Mg, as its intended audience is just one Firefox user (me), but it would be a good exercise. I will work on it, time permitting.

I would like to thank Jeff Waugh, Scott James Remnant and other Planet developers for Planet; Chris Dolan for the inspiring JavaScript on his planet; Edward Hieatt for JsUnit; Peter-Paul Koch for QuirksMode.