bench: Add logging benchmark #18815

pull MarcoFalke wants to merge 2 commits into bitcoin:master from MarcoFalke:2004-benchLog changing 2 files +64 −15
  1. MarcoFalke commented at 12:53 PM on April 29, 2020: member

    Might make finding performance bottlenecks or regressions (https://github.com/bitcoin/bitcoin/pull/17218) easier.

    For example, fuzzing relies on disabled logging to be as fast as possible.

  2. DrahtBot added the label Build system on Apr 29, 2020
  3. fanquake removed the label Build system on Apr 29, 2020
  4. fanquake added the label Tests on Apr 29, 2020
  5. MarcoFalke force-pushed on Apr 29, 2020
  6. DrahtBot commented at 4:24 PM on April 29, 2020: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #22702 (Add allocator for node based containers by martinus)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  7. MarcoFalke removed the label Tests on Apr 29, 2020
  8. DrahtBot added the label Build system on Apr 29, 2020
  9. MarcoFalke removed the label Build system on Apr 29, 2020
  10. DrahtBot added the label Build system on Apr 29, 2020
  11. DrahtBot added the label Tests on Apr 29, 2020
  12. MarcoFalke removed the label Build system on Apr 29, 2020
  13. practicalswift commented at 6:23 PM on April 29, 2020: contributor

    Concept ACK

  14. practicalswift commented at 7:05 PM on April 29, 2020: contributor

    Would it make sense to also benchmark the logging setup we use in the fuzz tests to avoid logging to disk?

        static TestingSetup setup{
            CBaseChainParams::REGTEST,
            {
                "-nodebuglogfile",
            },
        };
    
  15. DrahtBot cross-referenced this on Apr 29, 2020 from issue util: Pass size to ParseHex to assist preallocation by elichai
  16. DrahtBot cross-referenced this on Apr 29, 2020 from issue Avoid unnecessary signing provider copies on descriptor expansion by Empact
  17. DrahtBot cross-referenced this on Apr 29, 2020 from issue Faster sigcache nonce by JeremyRubin
  18. laanwj commented at 8:11 AM on April 30, 2020: member

    To be honest, I think the idea of logging being performance critical is a bit scary. It was never meant like this. We shouldn't log in inner loops and such. Sure, debug flags are enabled it's different but one can expect a performance hit in that case. It's not really something to optimize for IMO.

    (not opposed to adding a benchmark, but I just think it's not a very high priority thing to optimize and a benchmark encourages this)

    Edit: I understand it now in the context of #18678

  19. MarcoFalke commented at 12:09 PM on April 30, 2020: member

    Jup, this is not primarily to encourage people to optimize this function, but rather to make finding performance bottlenecks (https://github.com/bitcoin/bitcoin/issues/18538#issuecomment-614898713) or regressions (#17218) easier.

  20. jb55 commented at 10:07 AM on May 2, 2020: contributor

    I think a big issue with the logging is that it does a bunch of string concatenation and allocation for formatting, instead of format strings+printf. When you do this in a tight loop/IBD, I'm not surprised that you would see performance issues.

    My guess for the thread_local issue is just the fact that it has to allocate and concatenate even more when it formats threads names into the log.

  21. MarcoFalke commented at 11:57 AM on May 2, 2020: member

    The strings are written to disk unbuffered:

    https://github.com/bitcoin/bitcoin/blob/844d2070a2c0106bb7a54be5cad7d4da4d9cd55e/src/logging.cpp#L56

    If I had to guess, even with SSD this might be the dominant factor, and not memory allocation for strings.

  22. MarcoFalke added the label Needs Guix build on May 2, 2020
  23. MarcoFalke added the label Needs gitian build on May 2, 2020
  24. DrahtBot removed the label Needs Guix build on May 3, 2020
  25. DrahtBot removed the label Needs gitian build on May 4, 2020
  26. jamesob approved
  27. jamesob commented at 3:35 PM on May 5, 2020: member

    ACK fa22a52f2aae3d1962a386d973de192e0de8fd65 (jamesob/ackr/18815.1.MarcoFalke.bench_add_logging_benchm)

    Built and tested with ./src/bench/bench_bitcoin -filter='.*Logging.*'.

    Seems like a no-brainer to have this benchmark data on hand to avoid embarrassing regressions due to some quirk in the logging system.

    Worth noting that some effort was made previously to move logging to a separate thread (#13200), though I think that implementation did do string interpolation inline (synchronously). I had tried to move interpolation to the logging thread, but the difficulty of __VA_ARGS__ and getting the right function signatures deterred me; may be doable though.

    <details><summary>Show platform data</summary> <p>

    Tested on Linux-5.3.0-51-generic-x86_64-with-Ubuntu-18.04-bionic
    
    Configured with ./configure LDFLAGS=-L/home/james/src/bitcoin/db4/lib/ CPPFLAGS=-I/home/james/src/bitcoin/db4/include/ CXXFLAGS=-std=c++11 -Werror=thread-safety-analysis --enable-wallet --enable-debug --with-daemon CXX=/usr/bin/clang++-4.0 CC=/usr/bin/clang-4.0 PYTHONPATH= --disable-shared --with-pic --enable-benchmark=no --with-bignum=no --enable-module-recovery --disable-jni --disable-shared --with-pic --enable-benchmark=no --with-bignum=no --enable-module-recovery --disable-jni --no-create --no-recursion
    
    Compiled with /usr/bin/ccache /usr/bin/clang++-4.0 -std=c++11 -mavx -mavx2 -std=c++11 -Werror=thread-safety-analysis -O0 -g3 -ftrapv  -Wstack-protector -fstack-protector-all -msse4 -msha -msse4.1 -msse4.2  i
    
    Compiler version: clang version 4.0.1-10 (tags/RELEASE_401/final)
    

    </p></details>

    <details><summary>Show signature data</summary> <p>

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    ACK fa22a52f2aae3d1962a386d973de192e0de8fd65 ([`jamesob/ackr/18815.1.MarcoFalke.bench_add_logging_benchm`](https://github.com/jamesob/bitcoin/tree/ackr/18815.1.MarcoFalke.bench_add_logging_benchm))
    
    Built and tested with `./src/bench/bench_bitcoin -filter='.*Logging.*'`. 
    
    Seems like a no-brainer to have this benchmark data on hand to avoid embarrassing 
    regressions due to some quirk in the logging system.
    
    Worth noting that some effort was made previously to move logging to a separate
    thread (#13200), though I think that implementation did do string interpolation
    inline (synchronously). I had tried to move interpolation to the logging
    thread, but the difficulty of `__VA_ARGS__` and getting the right function
    signatures deterred me; may be doable though.
    
    
    <details><summary>Show platform data</summary>
    <p>
    
    

    Tested on Linux-5.3.0-51-generic-x86_64-with-Ubuntu-18.04-bionic

    Configured with ./configure LDFLAGS=-L/home/james/src/bitcoin/db4/lib/ CPPFLAGS=-I/home/james/src/bitcoin/db4/include/ CXXFLAGS=-std=c++11 -Werror=thread-safety-analysis --enable-wallet --enable-debug --with-daemon CXX=/usr/bin/clang++-4.0 CC=/usr/bin/clang-4.0 PYTHONPATH= --disable-shared --with-pic --enable-benchmark=no --with-bignum=no --enable-module-recovery --disable-jni --disable-shared --with-pic --enable-benchmark=no --with-bignum=no --enable-module-recovery --disable-jni --no-create --no-recursion

    Compiled with /usr/bin/ccache /usr/bin/clang++-4.0 -std=c++11 -mavx -mavx2 -std=c++11 -Werror=thread-safety-analysis -O0 -g3 -ftrapv -Wstack-protector -fstack-protector-all -msse4 -msha -msse4.1 -msse4.2 i

    Compiler version: clang version 4.0.1-10 (tags/RELEASE_401/final)

    
    </p></details>
    -----BEGIN PGP SIGNATURE-----
    
    iQIzBAEBCgAdFiEEpm2+LMqPsWj2rAwWyrywS1A+5mgFAl6xh6UACgkQyrywS1A+
    5mjoJg//ZgjGIa7dmzkSwvbUHW0sg/u2ShTCsOrWWfx6cdZ7ApQlPOH5nDcjO7yb
    Qr61POE/3uA3kUrcUvVvlwqStpbwbjqNNNR5g8OklGE/N2N4Q621ze1vtmWJOuU2
    ik7APJT3MlU/fOEEqRGSdS9Jow2P45CqrPTSgCjJA0oPlhTn6lrtaCtDEgT/dFR3
    TJlHO/Oe53zK2wpkzUVzKXswvNLsSSPYHIIp/hFYRNanfnnmFg16YTD73sr+CrSV
    K6JGkTbIwtXEIHRuIglTHRMW46U3MoAMhg2/e1L4Ssdq1oUI0aCUNC7nww066zI6
    1reKeu+fkfOVLAYNb+Ke18GqOrWwBdPUut+o8bTvK43nMYZHH2eRL/4orS/WKSWG
    PGV1qSBDY8F7DdtLUeIXmvWxZbCFubFFpx/zl/Ur8S9+Hr96jWilt9l8t2FOhzbF
    nzCV+LkfUYhpHYFgCxtXg3px6sKQ02S3A8NyyfWTkE/LIAMKrDcAG8JJxOeuAAMm
    iay0gemRuqZKA4zGrhZTc85Js0Qjpu9LAnpWSNKraGEzwbxLCNIFN9J0LvogERhn
    +4RbxIyJewk5P4Sb6k+lTuegmBu3CjfyohCndfuPEGdFI/++cd/ynIXlhDIjvDxq
    CeeYGoBm8SjxtEMkeBCeuw4G+tZCfB2n8m8VccknjInX7t0lQSM=
    =yVlS
    -----END PGP SIGNATURE-----
    
    

    </p></details>

  28. elichai commented at 2:58 PM on May 18, 2020: contributor

    Worth noting that some effort was made previously to move logging to a separate thread (#13200), though I think that implementation did do string interpolation inline (synchronously). I had tried to move interpolation to the logging thread, but the difficulty of VA_ARGS and getting the right function signatures deterred me; may be doable though.

    Is it? because LogPrintf accepts the inputs as references, so if you pass those to a thread and run tfm::format in that thread you might have a dangling reference or a data race here.

  29. DrahtBot added the label Needs rebase on Jun 2, 2020
  30. MarcoFalke force-pushed on Jun 2, 2020
  31. MarcoFalke closed this on Jun 2, 2020

  32. MarcoFalke reopened this on Jun 2, 2020

  33. DrahtBot removed the label Needs rebase on Jun 2, 2020
  34. DrahtBot cross-referenced this on Jun 13, 2020 from issue Replace current benchmarking framework with nanobench by martinus
  35. bitcoin deleted a comment on Jun 18, 2020
  36. bitcoin deleted a comment on Jun 18, 2020
  37. DrahtBot cross-referenced this on Jun 25, 2020 from issue bench: Add OrphanTxPool benchmark by hebasto
  38. DrahtBot cross-referenced this on Jul 7, 2020 from issue multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky
  39. DrahtBot cross-referenced this on Jul 7, 2020 from issue multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky
  40. DrahtBot added the label Needs rebase on Jul 30, 2020
  41. bench: Add logging benchmark fa31dc9b71
  42. bench: Sort bench_bench_bitcoin_SOURCES fafe06c379
  43. MarcoFalke force-pushed on Dec 15, 2021
  44. DrahtBot removed the label Needs rebase on Dec 15, 2021
  45. DrahtBot cross-referenced this on Dec 16, 2021 from issue Add allocator for node based containers by martinus
  46. DrahtBot cross-referenced this on Dec 16, 2021 from issue util: improve FindByte() performance by LarryRuane
  47. dergoegge cross-referenced this on Mar 10, 2022 from issue log: Mitigate disk filling attacks by rate limiting LogPrintf by dergoegge
  48. dergoegge commented at 10:14 PM on March 10, 2022: member

    ACK fafe06c379316f165e88b8de7300a716cef25d0a

    Tested with ./src/bench/bench_bitcoin -filter="Logging.*"

    These benchmarks were helpful to me in answering this review comment on my log rate limting PR.

  49. MarcoFalke merged this on Mar 16, 2022
  50. MarcoFalke closed this on Mar 16, 2022

  51. MarcoFalke deleted the branch on Mar 16, 2022
  52. sidhujag referenced this in commit 0606f79a2e on Mar 16, 2022
  53. jonatack cross-referenced this on Jan 23, 2023 from issue bench: update logging benchmarks by jonatack
  54. bitcoin locked this on Mar 16, 2023

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-05-20 06:54 UTC