Does RAID1 increase performance with Linux mdadm?

25,909

Solution 1

Yes, Linux implementation of RAID1 speeds up disk read operations by a factor of two as long as two separate disk read operations are performed at the same time. That means reading one 10GB file won't be any faster on RAID1 than on a single disk, but reading two distinct 10GB files*will be faster.

To demonstrate it, just read some data with dd. Before performing anything, clear the disk read cache with sync && echo 3 > /proc/sys/vm/drop_caches. Otherwise hdparm will claim super fast reads.

Single file:

# COUNT=1000; dd if=/dev/md127 of=/dev/null bs=10M count=$COUNT &
(...)
10485760000 bytes (10 GB) copied, 65,9659 s, 159 MB/s

Two files:

# COUNT=1000; dd if=/dev/md127 of=/dev/null bs=10M count=$COUNT &; dd if=/dev/md127 of=/dev/null bs=10M count=$COUNT skip=$COUNT &
(...)
10485760000 bytes (10 GB) copied, 64,9794 s, 161 MB/s
10485760000 bytes (10 GB) copied, 68,6484 s, 153 MB/s

Reading 10 GB of data took 65 seconds whereas reading 10 GB + 10 GB = 20 GB data took 68.7 seconds in total, which means multiple disk reads benefit greatly from RAID1 on Linux. skip=$COUNT part is very important. The second process reads 10 GB of data from the 10 GB offset.

Jared's answer and ssh's comments refering to http://www.unicom.com/node/459 are wrong. The benchmark from there proves disk reads don't benefit from RAID1. However, the test was performed with bonnie++ benchmarking tool which doesn't perform two separate reads at one time. The author explictly states bonnie++ is not usable for benchmarking RAID arrays (refer to readme).

Solution 2

Yes, you will get a reading performance boost + the redundancy. You can easily imagine that as you can read the parts of the files at the same from two different HDDs as the files are on both of the HDDs.

So theoretically, if the RAID controller does its job right, you could gain a speedup of O(n).

Solution 3

  • man 4 md states: "… Note that the read balancing done by the driver does not make the RAID1 performance profile be the same as for RAID0; a single stream of input will not be accelerated (e.g. a single dd), but multiple sequential streams or a random workload will use more than one spindle. In theory, having an N-disk RAID1 will allow N sequential threads to read from all disks. …"

  • To top it off — in practice, based on iostat output being observed on a typical 2 HDDs software RAID set-up, there's none of balancing. In fact it effectively looks like mdadm's option --write-mostly is always on.

Solution 4

No, you will not receive any benefits while reading from mdadm RAID1. I was asking myself about this some time ago.

dstat shows disks usage, also bwm-ng really helps especially in this case, since it can show read/write usage on separate mdadm RAID members. Just push n (next) a few times, it will switch from interface statistics to disk stats. Then switch to max values with t to see max read/writes from each disk. You will see following:

Doing write to RAID1 volume bwm-ng shows 2 x writes, writing to 2 disks at same time. Doing read from RAID1 volume bwm-ng shows reading from single drive (array member).

Solution 5

YES and NO at the same time. By default RAID 1 "read ahead" parameter is too low to notice the benefit on a single file transfer, however all you have to do is to adjust it.

In order to check your value type in:

# blockdev --getra /dev/md0
256

Now you can set read ahead (in 512-byte sectors) per raid device. The syntax is:

## Set read-ahead to 32 MiB ##
# blockdev --setra 65536 /dev/md0

In most cases just setting this parameter will double the single file read speed (assuming both drives are the same).

Note: This is applicable to all raid configurations.

Share:
25,909

Related videos on Youtube

Jesse
Author by

Jesse

Updated on September 18, 2022

Comments

  • Jesse
    Jesse over 1 year

    I have a cheap 2-bay NAS with a 2TB HDD. To be robust against disk failure, I'm thinking of buying a second 2TB HDD and putting it in RAID1 with Linux mdadm. The file system is ext4.

    Will this increase or decrease the performance of the NAS? What about just read or write performance?

    There seem to be lots of opinions about this online but no consensus.

    Thanks.

    Edit:

    So already I've got three different answers: "a fair bit faster", "you wont notice" and "will decrease the performance if anything". (I am interested primarily in read performance.) Wikipedia says "the read performance can go up roughly as a linear multiple of the number of copies". Which one is it?

    Edit 2:

    I've found mounting evidence in support of RAID1 increasing read performance, including the MD manpage:

    Changes are written to all devices in parallel. Data is read from any one device. The driver attempts to distribute read requests across all devices to maximise performance.

    I also discovered MD's RAID10 with --layout=f2, which provides redundancy of RAID1 with the read performance of RAID0, and can be used with just two drives. The write performance is reduced however, as a sequential write involves both drives seeking back and forth between distant parts of the drive. man md for details.

    • Admin
      Admin over 12 years
      writes; a little slower. reads; a fair bit faster. From what i understand, the write difference is nearly zero though, and the read is pretty noticeable.
    • Admin
      Admin over 12 years
      Just what sirex says.. you wont notice performance difference with the bare eye.. Dont expect to double it or even half it.
    • Admin
      Admin over 8 years
    • Admin
      Admin over 8 years
      I miss one part: How fast is access to the NAS. If one disk already fills the network connection then more internal speed will not help you much.
  • Vijay Prakash Desetty
    Vijay Prakash Desetty over 12 years
    mdadm is software RAID so there is actually no "RAID controller" but it will provide a good read boost when doing multplie reads in parallel, not so much in this case I suppose as a NAS box is rarely concurently acccessed. See here for details: freebsdwiki.net/index.php/…
  • ssh
    ssh over 10 years
    In practice the performance decreases for reading from Linux Software MD raid. See unicom.com/node/459 (In that test the read speed decreased from 77 MB/s to 74 MB/s).
  • Nowaker
    Nowaker almost 10 years
    @ssh unicom.com/node/459 is totally wrong. bonnie++ is not usable for testing RAID mirrors, which is explicitly stated in the readme. See my answer for more details. superuser.com/a/757264/68978
  • Peleion
    Peleion almost 4 years
    On my Fedora RAID1 the read-ahead defaults to 8192
  • Community
    Community about 2 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.