Speeding up bitcoin-qt on Linux

The problem

After freshly installing bitcoin-qt - the de-facto bitcoin client - to a computer, it starts downloading "blocks" from the network. The last few (tens of) thousands of blocks are especially slow, and the client is using the disk heavily.

Examining the disk usage closely with iostat showed that the disk utilization was 100%, but at a very low data rate. My disk can read and write about 150 MBytes/second if utilized properly, but bitcoin-qt could only write about one megabytes per second.

(EDIT: thanks for the donation, you rock! :) )

The cause

Bitcoin-qt is very nicely written program that uses the guarantees granted by modern file systems to improve data integrity. This means that if you pull the plug in the middle of disk operations, your filesystem will still be able to come back to life after reboot, and will do so quite quickly.

The program does this by calling the fsync() system call a lot. This ensures that when it returns, every byte sent to the file handle will be on the magnetic surface of your disk. Well, it seems to be the case in the default Ubuntu desktop configuration at least.

The ext4 file system  - what I use - sends so-called barrier commands to the disk when it fsync() is issued (well, on any journal commit). The barrier ensures that everything is on the disk before it starts to process commands after the barrier. By the time the barrier command returns, everything is on the spindles.

The solution

The block chain download is just painfully slow. Power outages are rare and I have backups. Data integrity therefore doesn't seem like a major concern to me, at least for a few hours while the block chain is downloading. If I could just disable barriers, that might improve performance.

The examples below assume that you keep your block chain on the / partition. If you have a separate partition for /home, you probably have to use that. Anyway if you start tweaking your file system like this, I expect you to know how to figure this out. ;)

This is easy to test, barrier writes can be disabled on-line:

sudo mount -o remount,nobarrier /

This disables barrier writes nicely totally risking the data integrity of your filesystem, unless you're using battery-backed RAID. The performance improvement of the client was drastic. The disk utilization dropped to about 50%, and my desktop programs (like firefox) was responsive again.

Do this only while you're initially downloading blocks. This can be dangerous on the average desktop computer. Always keep backups.

When the client is finished downloading blocks, return to normal operation:

sudo mount -o remount,barrier /


Oh, of course, you can always send me a few BTCs ;)

Bitcoin: 19uhBv4n8R7aUcJSMsD6vkaLotfXwcqavY

Litecoin: LdiZ2hwCsSh71CUK9zaac5iUS1KnQ5pS6D


Népszerű bejegyzések ezen a blogon

How does iptables hashlimit module work?

Converting a dual-boot MBR partitioned disk to GPT