January 21, 2009

Beware: ext3 and sync-binlog do not play well together

Posted by peter |

One of our customers reported strange problem with MySQL having extremely poor performance when sync-binlog=1 is enabled, even though the system with RAID and BBU were expected to have much better performance.

The problem could be repeated with SysBench as follows:

CODE:
  1. ./sysbench --num-threads=2 --test=oltp --oltp-test-mode=complex --oltp-table-size=100000 --oltp-distinct-ranges=0 --oltp-order-ranges=0 --oltp-sum-ranges=0 --oltp-simple-ranges=0 --oltp-point-selects=0 --oltp-range-size=0 --mysql-table-engine=innodb  --mysql-user=root --max-requests=0 --max-time=60 --mysql-db=test run

On Dell R900 with CentOS 5.2 and ext3 filesystem we get 1060 transactions/sec with single thread and sync_binlog=1 while with 2 threads it drops to 610 transactions/sec Because of synchronous serialized writes to binlog we're not expecting significant improvements in transaction rate (as the load is binlog fsync bound) but we surely do not expect it to drop ether.

To ensure this is not RAID controller related we repeated the run on the in memory block device and got very similar results - 2350 transactions/sec with 2 threads with sync-binlog=0 and just 750 transactions/sec with sync-binlog=1

We tried running data=writeback and data=journal just to make sure but results were basically the same.

Using XFS instead of EXT3 gives expected results - we get 2350 transactions/sec with sync_binlog=1 and 2550 transactions/sec with sync-binlog=0 which is about 10% overhead.

EXT2 filesystem also behaves similar to XFS so it seems to be EXT3 specific performance issue. We do not know if it is CentOS/RHEL specific and if it is fixed in the recent kernels. If somebody can run the same test with different kernels it would be interesting to know results.

You also may wonder how could this problem be unnoticed for a while ? First it only applies to the binary log. Innodb transactional log does not have the same problem on EXT3. I expect this is because Innodb log is pre-allocated so there is not need to modify meta data with each write while binary log is written as growing file. Another possible reason is small sizes of writes which are being fsync'ed with binary log. Though these are just my speculations - we did not investigate it in details.

Another reason is - it only happens with high transaction commit rate. If you're just running couple of hundreds of durable commits a second you may not notice this problem.

Third - sync-binlog=1 is an option great for safety but it is surely not the most commonly used one. The web applications which often have highest transaction rates typically do not have so strong durability requirements to run this option.

As the call for action - I would surely like someone to see if EXT3 can be fixed in this regard as it is by far the most common file system for Linux. It is also worth to investigate if something can be done on MySQL side - may be opening binlog with O_DSYNC flag if sync_binlog=1 instead of using fsync will help ? Or may be binlog pre-allocation would be good solution.

Related posts: :read_ahead (disabled) as steroid::No more MySQL Crash Safe Replication in 5.0 ?::Why MySQL’s binlog-do-db option is dangerous:
 

17 Comments »

  1. 1. Mark Callaghan

    Are log files for Falcon and Maria pre-allocated?

    Comment :: January 21, 2009 @ 9:37 pm

  2. Maria logs at least are not. I spoke to Monty about this and he plans to do it on optimization stage.

    Comment :: January 21, 2009 @ 9:55 pm

  3. Hi,

    I’m not 100% sure, but I think EXT3 flushes all the transactions affecting the filesystem when you fsync a file and not only the transactions affecting the fsynced file. That could be slow if said filesystem has seen lots of changes all over.

    Also, there was a long debate 6 months ago or so about Firefox RC1, etx3 and fsync:
    https://kerneltrap.org/mailarchive/linux-fsdevel/2008/5/26/1940114

    Anyway, I’ll try your sysbench to see if I can confirm the issue, because that could really be the problem I was seeing when I originally reported the kernel bug #7372:
    http://bugzilla.kernel.org/show_bug.cgi?id=7372

    Comment :: January 22, 2009 @ 12:12 am

  4. Who’s command is that? an specific program ?

    ./sysbench

    Comment :: January 22, 2009 @ 9:18 am

  5. 5. Davy

    Thanks for the post Peter. I have been noticing some weird iostat output that shows 4 – 6 MB/sec writes to a logical volume that only has our binary logs on it, even though the logs were only growing at about 1 MB every 8 seconds. After turning sync_binlog off, this behavior stopped and now iostat reports around 0.13 MB/sec writes to that volume.

    Comment :: January 22, 2009 @ 9:22 am

  6. Angelo,

    Yes this is the program we quite commonly use for MySQL benchmarks. Fownload it here:

    http://sourceforge.net/projects/sysbench

    Comment :: January 22, 2009 @ 9:49 am

  7. Brice,

    Yes as I remember ext3 has to flush its log when we have fsync on the file. This is by design as log file contains mix of transactions from various files (meta data changes typically) and just has to be flushed to the point. Same actually happens with Innodb – when you commit transaction changes from other transactions in the log also have to be flushed.

    But I do not think this is the deal here – the single binary log file on the volume still has the same problem.

    Comment :: January 22, 2009 @ 9:59 am

  8. on ext3, think of fsync==sync.

    The only engine inside MySQL that does pre-allocation correctly is NDB.

    Comment :: January 23, 2009 @ 12:15 am

  9. Steward,

    You’re saying FSYNC == O_SYNC for opening files ?

    Speaking about NDB I assume you mean besides Innodb which has fixed sized logs…. BTW even for tablespaces Innodb uses background pre-allocation.

    Comment :: January 23, 2009 @ 9:31 am

  10. well… fsync()==/bin/sync

    innodb does “preallocate” but just by writing out the files. NDB (on XFS… or recent glibc and kernel) call the filesystem’s fallocate function (xfsctl or if posix_fallocate is implemented correctly in libc and kernel) to ask it to preallocate the disk space (which usually results in much less fragmented files on any remotely aged file system)

    Comment :: January 23, 2009 @ 2:24 pm

  11. Steward,

    Are you sure about fsync()==/bin/sync ? I know it does flushes the log but I think I commonly see “dirty” pages in the cache on server running Innodb on ext3 while running tens of durable commits per seconds which would keep this number very low if it would be full syncs.

    Speaking about Pre-Allocation I think it is different story. This helps with fragmentation by reserving the space. But if files change their size with each write you get important meta data updates all the time. Though I guess it would be interesting to just see how it affects performance – growing file vs fallocate preallocated vs physically preallocated.

    Comment :: January 23, 2009 @ 5:48 pm

  12. 12. David Nguyen

    I’ve ran several sysbench tests with ext3, ext2, and XFS. I noticed a huge performance hit with ext3 and sync_binlog=1 and only a ~10% hit with ext2 (just as you have posted above). However, I was not able to get good numbers with XFS on Debian. What are some of the recommended XFS tuning parameters?

    Comment :: April 6, 2009 @ 11:46 am

  13. 13. Vadim

    David,

    You may mount XFS partition with -o nobarrier option.

    Comment :: April 6, 2009 @ 12:16 pm

  14. with -onobarrier, be sure that you have write cache disabled for the drive – otherwise you *will* get filesystem corruption on crash.

    Note that ext3, by default, does *NOT* use write barriers – so it’s actually dangerous if write cache is enabled.

    Comment :: April 6, 2009 @ 5:20 pm

  15. 15. David Nguyen

    Thanks for your quick replies. I am running MySQL on a Dell PowerEdge 2950 with PERC6 (with BBU) 6 x 15K drives configured with Raid 10.

    Is the recommendation to:

    1) mount XFS with -onobarrier
    2) write cache disabled for the drive
    3) write-back enabled for the controller

    Comment :: April 7, 2009 @ 12:56 pm

  16. It can depend on the performance characteristics of the device. with battery backed RAID cache, barriers should be the best performing setup as you will want to be using the write cache.

    Comment :: April 7, 2009 @ 5:47 pm

  17. 17. Steve Katz

    Does this same problem exist on CentOS 5.4?

    Comment :: November 12, 2009 @ 2:34 pm

 

Subscribe without commenting

Trackbacks/Pingbacks