How to obtain good concurrent read performance from disk

后端 未结 6 897
我寻月下人不归
我寻月下人不归 2021-01-31 18:12

I\'d like to ask a question then follow it up with my own answer, but also see what answers other people have.

We have two large files which we\'d like to read from two

6条回答
  •  孤街浪徒
    2021-01-31 18:36

    I'd like to add some further notes in my response. All other non-Microsoft operating systems we have tested do not suffer from this problem. Linux, FreeBSD, and Mac OS X (this final one on different hardware) all degrade much more gracefully in terms of aggregate bandwidth when moving from one thread to two. Linux for example degraded from ~45 MiB/sec to ~42 MiB/sec. These other operating systems must be reading larger chunks of the file between each seek, and therefor not spending nearly all their time waiting on the disk to seek.

    Our solution for Windows is to pass the FILE_FLAG_NO_BUFFERING flag to CreateFile and use large (~16MiB) reads in each call to ReadFile. This is suboptimal for several reasons:

    • Files don't get cached when read like this, so there are none of the advantages that caching normally gives.
    • The constraints when working with this flag are much more complicated than normal reading (alignment of read buffers to page boundaries, etc).

    (As a final remark. Does this explain why swapping under Windows is so hellish? Ie, Windows is incapable of doing IO to multiple files concurrently with any efficiency, so while swapping all other IO operations are forced to be disproportionately slow.)


    Edit to add some further details for Will Dean:

    Of course across these different hardware configurations the raw figures did change (sometimes substantially). The problem however is the consistent degradation in performance that only Windows suffers when moving from one thread to two. Here is a summary of the machines tested:

    • Several Dell workstations (Intel Xeon) of various ages running Windows 2000, Windows XP (32-bit), and Windows XP (64-bit) with single drive.
    • A Dell 1U server (Intel Xeon) running Windows Server 2003 (64-bit) with RAID 1+0.
    • An HP workstation (AMD Opteron) with Windows XP (64-bit), and Windows Server 2003, and hardware RAID 5.
    • My home unbranded PC (AMD Athlon64) running Windows XP (32-bit), FreeBSD (64-bit), and Linux (64-bit) with single drive.
    • My home MacBook (Intel Core1) running Mac OS X, single SATA drive.
    • My home Koolu PC running Linux. Vastly underpowered compared to the other systems but I demonstrated that even this machine can outperform a Windows server with RAID5 when doing multi-threaded disk reads.

    CPU usage on all of these systems was very low during the tests and anti-virus was disabled.

    I forgot to mention before but we also tried the normal Win32 CreateFile API with the FILE_FLAG_SEQUENTIAL_SCAN flag set. This flag didn't fix the problem.

提交回复
热议问题