Skip to content

Instantly share code, notes, and snippets.

@pklaus
Created March 12, 2020 15:24
Show Gist options
  • Select an option

  • Save pklaus/36fb8c45fa786d45b85025bbae3f4ab2 to your computer and use it in GitHub Desktop.

Select an option

Save pklaus/36fb8c45fa786d45b85025bbae3f4ab2 to your computer and use it in GitHub Desktop.

Revisions

  1. pklaus created this gist Mar 12, 2020.
    52 changes: 52 additions & 0 deletions pg_test_fsync
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    $ uname -a
    Linux owl 5.5.8-arch1-1 #1 SMP PREEMPT Fri, 06 Mar 2020 00:57:33 +0000 x86_64 GNU/Linux
    $ cat /etc/os-release
    NAME="Arch Linux"
    PRETTY_NAME="Arch Linux"
    ID=arch
    BUILD_ID=rolling
    ANSI_COLOR="0;36"
    HOME_URL="https://www.archlinux.org/"
    DOCUMENTATION_URL="https://wiki.archlinux.org/"
    SUPPORT_URL="https://bbs.archlinux.org/"
    BUG_REPORT_URL="https://bugs.archlinux.org/"
    $ pg_config --version
    PostgreSQL 12.2

    $ pg_test_fsync
    5 seconds per test
    O_DIRECT supported on this platform for open_datasync and open_sync.

    Compare file sync methods using one 8kB write:
    (in wal_sync_method preference order, except fdatasync is Linux's default)
    open_datasync 34040.623 ops/sec 29 usecs/op
    fdatasync 33762.892 ops/sec 30 usecs/op
    fsync 31874.647 ops/sec 31 usecs/op
    fsync_writethrough n/a
    open_sync 31882.292 ops/sec 31 usecs/op

    Compare file sync methods using two 8kB writes:
    (in wal_sync_method preference order, except fdatasync is Linux's default)
    open_datasync 28638.931 ops/sec 35 usecs/op
    fdatasync 28652.748 ops/sec 35 usecs/op
    fsync 28329.926 ops/sec 35 usecs/op
    fsync_writethrough n/a
    open_sync 28294.717 ops/sec 35 usecs/op

    Compare open_sync with different write sizes:
    (This is designed to compare the cost of writing 16kB in different write
    open_sync sizes.)
    1 * 16kB open_sync write 28022.049 ops/sec 36 usecs/op
    2 * 8kB open_sync writes 28228.306 ops/sec 35 usecs/op
    4 * 4kB open_sync writes 16144.664 ops/sec 62 usecs/op
    8 * 2kB open_sync writes 4352.070 ops/sec 230 usecs/op
    16 * 1kB open_sync writes 1836.779 ops/sec 544 usecs/op

    Test if fsync on non-write file descriptor is honored:
    (If the times are similar, fsync() can sync data written on a different
    descriptor.)
    write, fsync, close 31803.079 ops/sec 31 usecs/op
    write, close, fsync 31768.603 ops/sec 31 usecs/op

    Non-sync'ed 8kB writes:
    write 569657.775 ops/sec 2 usecs/op