Linux – Sync writes very slow. Ubuntu 10.10, 32 bits, ext4

ext4hard-disklinuxperformance

I am running ActiveMQ on my Macbook Pro that runs Ubuntu 10.10, 32 bits with an ext4 partition.

Linux iker-laptop 2.6.35-23-generic-pae #40-Ubuntu SMP Wed Nov 17 22:32:51 UTC 2010 i686 GNU/Linux

If I enable persistence in ActiveMQ the performance drops terribly. I've tested the same thing on other machines and the difference is of 2 orders of magnitude.

There is a tool with activeMQ to test the HD, here are the results:

iker@iker-laptop:~/apps/apache-activemq-5.4.1$ java -classpath lib/kahadb-5.4.1.jar org.apache.kahadb.util.DiskBenchmark 

Benchmarking: /home/iker/apps/apache-activemq-5.4.1/disk-benchmark.dat
Writes: 
  146171 writes of size 4096 written in 11.074 seconds.
  13199.477 writes/second.
  51.560455 megs/second.

Sync Writes: 
  197 writes of size 4096 written in 10.006 seconds.
  19.688187 writes/second.
  0.07690698 megs/second.

Reads: 
  5589861 reads of size 4096 read in 10.001 seconds.
  558930.2 writes/second.
  2183.321 megs/second.

Performance for Sync Writes is s**t. There must be something misconfigured, but this is the only app where I've noticed a HD performace issue.

hdparm throws expected values:

iker@iker-laptop:~$ sudo hdparm -tT /dev/sda

/dev/sda:
 Timing cached reads:   6282 MB in  2.00 seconds = 3141.73 MB/sec
 Timing buffered disk reads:  240 MB in  3.00 seconds =  79.88 MB/sec

Best Answer

The major limiting factor for synchronous IO isn't throughput of your harddrive, but rather the time it takes from when the write is issued and it being committed to disk. The most relevant performance metric for a harddrive in this regard would be the seek time of the harddrive and not it's throughput under ideal circumstances.

In addition to the hardware working against you, so are the kernel, I'm guessing you might see a small improvement (although, probably nowhere near what you'll get from doing async IO) if you can ionice the benchmark (application) to run under the realtime IO scheduling class. By default, applications will be scheduled under the best effort class, which probably also will add to the wait time of your writes. Use the realtime scheduling class at your own risk, as it'll have adverse effects on other applications performance when accessing disk.

In general, I don't really think there's anything horribly wrong with the synchronous write performance you're seeing. Synchronous IO will in general perform horribly compared to asynchronous IO.

As a side note a quick google of activemq and synchronous io gave the following:

For performance reasons you may wish to stream messages to the broker as fast as possible even if you are using persistent messages