Wednesday, January 12, 2011

Fix slowness during writing to/reading from hard drive

I have been plagued by my choppy mouse movement (most noticeable) and generally poor performance while running Deluge for a while. I had a really hard time ruling out possible reasons for this issue. First I noticed it wasn't just Deluge, but all BT downloads. Then I tried using a console BT client (also Deluge, which I highly recommend) and realized that the problem still persisted. Finally, I realized that as I limited my download/seed speeds I experienced less and less issues. This wasn't a networking issue, and so I finally narrowed it down to an IO issue; that is, the faster things were being written and read from the disk, the worse the problems became. I hardly ever noticed it before because generally when I'm moving files around it doesn't take more than a minute or so.
I did a bit of research and thanks to the good folks at techtidbits.com, I found what seems to be a solution. I changed my default IO scheduler from the default in Ubuntu, which is called CFQ, to a scheduler called Deadline. So if you're experiencing similar problems, I suggest giving it a shot. It's made a world of difference in my entire experience while I use my computer because I'm almost always downloading.
First, give Deadline a try (you can change it on-the-fly without any real effort).
From the console, use this command:
echo "deadline" | sudo tee /sys/block/sda/queue/scheduler
Now, keep in mind you'll possibly need to change "sda" to something else (whatever drive your root partition is on, which you can find out by typing file /dev/root in the console.
For me, this yielded symbolic link to `sda5'. So, I left "sda" as is.
Now, you want to test the results to make sure there are no problems and, hopefully, observe improved performance. Do this by copying a large file to/from your hard drive.
If all went well, you'll want to make your changes permanent. To do so (if you're using GRUB2, which most Ubuntu users are (it's been default since 9.10 on)),

gksudo gedit /etc/default/grub

put in your password and when gedit launches, look for

GRUB_CMDLINE_LINUX_DEFAULT=""

and change it to say:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=deadline"

Next, run the following:

sudo update-grub

You should get output similar to:

Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.31-20-generic
Found initrd image: /boot/initrd.img-2.6.31-20-generic
Found memtest86+ image: /boot/memtest86+.bin
done

If so, you're good to go! Enjoy your improved IO performance.

No comments:

Post a Comment