Re: Horrible CREATE DATABASE Performance in High Sierra
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Brent Dearth <brent.dearth@gmail.com>
Cc: Andres Freund <andres@anarazel.de>, pgsql-hackers@postgresql.org
Date: 2017-10-07T20:46:55Z
Lists: pgsql-hackers
Attachments
- smarter-flush-distance-choice-1.patch (text/x-diff) patch
I wrote: > Current status is that I've filed a bug report with Apple and am waiting > to see their response before deciding what to do next. If they fix the > issue promptly then there's little need for us to do anything. Not having heard a peep from Apple yet, I decided to do a bit more experimenting. I found that indeed, issuing fewer and larger mmap/msync requests helps enormously. If you're willing to go as far as issuing only one per file, the speed seems on par with non-fsync. But that requires being able to mmap 1GB-sized files, so it's probably not something we want to do. What I did instead was to adjust the logic in copy_file() so that the unit of flush requests can be a multiple of the unit of read/write requests. (My original thought of just raising the buffer size seems like not as good an idea; it's less cache-friendly for one thing.) I find that on both Linux and macOS-with-HFS, requesting a flush only every 1MB seems to be a win compared to flushing every 64KB as we currently do. Actually it seems that on macOS, every increment of increase in the flush distance helps, but with HFS you hit diminishing returns after 1MB or so. With APFS you need a flush distance of 32MB or more to have credible performance. Accordingly I propose the attached patch. If anyone's interested in experimenting on other platforms, we might be able to refine/complicate the FLUSH_DISTANCE selection further, but I think this is probably good enough for a first cut. regards, tom lane
Commits
-
Increase distance between flush requests during bulk file copies.
- c3723317d08c 10.1 landed
- 643c27e36ff3 11.0 landed
- 13a8924ecf00 9.6.6 landed