“A three-pronged attack on performance” is a good read on improving performance in Linux. One performance enhancing setting is the hard disk’s readahead value. Unfortunately, there is no magical readahead value that will optimize your hard disk’s performance; you must run your own benchmarks. I used the following code to benchmark disk performance (12 times) at each readahead value on my 256MB Slicehost VPS.
for ((i=0;i<12;i++)); do sudo hdparm -t /dev/sda1; done
The average disk read speeds at each readahead value are as follows:
“hdparm -a128 /dev/sda1″ - 65.69 mb/sec
“hdparm -a256 /dev/sda1″ - 104.44 mb/sec
“hdparm -a512 /dev/sda1″ - 114.54 mb/sec
“hdparm -a1024 /dev/sda1″ - 119.39 mb/sec
“hdparm -a2048 /dev/sda1″ - 122.82 mb/sec
It appears that on my Slicehost VPS, “hdparm -a2048” yields the best performance. To ensure that this readahead value is used at all times, I instruct hdparm to set it on every bootup by adding the following line to /etc/conf.d/local.start
hdparm -a2048 /dev/sda1
More details and documentation on Slicehost’s Wiki.
If you liked this post, please subscribe to my feed. Thanks for visiting!


Using your proposal, an inline script to get the averages automatically:
for r in 128 256 512 1024 2048; do \
echo -n “With readahead $r, “; \
for ((i=1;i<11;i++)); do \
aux=$((aux + \
`sudo hdparm -t /dev/sda1 | grep “Timing buffered” | \
awk -F” ” ‘{print $11;}’ | awk -F”.” ‘{print $1;}’`)); \
done; \
echo “average timing buffered disk reads: $((aux/10))”; \
aux=0; \
done
Thanks, chous! An automated benchmark is much more elegant.
Just to make a quick modification to fix a bug:
for r in 128 256 512 1024 2048; do \
sudo hdparm -a${r} /dev/sda1
echo -n “With readahead $r, “; \
for ((i=1;i<11;i++)); do \
aux=$((aux + \
`sudo hdparm -t /dev/sda1 | grep “Timing buffered” | \
awk -F” ” ‘{print $11;}’ | awk -F”.” ‘{print $1;}’`)); \
done; \
echo “average timing buffered disk reads: $((aux/10))”; \
aux=0; \
done