RAID-1 - suboptimal write performance?
While doing rsyncs of large archives from one RAID-1 btrfs filesystem to another RAID-1 btrfs filesystem:
btrfs filesystem 1: sda + sdb (RAID-1), being copied to:
btrfs filesystem 2: sdc + sdd (RAID-1)
Server has 32 GB RAM
I can observe the following:
Quoted 1 line
From time to time, rsync "freezes", while there is high IO on only *one*
of write drives.
To reproduce:
dd if=/dev/urandom of=/mnt/btrfs1/bigfile.img bs=1M count=10000; sync
# cp should work, too, but won't show copy speed/progress rsync -a -v --progress /mnt/btrfs1/bigfile.img /mnt/btrfs2/
In another terminal, run iostat -m 1:
1) a few seconds of writes to only one RAID-1 member:
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdc 355.00 0.00 177.50 0 177 sdb 0.00 0.00 0.00 0 0 sdd 0.00 0.00 0.00 0 0 sda 0.00 0.00 0.00 0 0
2) then, a few seconds of writes to the other RAID-1 member:
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdc 0.00 0.00 0.00 0 0 sdb 0.00 0.00 0.00 0 0 sdd 351.00 0.00 175.50 0 175 sda 0.00 0.00 0.00 0 0
Is it optimal behaviour? With software RAID-1, I'm seeing writes to both devices at the same time.
Also, what happens when the system crashes, and one drive has several hundred megabytes data more than the other one?
Signature · 2 lines
Tomasz Chmielewski http://wpkg.org
Quoted 8 lines · Tomasz Chmielewski
While doing rsyncs of large archives from one RAID-1 btrfs filesystem to another RAID-1 btrfs filesystem:
btrfs filesystem 1: sda + sdb (RAID-1), being copied to:
btrfs filesystem 2: sdc + sdd (RAID-1)
Server has 32 GB RAM
Quoted 5 lines
I can observe the following:
From time to time, rsync "freezes", while there is high IO on only *one* of write drives.
No comment on the performance issue, other than to say that I've seen similar on RAID-10 before, I think.
Quoted 2 lines
Also, what happens when the system crashes, and one drive has several hundred megabytes data more than the other one?
This shouldn't be an issue as long as you occasionally run a scrub or balance. The scrub should find it and fix the missing data, and a balance would just rewrite it as proper RAID-1 as a matter of course.
Signature · 1 line
Calvin Walton <[email protected]>
Quoted 9 lines · On Fri, 16 May 2014 14:06:24 -0400 Calvin Walton <[email protected]>…
No comment on the performance issue, other than to say that I've seen similar on RAID-10 before, I think.
Quoted 2 lines
Also, what happens when the system crashes, and one drive has several hundred megabytes data more than the other one?
This shouldn't be an issue as long as you occasionally run a scrub or balance. The scrub should find it and fix the missing data, and a balance would just rewrite it as proper RAID-1 as a matter of course.
It's similar (writes to just one drive, while the other is idle) when removing (many) snapshots.
Not sure if that's optimal behaviour.
Signature · 2 lines
Tomasz Chmielewski http://wpkg.org
Quoted 9 lines · Tomasz Chmielewski
Quoted 6 lines · On Fri, 16 May 2014 14:06:24 -0400 Calvin Walton <[email protected]>…
No comment on the performance issue, other than to say that I've seen similar on RAID-10 before, I think.
Quoted 2 lines
Also, what happens when the system crashes, and one drive has several hundred megabytes data more than the other one?
Quoted 9 lines
Quoted 3 lines
This shouldn't be an issue as long as you occasionally run a scrub or balance. The scrub should find it and fix the missing data, and a balance would just rewrite it as proper RAID-1 as a matter of course.
It's similar (writes to just one drive, while the other is idle) when removing (many) snapshots.
Not sure if that's optimal behaviour.
I think, after having looked at some of the code, that I know what is causing this (although my interpretation of the code may be completely off target). As far as I can make out, BTRFS only dispatches writes to one device at a time, and the write() system call only returns when the data is on both devices. While dispatching to one device at a time is optimal when both 'devices' are partitions on the same underlying disk (and also if your optimization metric is the simplicity of the underlying code), it degrades very fast to the worst case when using multiple devices. The underlying cause however, which the one device at a time logic in BTRFS just makes much worse, is that the buffer for the write() call is kept in memory until the write completes, and counts against the per-process write-caching limit, and when the process fills up it's write-cache, the next call it makes that would write to the disk hangs until the write cache is less full.
The two options that I've found that work around this are:
1. Run 'sync' whenever the program stalls, or
2. Disable write-caching by adding the following to /etc/sysctl.conf vm.dirty_bytes = 0
vm.dirty_background_bytes = 0
Option 1 is kind of tedious, but doesn't hurt performance all that much, Option 2 will lower throughput, but will cause most of the stalls to disappear.
Ideally, BTRFS should dispatch the first write for a block in a round-robin fashion among available devices. This won't fix the underlying issue, but it will make it less of an issue for BTRFS.
Quoted 15 lines · Austin S Hemmelgarn
Quoted 14 lines · Tomasz Chmielewski
Quoted 8 lines · On Fri, 16 May 2014 14:06:24 -0400 Calvin Walton <[email protected]>…
No comment on the performance issue, other than to say that I've seen similar on RAID-10 before, I think.
Quoted 2 lines
Also, what happens when the system crashes, and one drive has several hundred megabytes data more than the other one?
This shouldn't be an issue as long as you occasionally run a scrub or balance. The scrub should find it and fix the missing data, and a balance would just rewrite it as proper RAID-1 as a matter of course.
It's similar (writes to just one drive, while the other is idle) when removing (many) snapshots.
Quoted 8 lines
Quoted 2 lines
Not sure if that's optimal behaviour.
[snip]
Ideally, BTRFS should dispatch the first write for a block in a round-robin fashion among available devices. This won't fix the underlying issue, but it will make it less of an issue for BTRFS.
More ideally, btrfs should dispatch them in parallel. This will likely be looked into for N-way mirroring. Having 3 or more copies and working in the current way would be far from optimal.
Signature · 4 lines
__________ Brendan Hide http://swiftspirit.co.za/ http://www.webafrica.co.za/?AFF1E97
Quoted 9 lines · On Fri, 16 May 2014 17:36:57 -0400 Austin S Hemmelgarn <[email protected]>…
Quoted 5 lines
It's similar (writes to just one drive, while the other is idle) when removing (many) snapshots.
Not sure if that's optimal behaviour.
I think, after having looked at some of the code, that I know what is causing this (although my interpretation of the code may be completely off target). As far as I can make out, BTRFS only dispatches writes to one device at a time
Yes, I can confirm this... yesterday I was writing large files to my Btrfs RAID1 of two devices, and remembering this thread, decided to take a look at how the writes are performed. And indeed in 'iostat' it was clear that only one device works at a time. In my case, first one drive was writing at 80-100 MB/sec for 5-10 seconds, then activity on that once ceased entirely, and the second drive started writing for the same period at similar speeds.
In effect this is causing the whole operation take about 2x longer than ideal (or in case of just a single device Btrfs). Surprising that this performance drawback of Btrfs RAID1 is not more widely known or discussed.
Signature · 2 lines
With respect, Roman