Move logging to background thread #17216

issue maflcko opened this issue on October 22, 2019
  1. maflcko commented at 1:15 PM on October 22, 2019: member

    To increase parallelism, the logging could be moved to a background thread.

    Currently, writing to the debug log is done in-line (synchronous) and unbuffered. See https://github.com/bitcoin/bitcoin/blob/a22b62481aae95747830bd3c0db3227860b12d8e/src/logging.cpp#L56 That means that on slow disks (non-ssd, mostly), calls to LogPrint*() are potentially expensive and blocking further execution of the calling thread (potentially the net processing or validation thread).

    Moving logging to a background thread should be fine, except for some edge cases:

    • We use assert_debug_log in the functional tests, which assume that a message is written to the debug log synchronous. However, the recently added polling to assert_debug_log should work around that.
    • The logging thread should probably be started when logging is started and shut down when the node is shut down. Calls to logging during shutdown should probably be in-line.
  2. maflcko added the label Brainstorming on Oct 22, 2019
  3. maflcko added the label Utils/log/libs on Oct 22, 2019
  4. promag commented at 1:23 PM on October 22, 2019: member

    Like #13200?

  5. maflcko commented at 1:25 PM on October 22, 2019: member

    Ah, yes. "Up for grabs" I guess.

  6. adamjonas commented at 6:12 PM on October 23, 2019: member

    I have a branch of a rebased #13200. I could use some help benchmarking to make a good case for reopening.

  7. maflcko commented at 5:42 PM on October 24, 2019: member

    The instructions on how to run bitcoinperf are here: https://github.com/chaincodelabs/bitcoinperf#example-local-usage-no-docker

    I'd suggest to not run it on your normal machine, as it installs quite a bunch of crap.

  8. adamjonas commented at 7:53 PM on October 28, 2019: member

    Ran some benchmarks on an HDD machine:

    In all, we saw a 2.6% speed-up from for the first 200,000 blocks and a negligible slow down for blocks 500,000 to 525,000 with a 1% reduction in peak memory usage.

    First 200_000 blocks

    async-log vs. master (absolute)

    bench name # of runs async-log master
    ibd.local.200000.total_secs 2 179.3786 (± 0.2791) 184.0771 (± 1.5131)
    ibd.local.200000.peak_rss_KiB 2 771078.0000 (± 322.0000) 771026.0000 (± 82.0000)

    async-log vs. master (relative)

    bench name # of runs async-log master
    ibd.local.200000.total_secs 2 1.000 1.026
    ibd.local.200000.peak_rss_KiB 2 1.000 1.000

    ibd local 200000

    Blocks 500_000 to 525_000

    async-log vs. master (absolute)

    bench name # of runs async-log master
    ibd.local.range.500000.525000.total_secs 2 2619.9838 (± 2.5637) 2615.2636 (± 4.9015)
    ibd.local.range.500000.525000.peak_rss_KiB 2 4489636.0000 (± 604.0000) 4538482.0000 (± 910.0000)

    async-log vs. master (relative)

    bench name # of runs async-log master
    ibd.local.range.500000.525000.total_secs 2 1.002 1.000
    ibd.local.range.500000.525000.peak_rss_KiB 2 1.000 1.011

    ibd local range 500000 525000

    Ran on:

    cpu_model_name         Intel(R) Xeon(R) CPU E3-1220 v5 @ 3.00GHz
    ram_gb                 7.712368011474609
    os                     ['Debian GNU/Linux', '9', 'stretch']
    arch                   x86_64
    kernel                 4.9.0-8-amd64
    read_iops (/tmp)       214
    write_iops (/tmp)      71
    read_iops (.)          255
    write_iops (.)         84
    
  9. maflcko commented at 1:26 PM on April 17, 2020: member

    There is evidence that logging slows down some tasks by a factor of 5 (500% overhead) on non-intel low-end machines:

  10. willcl-ark commented at 4:20 PM on September 21, 2023: member

    The feature request didn't seem to attract much attention in the past. Also, the issue seems not important enough right now to keep it sitting around idle in the list of open issues.

    Pull requests with improvements are always welcome.

  11. willcl-ark closed this on Sep 21, 2023

  12. mmortal03 commented at 4:34 PM on September 21, 2023: none

    Also, the issue seems not important enough right now to keep it sitting around idle in the list of open issues.

    Isn't that a point of labels and milestones? You can leave issues open to accumulate various perspectives for reference, and just mark the particular issues being worked on for the current milestones?

  13. maflcko commented at 4:38 PM on September 21, 2023: member

    The issue will be around forever. It is just closed, not removed. But if there is little gain and interest, it doesn't make sense to keep it open forever. Otherwise the list would be unbounded, because there are unlimited ideas that one can come up with that provide a little edge-case gain and have trade-offs.

  14. bitcoin locked this on Sep 20, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me