Add local thread pool to CCheckQueue #18710

pull hebasto wants to merge 5 commits into bitcoin:master from hebasto:200419-thread-pool changing 9 files +97 −96
  1. hebasto commented at 2:51 PM on April 20, 2020: member

    This PR:

    Also, with this PR (I hope) it could be easier to resurrect a bunch of brilliant ideas from #9938.

    Related: #17307

  2. MarcoFalke added the label Refactoring on Apr 20, 2020
  3. MarcoFalke added the label Validation on Apr 20, 2020
  4. MarcoFalke added this to the "In progress" column in a project

  5. MarcoFalke commented at 3:13 PM on April 20, 2020: member

    Concept ACK on getting rid of boost in consensus code. This pull looks similar to #14464?

  6. MarcoFalke commented at 3:14 PM on April 20, 2020: member

    Also, with this PR (I hope) it could be easier to resurrect a bunch of brilliant ideas from #9938.

    cc @JeremyRubin

  7. hebasto commented at 3:16 PM on April 20, 2020: member

    @MarcoFalke

    Concept ACK on getting rid of boost in consensus code. This pull looks similar to #14464?

    Thanks for pointing to #14464. I'll look into it.

  8. DrahtBot commented at 4:06 PM on April 20, 2020: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  9. DrahtBot cross-referenced this on Apr 20, 2020 from issue Make g_chainman internal to validation by MarcoFalke
  10. DrahtBot cross-referenced this on Apr 20, 2020 from issue Prevent consecutive ::cs_main locks by hebasto
  11. DrahtBot cross-referenced this on Apr 20, 2020 from issue coins: allow cache resize after init by jamesob
  12. DrahtBot cross-referenced this on Apr 20, 2020 from issue bench: Remove requirement that all benches use same testing setup by MarcoFalke
  13. hebasto force-pushed on Apr 20, 2020
  14. hebasto commented at 5:48 PM on April 20, 2020: member

    Updated 9764d81e1f000d1bd3c03ac6f6f4361c4aa84ee9 -> f4cd37e93a522d5ab2bc872d129a0142be773a7d (pr18710.01 -> pr18710.02, diff):

    • fixed linter issue with boost headers
  15. JeremyRubin commented at 6:27 AM on April 21, 2020: contributor

    Nice! From a simple code review PoV it looks good.

    I remember there being a bunch of subtle nasties in the specifics of using std::threads v.s. boost threads around interrupt system and the details of how condition variables work. I can't remember what they all were though now. I think #14464 closed because of that...

    But generally huge concept ack on anything that makes #9938 more likely to move forward! Note though that the cuckoocache sort of stole it's thunder -- a lot of the contention in the CheckQueue was around the sigcache locking and the cuckoocache made that stuff way faster so it's not obvious #9938 will show as impressive gains, and the trade offs for consensus code may be less worth it. Can discuss more via IRC; I'd love to get some of the improvements through in any case.

  16. hebasto commented at 5:08 PM on April 21, 2020: member

    @MarcoFalke

    Concept ACK on getting rid of boost in consensus code. This pull looks similar to #14464?

    The differences from #14464 are:

  17. hebasto force-pushed on Apr 21, 2020
  18. hebasto commented at 9:14 PM on April 21, 2020: member

    Updated f4cd37e93a522d5ab2bc872d129a0142be773a7d -> b02bc2583e421dbca35a5652c650ae861230f480 (pr18710.02 -> pr18710.03, diff):

    • picked some ideas from #14464
    • reduced scope of the PR (some commits has been moved into the #18731)
    • OP updated (now every commit passes unit tests)
  19. hebasto commented at 10:28 PM on April 21, 2020: member

    Benchmark results on my machine:

    • master (a998c5185bc7fc2c7e22312fac60175cb2869bdd)
    # Benchmark, evals, iterations, total, min, max, median
    CCheckQueueSpeedPrevectorJob, 100, 1400, 96.3747, 0.000677139, 0.000695471, 0.000688339
    
    • this PR (b02bc2583e421dbca35a5652c650ae861230f480)
    # Benchmark, evals, iterations, total, min, max, median
    CCheckQueueSpeedPrevectorJob, 100, 1400, 77.4393, 0.000545271, 0.00057892, 0.000552496
    
  20. hebasto cross-referenced this on Apr 22, 2020 from issue refactor: Make CCheckQueue RAII-styled by hebasto
  21. DrahtBot added the label Needs rebase on Apr 22, 2020
  22. hebasto force-pushed on Apr 22, 2020
  23. hebasto commented at 10:52 PM on April 22, 2020: member

    Rebased b02bc2583e421dbca35a5652c650ae861230f480 -> https://github.com/bitcoin/bitcoin/commit/f16f7f79dcd5d6c1b55966317b8762abeb5561c3 (pr18710.03 -> pr18710.04) due to the conflict with #18575.

  24. DrahtBot removed the label Needs rebase on Apr 23, 2020
  25. in src/checkqueue.h:149 in 9c86a08b88 outdated
     144 | +    {
     145 | +        if (threads_num <= 0) return;
     146 | +        assert(m_worker_threads.empty());
     147 | +        m_stopped = false;
     148 | +        m_worker_threads.reserve(threads_num);
     149 | +        for (auto n = 0; n < threads_num; ++n) {
    


    MarcoFalke commented at 11:33 PM on April 23, 2020:
            for (int n = 0; n < threads_num; ++n) {
    

    is shorter and more precise


    hebasto commented at 11:36 AM on April 24, 2020:

    Agree.


    hebasto commented at 1:28 PM on April 24, 2020:
  26. in src/checkqueue.h:148 in 9c86a08b88 outdated
     143 | +    void StartWorkerThreads(const int threads_num)
     144 | +    {
     145 | +        if (threads_num <= 0) return;
     146 | +        assert(m_worker_threads.empty());
     147 | +        m_stopped = false;
     148 | +        m_worker_threads.reserve(threads_num);
    


    MarcoFalke commented at 11:34 PM on April 23, 2020:

    is this useful in any way?


    hebasto commented at 1:29 PM on April 24, 2020:
  27. in src/checkqueue.h:145 in 9c86a08b88 outdated
     138 | @@ -132,16 +139,31 @@ class CCheckQueue
     139 |      {
     140 |      }
     141 |  
     142 | +    //! Create a pool of new worker threads.
     143 | +    void StartWorkerThreads(const int threads_num)
     144 | +    {
     145 | +        if (threads_num <= 0) return;
    


    MarcoFalke commented at 11:35 PM on April 23, 2020:

    Is this needed? the for loop will never run anyway when this is true.


    hebasto commented at 11:40 AM on April 24, 2020:

    The idea was to prevent m_stopped = false;


    hebasto commented at 1:29 PM on April 24, 2020:
  28. in src/checkqueue.h:104 in 9c86a08b88 outdated
     100 | @@ -95,6 +101,7 @@ class CCheckQueue
     101 |                          return fRet;
     102 |                      }
     103 |                      nIdle++;
     104 | +                    if (m_stopped) return true; // TODO: This return value is unused.
    


    MarcoFalke commented at 11:37 PM on April 23, 2020:

    Also, shouldn't the if (m_stopped) be after the condition variable wait? Otherwise notifying it will first empty the queue. Finally, m_stopped could be renamed to m_request_stop and only briefly set in StopWorkerThreads to true and then immediately after to false. No other member functions (like StartWorkerThreads) touch it


    hebasto commented at 11:58 AM on April 24, 2020:

    Otherwise notifying it will first empty the queue.

    Correct. This is done intentionally as I think that worker threads should exit with a clean check queue, no?


    hebasto commented at 12:08 PM on April 24, 2020:

    Also, shouldn't the if (m_stopped) be after the condition variable wait?

    This wouldn't work for the master thread that could never return.


    hebasto commented at 12:20 PM on April 24, 2020:

    Finally, m_stopped could be renamed to m_request_stop and only briefly set in StopWorkerThreads to true and then immediately after to false.

    How this approach could work when StopWorkerThreads() is called during check queue being processed? I think m_stopped should keep its state in that case.


    hebasto commented at 1:29 PM on April 24, 2020:
  29. in src/test/checkqueue_tests.cpp:13 in 1c7fdb71b3 outdated
       8 | @@ -9,7 +9,7 @@
       9 |  #include <util/time.h>
      10 |  
      11 |  #include <boost/test/unit_test.hpp>
      12 | -#include <boost/thread.hpp>
      13 | +#include <boost/thread/thread.hpp>
    


    MarcoFalke commented at 11:47 PM on April 23, 2020:

    1c7fdb71b32bd91f6ae10313169d9eec63d46e3e: This commit should probably go last, because some of the changes are removed earlier anyway


    hebasto commented at 11:21 AM on April 24, 2020:

    In that case in the commit "bench: Use CCheckQueue local thread pool" the lint-includes.sh linter will produce:

    Good job! The Boost dependency "boost/thread/thread.hpp" is no longer used.
    Please remove it from EXPECTED_BOOST_INCLUDES in ./test/lint/lint-includes.sh
    to make sure this dependency is not accidentally reintroduced.
    

    which seems a bit falsely.


    MarcoFalke commented at 11:23 AM on April 24, 2020:

    I hope that no one is running the linters on every commit. They are meant to warn authors and reviewers as well as maintainers of code smell in a pull request as a whole. They are not meant as unit tests that absolutely must pass on every commit.


    hebasto commented at 1:29 PM on April 24, 2020:
  30. in src/test/checkqueue_tests.cpp:390 in d64dd5ffee outdated
     354 | -
     355 | -
     356 | -/** Test that CCheckQueueControl is threadsafe */
     357 | -BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
     358 | -{
     359 | -    auto queue = MakeUnique<Standard_Queue>(QUEUE_BATCH_SIZE);
    


    MarcoFalke commented at 11:48 PM on April 23, 2020:

    d64dd5ffee064b0b943b7e00b16b0ad28ac65474: Why remove this test?


    hebasto commented at 11:26 AM on April 24, 2020:

    ~I have no idea how to pass a customized callback into the CCheckQueue::StartWorkerThreads(int).~


    JeremyRubin commented at 8:02 PM on April 24, 2020:

    Usually you want to use a callable template parameter...

    template<typename Callable>
    function(int x, Callable&& function) {
        function(x);
    }
    function(1, [](int x) { return x});
    function(1, [](int x) { });
    

    hebasto commented at 3:06 AM on April 26, 2020:

    @JeremyRubin Thank you for your suggestion :)

    ~Sorry for my broken English, but I meant do we really need a unit test if the CCheckQueue class has no interface to test?~


    JeremyRubin commented at 5:38 PM on June 2, 2020:

    Sorry to just be responding on this:

    I think if there isn't an interface for something, but you can expose one to make testing more robust, it's worthwhile.

    E.g., the CheckQueue does not need to be templated as we know a concrete single type for it, but templating it allows us to mock out the job type and probe the internal execution, which is a good thing.

    What's the missing interface here? I don't see one being used in the code for this test.


    hebasto commented at 6:26 AM on June 6, 2020:

    @MarcoFalke @JeremyRubin I was confused about this test (I don't know the exact reason of that confusion now). The test has been restored.

  31. in src/checkqueue.h:39 in 629dae2482 outdated
      34 | -    boost::mutex mutex;
      35 | -
      36 | -    //! Worker threads block on this when out of work
      37 | -    boost::condition_variable condWorker;
      38 | -
      39 | -    //! Master thread blocks on this when out of work
    


    MarcoFalke commented at 11:50 PM on April 23, 2020:

    629dae24827121412fb24d31ac19a918ade1db3f: why remove the documentation?


    hebasto commented at 1:30 PM on April 24, 2020:
  32. MarcoFalke approved
  33. MarcoFalke commented at 11:56 PM on April 23, 2020: member

    Approach ACK f16f7f79dcd5d6c1b55966317b8762abeb5561c3 🌘

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    Approach ACK f16f7f79dcd5d6c1b55966317b8762abeb5561c3 🌘
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUhhpwv+NPSS8v5sdXJqBUVegg4/8o1tsvoNpU9cE80q4qYqkmrP2V55QWbkG2VI
    NE6+E0XSgTx8UuESI+9YEJ9+8gH4jCgNIqDMS4dqG+uPeeTXJUKn39Jn59YuaJGQ
    yWCCO4BZXqW/DWCLVpcDINXGtlZgFR3sv53RiFPWw+NNU5aJYTFssv9KJ8nBQVko
    SXNKSNzFxqx2oafuIaF+Ikrp+HbPzwE7Xrk2byS9Od1sA8d/LGkbhxBB4j32L4NT
    8NNUBKdata4zjzkQCXHIrBYNxJxy8/qK45lMO4WjiApxyA5kbbOZ20v9eyh8oF5I
    4hsvQN1Bpvdm8hK3oqxcLzZ2/QO6SjkNnVslNlFeYubasFMoTGS7n0SMqgmqgIbW
    qi9sMpsuMEBov6wq5kCIpWTBwHIuDMeRbjo/dOkJcTNqJHu8+s83aqD8P3MbTa0y
    ykeCbWwB8k0v5SPGhKMRx5sUMOGHQBWboDRzDJmNF909W+Yd3DL+C0qONk6vvMSy
    03UYQCgR
    =16Sm
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash fd6cc8b78bfb432d1fffbc1706dd13c7f3563a0d2caef6be9b45688ccd1b15ad -

    </details>

  34. MarcoFalke added this to the milestone 0.21.0 on Apr 24, 2020
  35. hebasto force-pushed on Apr 24, 2020
  36. hebasto commented at 1:25 PM on April 24, 2020: member

    Updated f16f7f79dcd5d6c1b55966317b8762abeb5561c3 -> 7a7e346a1d153fc7367bca5a1926881af65279ec (pr18710.04 -> pr18710.05, diff):

  37. MarcoFalke commented at 1:51 PM on April 24, 2020: member

    In the last commit: Could replace the last occurrence of thread.hpp with #include <boost/thread/shared_mutex.hpp> and kill boost thread from the linter?

  38. hebasto force-pushed on Apr 24, 2020
  39. hebasto commented at 2:36 PM on April 24, 2020: member

    Updated 7a7e346a1d153fc7367bca5a1926881af65279ec -> 61739174c67a773d124734ab6ec3385657fe3ef8 (pr18710.05 -> pr18710.06, diff):

    In the last commit: Could replace the last occurrence of thread.hpp with #include <boost/thread/shared_mutex.hpp> and kill boost thread from the linter?

  40. hebasto commented at 4:50 PM on April 24, 2020: member
  41. DrahtBot cross-referenced this on Apr 24, 2020 from issue Remove unused boost/thread by MarcoFalke
  42. hebasto force-pushed on Apr 24, 2020
  43. hebasto commented at 6:36 PM on April 24, 2020: member

    Updated 61739174c67a773d124734ab6ec3385657fe3ef8 -> b3ac0c3d15a729cdce5f15b918947037905b59dc (pr18710.06 -> pr18710.07, diff):

    It seems there is a thread issue on windows: https://travis-ci.org/github/bitcoin/bitcoin/jobs/679063276 and https://bitcoinbuilds.org/?job=90df9b0f-d918-45a1-b27d-0ae6d4cec303 ...

  44. hebasto marked this as a draft on Apr 25, 2020
  45. hebasto renamed this:
    Add local thread pool to CCheckQueue
    [WIP] Add local thread pool to CCheckQueue
    on Apr 25, 2020
  46. hebasto force-pushed on Apr 26, 2020
  47. hebasto marked this as ready for review on Apr 26, 2020
  48. hebasto commented at 3:00 AM on April 26, 2020: member

    Reworked dac216cee9e2e8fece089f67cf84f80f6890541f:

    • fixed data race conditions
    • dropped "refactor: Change return type of CCheckQueue::Loop()" commit
  49. hebasto renamed this:
    [WIP] Add local thread pool to CCheckQueue
    Add local thread pool to CCheckQueue
    on Apr 26, 2020
  50. promag commented at 10:32 PM on April 26, 2020: member

    Code review ACK dac216cee9e2e8fece089f67cf84f80f6890541f.

    Is f9c3bf45c13c147cb8d66d156519af021d66218e really a refactor due to changes between boost and std threads?

  51. hebasto commented at 10:38 PM on April 26, 2020: member

    Is f9c3bf4 really a refactor due to changes between boost and std threads?

    I think it is, as the code in the pre- f9c3bf45c13c147cb8d66d156519af021d66218e state does not rely on boost::thread-specific features, no?

  52. MarcoFalke cross-referenced this on Apr 27, 2020 from issue Stop using `boost::thread_group` by laanwj
  53. hebasto force-pushed on Apr 28, 2020
  54. hebasto commented at 6:03 PM on April 28, 2020: member

    Updated dac216cee9e2e8fece089f67cf84f80f6890541f -> 0b5e2a5528fae627e7be98ac231bfb9ae24cd504 (pr18710.08 -> pr18710.09, diff):

    • added missed GUARDED_BY thread-safety annotation
  55. DrahtBot cross-referenced this on May 2, 2020 from issue The Zero Allocations project by jb55
  56. DrahtBot cross-referenced this on May 6, 2020 from issue More thread safety annotation coverage by ajtowns
  57. DrahtBot cross-referenced this on May 14, 2020 from issue wallet: Refactor the classes in wallet/db.{cpp/h} by achow101
  58. hebasto force-pushed on May 26, 2020
  59. hebasto commented at 5:45 PM on May 26, 2020: member

    Rebased 0b5e2a5528fae627e7be98ac231bfb9ae24cd504 -> 82d5e650ee2b72d1447cbfc7bf1bb107dfd390b6 (pr18710.09 -> pr18710.10) on top of the #18881.

  60. DrahtBot cross-referenced this on May 27, 2020 from issue wallet: Add sqlite as an alternative wallet database and use it for new descriptor wallets by achow101
  61. DrahtBot cross-referenced this on May 27, 2020 from issue wallet: Remove boost from PeriodicFlush by MarcoFalke
  62. DrahtBot added the label Needs rebase on May 28, 2020
  63. hebasto force-pushed on May 28, 2020
  64. hebasto commented at 8:22 AM on May 28, 2020: member

    Rebased 82d5e650ee2b72d1447cbfc7bf1bb107dfd390b6 -> 46838e94da7c54389bce1fb7c0951ab338dcc304 (pr18710.10 -> pr18710.11) on top of the #16127.

  65. DrahtBot removed the label Needs rebase on May 28, 2020
  66. DrahtBot cross-referenced this on May 28, 2020 from issue Refactor: clean up PeriodicFlush() by jnewbery
  67. DrahtBot cross-referenced this on May 29, 2020 from issue wallet: Introduce and use DummyDatabase instead of dummy BerkeleyDatabase by achow101
  68. DrahtBot cross-referenced this on Jun 2, 2020 from issue wallettool: Add dump and createfromdump commands by achow101
  69. DrahtBot added the label Needs rebase on Jun 2, 2020
  70. hebasto force-pushed on Jun 4, 2020
  71. hebasto commented at 9:34 AM on June 4, 2020: member

    Rebased 46838e94da7c54389bce1fb7c0951ab338dcc304 -> 8457827f784e0e2586b19e78785d143b8eeb9513 (pr18710.11 -> pr18710.12) on top of the #18792.

  72. DrahtBot removed the label Needs rebase on Jun 4, 2020
  73. DrahtBot cross-referenced this on Jun 4, 2020 from issue validation: Make VerifyDB level 4 interruptible by MarcoFalke
  74. DrahtBot added the label Needs rebase on Jun 4, 2020
  75. hebasto force-pushed on Jun 4, 2020
  76. hebasto commented at 2:37 PM on June 4, 2020: member

    Rebased 8457827f784e0e2586b19e78785d143b8eeb9513 -> b392ef178725795d9e38a4dd000b20ee47c0d60a (pr18710.12 -> pr18710.13) due to the conflict with #19142.

  77. DrahtBot removed the label Needs rebase on Jun 4, 2020
  78. DrahtBot added the label Needs rebase on Jun 5, 2020
  79. hebasto force-pushed on Jun 5, 2020
  80. hebasto commented at 5:12 AM on June 5, 2020: member

    Rebased b392ef178725795d9e38a4dd000b20ee47c0d60a -> eee80a1c36d886583e387934abce6dac9b3117b5 (pr18710.13 -> pr18710.14) due to the conflict with #18758.

  81. fanquake removed the label Needs rebase on Jun 5, 2020
  82. JeremyRubin commented at 11:58 PM on June 5, 2020: contributor

    utack eee80a1

    Failure is a build pause, job needs restart. I'm still not sure why the test needed to be removed, maybe you can explain that more clearly.

  83. DrahtBot cross-referenced this on Jun 6, 2020 from issue [WIP DONOTMERGE] Replace boost with C++17 (std::shared_mutex) by MarcoFalke
  84. hebasto force-pushed on Jun 6, 2020
  85. hebasto commented at 6:24 AM on June 6, 2020: member

    Updated eee80a1c36d886583e387934abce6dac9b3117b5 -> ec4401480246f60c6b22d98d205a509a181010d7 (pr18710.14 -> pr18710.15, diff):

    • restored the test_CheckQueueControl_Locks unit test that was removed by mistake
  86. hebasto commented at 7:21 AM on June 6, 2020: member

    @JeremyRubin

    Failure is a build pause, job needs restart.

    No chance, unfortunately. See: #19171. The #18731 has been built on top of this PR successfully.

  87. JeremyRubin commented at 5:47 PM on June 6, 2020: contributor

    utACK ec44014

    Annoying note:

    As noted in #18710 (comment), Would be good if someone with access to some of the different platforms/arches we support can do benching/real network profiling to just to confirm there's no perf regression on the condition variable and mutex behavior. Otherwise seems ready to merge.

    see https://codesequoia.wordpress.com/2013/03/27/condition-variables-performance-of-boost-win32-and-the-c11-standard-library/ for some context, some std synchronization primitives are worse on some platforms and can have more variance.

    But to be clear, these potential regressions would probably be small compared to other improvements realizable in the checkqueue design, so I don't think it's a blocker for accepting these changes but we do want to know if merging this means we should be prioritizing some optimizations to neutralize any degradation.

  88. DrahtBot cross-referenced this on Jun 13, 2020 from issue Replace current benchmarking framework with nanobench by martinus
  89. DrahtBot cross-referenced this on Jun 16, 2020 from issue Replace boost::filesystem with std::filesystem by kiminuo
  90. hebasto cross-referenced this on Jun 20, 2020 from issue sync: detect double lock from the same thread by vasild
  91. hebasto closed this on Jun 23, 2020

  92. hebasto reopened this on Jun 23, 2020

  93. laanwj commented at 2:50 PM on July 1, 2020: member

    Concept ACK, will review

  94. laanwj added this to the "Blockers" column in a project

  95. DrahtBot cross-referenced this on Jul 20, 2020 from issue Remove mempool global by MarcoFalke
  96. DrahtBot cross-referenced this on Jul 26, 2020 from issue rpc: Avoid useless mempool query in gettxoutproof by MarcoFalke
  97. adamjonas commented at 1:29 PM on July 27, 2020: member

    To summarize the state of review for this PR:

    Concept ACK (laanwj), Approach ACK (MarcoFalke), Code review ACK (Promag), utACK (JeremyRubin) with no NACKs or blocking concerns raised. @JeremyRubin asked if someone "with access to some of the different platforms/arches we support can do benching/real network profiling to just to confirm there's no perf regression on the condition variable and mutex behavior."

    Benchmarks from the author (Linux Mint): master (a998c51)

    # Benchmark, evals, iterations, total, min, max, median
    CCheckQueueSpeedPrevectorJob, 100, 1400, 96.3747, 0.000677139, 0.000695471, 0.000688339
    

    this PR (b02bc25 - pre-rebase)

    # Benchmark, evals, iterations, total, min, max, median
    CCheckQueueSpeedPrevectorJob, 100, 1400, 77.4393, 0.000545271, 0.00057892, 0.000552496
    
  98. DrahtBot added the label Needs rebase on Jul 28, 2020
  99. hebasto force-pushed on Jul 29, 2020
  100. hebasto commented at 8:39 AM on July 29, 2020: member

    Rebased ec4401480246f60c6b22d98d205a509a181010d7 -> e7893d2e522477374ef9bf01997e9776c86b9813 (pr18710.15 -> pr18710.16) due to the conflicts with #18637 and #19589.

  101. hebasto commented at 9:01 AM on July 29, 2020: member

    Updated benchmarks (Linux Mint 20, x86_64):

    • master (2f71a1ea35667b3873197201531e7ae198ec5bf4)
    # Benchmark, evals, iterations, total, min, max, median
    CCheckQueueSpeedPrevectorJob, 5, 1400, 4.31038, 0.000612868, 0.000620909, 0.000614335
    
    • this PR (e7893d2e522477374ef9bf01997e9776c86b9813)
    # Benchmark, evals, iterations, total, min, max, median
    CCheckQueueSpeedPrevectorJob, 5, 1400, 3.67213, 0.000517622, 0.000531811, 0.000523883
    
  102. DrahtBot removed the label Needs rebase on Jul 29, 2020
  103. DrahtBot cross-referenced this on Jul 29, 2020 from issue Pass mempool pointer to UnloadBlockIndex/GetCoinsCacheSizeState by MarcoFalke
  104. DrahtBot cross-referenced this on Jul 30, 2020 from issue Disable fee estimation in blocksonly mode (by removing the fee estimates global) by darosior
  105. DrahtBot added the label Needs rebase on Jul 30, 2020
  106. hebasto force-pushed on Jul 31, 2020
  107. DrahtBot removed the label Needs rebase on Jul 31, 2020
  108. hebasto commented at 11:21 AM on July 31, 2020: member

    Rebased e7893d2e522477374ef9bf01997e9776c86b9813 -> a57a0e526c94b35b1b018fde5a8a2ea46fca8899 (pr18710.16 -> pr18710.17) due to the conflicts with #18011 and #19604.

    Updated benchmarks (Linux Mint 20, x86_64):

    • master (a63a26f042134fa80356860c109edb25ac567552)
    |              ns/job |               job/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |              189.96 |        5,264,153.75 |    4.1% |      0.01 | `CCheckQueueSpeedPrevectorJob`
    
    • this PR (a57a0e526c94b35b1b018fde5a8a2ea46fca8899)
    |              ns/job |               job/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |              157.27 |        6,358,598.51 |    1.9% |      0.01 | `CCheckQueueSpeedPrevectorJob
    
  109. in src/checkqueue.h:152 in e6eb62464c outdated
     150 | +            nTotal = 0;
     151 | +            fAllOk = true;
     152 | +        }
     153 | +        assert(m_worker_threads.empty());
     154 | +        for (int n = 0; n < threads_num; ++n) {
     155 | +            m_worker_threads.emplace_back([this, n]() {
    


    promag commented at 9:10 PM on July 31, 2020:

    e6eb62464cbfcc9f27a9e4d1e7377df30af77a86

    nit, drop ().


    hebasto commented at 9:53 AM on August 2, 2020:
  110. in src/checkqueue.h:64 in e6eb62464c outdated
      63 | @@ -62,8 +64,11 @@ class CCheckQueue
      64 |      //! The maximum number of elements to be processed in one batch
      65 |      const unsigned int nBatchSize;
      66 |  
      67 | +    std::vector<std::thread> m_worker_threads;
    


    promag commented at 9:15 PM on July 31, 2020:

    e6eb62464cbfcc9f27a9e4d1e7377df30af77a86

    These could be guarded by mutex too? At least m_request_stop already is.


    hebasto commented at 8:25 AM on August 2, 2020:

    Why? m_worker_threads is accessed from one thread only.

  111. in src/checkqueue.h:150 in e6eb62464c outdated
     148 | +            boost::unique_lock<boost::mutex> lock(mutex);
     149 | +            nIdle = 0;
     150 | +            nTotal = 0;
     151 | +            fAllOk = true;
     152 | +        }
     153 | +        assert(m_worker_threads.empty());
    


    promag commented at 9:16 PM on July 31, 2020:

    e6eb62464cbfcc9f27a9e4d1e7377df30af77a86

    nit, && ! m_request_stop


    hebasto commented at 9:54 AM on August 2, 2020:
  112. martinus commented at 11:11 AM on August 1, 2020: contributor

    Hi! I only have access to two different computers, an Intel i7-8700, and an Intel Celeron N3050. Compiled with g++ 10.1.0.

    i7-8700 (12 threads)

    master f7c73b03d975a72f609ded2bbe250c1c8a76a944, i7-8700:

    | ns/job | job/s | err% | ins/job | cyc/job | IPC | bra/job | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 582.25 | 1,717,469.22 | 0.5% | 267.01 | 347.19 | 0.769 | 50.65 | 3.7% | 0.02 | CCheckQueueSpeedPrevectorJob

    PR a57a0e526c94b35b1b018fde5a8a2ea46fca8899, i7-8700:

    | ns/job | job/s | err% | ins/job | cyc/job | IPC | bra/job | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 371.47 | 2,692,026.21 | 0.6% | 260.57 | 334.12 | 0.780 | 49.78 | 3.7% | 0.01 | CCheckQueueSpeedPrevectorJob

    PR is much faster here, quite an improvement here! Results are also relatively stable, at least stable enough to see that the PR is faster on average.

    Intel Celeron N3050 (2 threads)

    Here the runtime fluctuates so much that it doesn't make much sense to show the raw numbers. Especially the PR seems much more prone to fluctuations. To get a better understanding of the fluctuations, I've set epoch(100), and generated boxplots with

    std::ofstream html("pr.html");
    bench.render(ankerl::nanobench::templates::htmlBoxplot(), html);
    

    Then I get two html's for each run, which I've merged by hand:

    newplot(2)

    The PR seems to be slower here, but this might also be an artifact of the benchmark. I don't think this benchmark is very good.

  113. martinus commented at 4:36 PM on August 1, 2020: contributor

    I ran the benchmark again on the Intel Celeron N3050, but with BATCHES=5001 instead of 101. The benchmark takes a long time, and is a bit more stable. It still fluctuates by a factor of 4. On average the PR is slower than master on this machine.

    newplot(4)

  114. hebasto force-pushed on Aug 2, 2020
  115. hebasto commented at 9:53 AM on August 2, 2020: member

    Updated a57a0e526c94b35b1b018fde5a8a2ea46fca8899 -> e084c3b6051fc596d0b9a38ae7a5da58e3637a31 (pr18710.17 -> pr18710.18, diff):

    • addressed @promag's nits

    • added commit b8e267134431db97e853cddd32fdc41716d3414e "bench: Prevent thread oversubscription"

    Benchmarks on my machine (Linux Mint 20, x86_64):

    • master (a63a26f042134fa80356860c109edb25ac567552)
    |              ns/job |               job/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |              191.58 |        5,219,878.03 |    2.1% |      0.01 | `CCheckQueueSpeedPrevectorJob`
    
    • master + b8e267134431db97e853cddd32fdc41716d3414e (without thread oversubscription)
    |              ns/job |               job/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |              182.46 |        5,480,666.18 |    2.0% |      0.01 | `CCheckQueueSpeedPrevectorJob`
    
    • this PR (e084c3b6051fc596d0b9a38ae7a5da58e3637a31)
    |              ns/job |               job/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |              150.84 |        6,629,325.36 |    1.1% |      0.01 | `CCheckQueueSpeedPrevectorJob`
    
  116. hebasto commented at 9:58 AM on August 2, 2020: member

    @martinus

    There are some concerns about thread oversubscription impact on benchmarking.

    Mind repeating your benchmarks on 2-thread system with updated branch?

  117. martinus commented at 10:36 AM on August 2, 2020: contributor

    Sure, I ran it again. i7-8700 is faster too. I also tested it with queue.StartWorkerThreads(1);, which is by far the fastest for that benchmark. It seems that the work units are far too small to be able to reasonably distribute the work. So I am not sure if this benchmark is much useful.

    | ns/job | job/s | err% | ins/job | cyc/job | IPC | bra/job | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 582.25 | 1,717,469.22 | 0.5% | 267.01 | 347.19 | 0.769 | 50.65 | 3.7% | 0.02 | master f7c73b03d975a72f609ded2bbe250c1c8a76a944 | 371.47 | 2,692,026.21 | 0.6% | 260.57 | 334.12 | 0.780 | 49.78 | 3.7% | 0.01 | PR a57a0e526c94b35b1b018fde5a8a2ea46fca8899 | 351.57 | 2,844,406.84 | 1.7% | 261.09 | 332.71 | 0.785 | 49.90 | 3.6% | 0.11 | PR e084c3b6051fc596d0b9a38ae7a5da58e3637a31 | 131.95 | 7,578,398.22 | 1.1% | 262.19 | 252.28 | 1.039 | 50.15 | 3.8% | 0.04 | queue.StartWorkerThreads(1);

    Updated graph with BATCHES = 5001 on the Celeron N3050:

    newplot(5)

  118. hebasto commented at 10:48 AM on August 2, 2020: member

    @martinus Great! Thanks very much!

    Mind including benchmark for b8e267134431db97e853cddd32fdc41716d3414e on the Celeron N3050 as well, as this commit changes the benchmark itself?

  119. martinus commented at 11:11 AM on August 2, 2020: contributor

    If I understand it correcly, the benchmark queues PrevectorJob as as the job to simulate. But the jobs itself do nothing, they simply return true:

    bool operator()()  {
        return true;
    }
    

    I'd say the job should do some reasonable amount of work so using multiple threads actually make any sense.

    Anyways, here is an update with b8e2671 included:

    i7-8700:

    | ns/job | job/s | err% | ins/job | cyc/job | IPC | bra/job | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 582.25 | 1,717,469.22 | 0.5% | 267.01 | 347.19 | 0.769 | 50.65 | 3.7% | 0.02 | master f7c73b03d975a72f609ded2bbe250c1c8a76a944 | 371.47 | 2,692,026.21 | 0.6% | 260.57 | 334.12 | 0.780 | 49.78 | 3.7% | 0.01 | PR a57a0e526c94b35b1b018fde5a8a2ea46fca8899 | 351.57 | 2,844,406.84 | 1.7% | 261.09 | 332.71 | 0.785 | 49.90 | 3.6% | 0.11 | PR e084c3b6051fc596d0b9a38ae7a5da58e3637a31 | 131.95 | 7,578,398.22 | 1.1% | 262.19 | 252.28 | 1.039 | 50.15 | 3.8% | 0.04 | queue.StartWorkerThreads(1); | 548.98 | 1,821,565.90 | 2.9% | 267.48 | 334.32 | 0.800 | 50.76 | 3.6% | 0.02 | b8e267134

    Celeron N3050:

    newplot(7)

    They behave very similar, e084c3b6051fc596d0b9a38ae7a5da58e3637a31 is a bit faster than b8e267134.

  120. hebasto commented at 11:29 AM on August 2, 2020: member

    This PR consist of two distinct changes now:

    • master -> b8e267134431db97e853cddd32fdc41716d3414e
      • prevented thread oversubscription during benchmarking
      • benchmark change only
      • benchmarking results variance becomes lower
    • b8e267134431db97e853cddd32fdc41716d3414e -> e084c3b6051fc596d0b9a38ae7a5da58e3637a31
      • dropped boost::thread_group
      • benchmarking results mean improved on all tested platforms (including 2-threaded Celeron N3050)

    What did I miss?

  121. hebasto cross-referenced this on Aug 13, 2020 from issue bench: Prevent thread oversubscription and decreases the variance of result values by hebasto
  122. hebasto commented at 2:30 PM on August 13, 2020: member

    To make reviewing easier, the first commit is split out to #19710.

  123. laanwj removed this from the "Blockers" column in a project

  124. hebasto force-pushed on Aug 21, 2020
  125. hebasto commented at 6:33 AM on August 21, 2020: member

    Rebased e084c3b6051fc596d0b9a38ae7a5da58e3637a31 -> fa815a305108bc8b25ac468abaec7fa60c261f41 (pr18710.18 -> pr18710.19) on top of #19710 to prevent a merge conflict.

  126. MarcoFalke referenced this in commit afffbb1bc6 on Aug 31, 2020
  127. DrahtBot added the label Needs rebase on Aug 31, 2020
  128. hebasto force-pushed on Aug 31, 2020
  129. hebasto commented at 9:00 AM on August 31, 2020: member

    Rebased fa815a305108bc8b25ac468abaec7fa60c261f41 -> 89c4f7591e02df4fd36071995740113c1c06db3d (pr18710.19 -> pr18710.20) due to the conflict with #19710.

  130. DrahtBot removed the label Needs rebase on Aug 31, 2020
  131. sidhujag referenced this in commit bfafd05ac3 on Aug 31, 2020
  132. laanwj added this to the "Blockers" column in a project

  133. DrahtBot cross-referenced this on Sep 19, 2020 from issue validation: Reduce direct g_chainman usage by dongcarl
  134. DrahtBot cross-referenced this on Sep 19, 2020 from issue refactor: Remove unused CTxMemPool::clear() helper by MarcoFalke
  135. DrahtBot added the label Needs rebase on Sep 23, 2020
  136. refactor: Use member initializers in CCheckQueue 0ef938685b
  137. Add local thread pool to CCheckQueue 01511776ac
  138. test: Use CCheckQueue local thread pool dba30695fc
  139. bench: Use CCheckQueue local thread pool 6784ac471b
  140. refactor: Drop boost::thread stuff in CCheckQueue bb6fcc75d1
  141. hebasto force-pushed on Sep 24, 2020
  142. hebasto commented at 4:04 AM on September 24, 2020: member

    Rebased 89c4f7591e02df4fd36071995740113c1c06db3d -> bb6fcc75d1ec94b733d1477c816351c50be5faf9 (pr18710.20 -> pr18710.21) due to the conflict with #19927.

  143. DrahtBot removed the label Needs rebase on Sep 24, 2020
  144. DrahtBot cross-referenced this on Sep 28, 2020 from issue validation: Remove useless call to mempool->clear() by MarcoFalke
  145. laanwj removed this from the milestone 0.21.0 on Oct 8, 2020
  146. laanwj added this to the milestone 0.22.0 on Oct 8, 2020
  147. DrahtBot cross-referenced this on Oct 15, 2020 from issue tree-wide: De-globalize ChainstateManager by dongcarl
  148. DrahtBot cross-referenced this on Nov 25, 2020 from issue Add syscall sandboxing using seccomp-bpf (Linux secure computing mode) by practicalswift
  149. DrahtBot cross-referenced this on Dec 5, 2020 from issue tests: Create or use existing properly initialized NodeContexts by dongcarl
  150. jamesob commented at 5:12 AM on December 11, 2020: member

    Concept ACK, will plan to review.

  151. LarryRuane commented at 12:54 AM on December 16, 2020: contributor

    nit: remove the #include <boost/thread/thread.hpp> from checkqueue_tests.cpp.

    Looks good. I ran the affected tests (and single-stepped through most of the new test code), and verified using debugger that a mainnet node correctly reaches the real script checking code. ACK bb6fcc75d1ec94b733d1477c816351c50be5faf9

  152. hebasto commented at 1:21 AM on December 16, 2020: member

    @LarryRuane

    nit: remove the #include <boost/thread/thread.hpp> from checkqueue_tests.cpp.

    boost::thread_group is still used in the test_CheckQueueControl_Locks.

  153. LarryRuane commented at 2:08 AM on December 16, 2020: contributor

    boost::thread_group is still used in the test_CheckQueueControl_Locks

    It builds for me without that include. Oh, I see, it's included indirectly via test/util/setup_common.h, thanks.

  154. laanwj commented at 5:51 PM on January 7, 2021: member

    Thanks for getting rid of the one-to-last use of boost::thread_group.

    Code review ACK bb6fcc75d1ec94b733d1477c816351c50be5faf9

  155. jonatack commented at 8:53 AM on January 11, 2021: contributor

    Code review ACK bb6fcc75d1ec94b733d1477c816351c50be5faf9 and verified rebase to master builds cleanly with unit/functional tests green

  156. jonatack cross-referenced this on Jan 11, 2021 from issue Lock-Free CheckQueue by JeremyRubin
  157. laanwj merged this on Jan 25, 2021
  158. laanwj closed this on Jan 25, 2021

  159. laanwj removed this from the "Blockers" column in a project

  160. sidhujag referenced this in commit af159bf7a7 on Jan 25, 2021
  161. hebasto deleted the branch on Jan 25, 2021
  162. fanquake referenced this in commit f827e151a2 on Jan 26, 2021
  163. fanquake cross-referenced this on Jan 26, 2021 from issue refactor: remove straggling boost::mutex usage by fanquake
  164. MarcoFalke referenced this in commit 280d0bd0bd on Jan 26, 2021
  165. remyers referenced this in commit 3edbc4f0ad on Jan 26, 2021
  166. fanquake cross-referenced this on Jan 27, 2021 from issue refactor: remove boost::thread_group usage by fanquake
  167. laanwj referenced this in commit d0d256536c on Feb 1, 2021
  168. fanquake moved this from the "In progress" to the "Done" column in a project

  169. kwvg referenced this in commit 15b2b65089 on Jun 4, 2021
  170. kwvg referenced this in commit b0f9dfafe1 on Jun 5, 2021
  171. kwvg cross-referenced this on Jun 5, 2021 from issue partial #15842, merge #15849, #17342, #18710: Add local thread pool to CCheckQueue by kwvg
  172. kwvg referenced this in commit 0261427826 on Jun 6, 2021
  173. kwvg referenced this in commit 70109da016 on Jun 6, 2021
  174. kwvg referenced this in commit 25227a72f6 on Jun 7, 2021
  175. kwvg referenced this in commit a1271b1b36 on Jun 8, 2021
  176. kwvg referenced this in commit 0bdeee66bd on Jun 8, 2021
  177. kwvg referenced this in commit 2759ad03ab on Jun 9, 2021
  178. kwvg referenced this in commit 347135080a on Jun 10, 2021
  179. kwvg referenced this in commit 7a72b35ac0 on Jun 11, 2021
  180. kwvg referenced this in commit d27e5467d3 on Jun 16, 2021
  181. kwvg referenced this in commit 972af32631 on Jun 16, 2021
  182. kwvg referenced this in commit 076356fa3b on Jun 16, 2021
  183. kwvg referenced this in commit 78e9bd547f on Jun 24, 2021
  184. kwvg referenced this in commit c9d0d92b2d on Jun 25, 2021
  185. UdjinM6 referenced this in commit c5cc285d0e on Jun 26, 2021
  186. ftrader referenced this in commit 0e94c77f6e on Aug 13, 2021
  187. Bushstar cross-referenced this on Sep 8, 2021 from issue Boost usage reduction by Bushstar
  188. Bushstar cross-referenced this on Sep 10, 2021 from issue C++17 and reduce Boost usage by Bushstar
  189. Fabcien referenced this in commit 83a6f76099 on Feb 4, 2022
  190. Fabcien referenced this in commit 8b2338aa87 on Feb 4, 2022
  191. Fabcien referenced this in commit 21d559eb1d on Feb 4, 2022
  192. Fabcien referenced this in commit e376425680 on Feb 4, 2022
  193. Fabcien referenced this in commit 5d1d773738 on Feb 4, 2022
  194. shaavan cross-referenced this on Mar 17, 2022 from issue Suggestion for questions based on architecture of the Bitcoin core by shaavan
  195. gades referenced this in commit 7cd576f4c1 on May 1, 2022
  196. bitcoin locked this on Aug 16, 2022

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