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: member

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

    Conflicts

    No conflicts as of last run.

  9. hebasto force-pushed on Apr 20, 2020
  10. 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
  11. 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.

  12. 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:

  13. hebasto force-pushed on Apr 21, 2020
  14. 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)
  15. hebasto commented at 10:28 pm on April 21, 2020: member

    Benchmark results on my machine:

    • master (a998c5185bc7fc2c7e22312fac60175cb2869bdd)
    0# Benchmark, evals, iterations, total, min, max, median
    1CCheckQueueSpeedPrevectorJob, 100, 1400, 96.3747, 0.000677139, 0.000695471, 0.000688339
    
    • this PR (b02bc2583e421dbca35a5652c650ae861230f480)
    0# Benchmark, evals, iterations, total, min, max, median
    1CCheckQueueSpeedPrevectorJob, 100, 1400, 77.4393, 0.000545271, 0.00057892, 0.000552496
    
  16. DrahtBot added the label Needs rebase on Apr 22, 2020
  17. hebasto force-pushed on Apr 22, 2020
  18. 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.
  19. DrahtBot removed the label Needs rebase on Apr 23, 2020
  20. 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:
    0        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:
  21. 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:
  22. 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:
  23. 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:
  24. 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:

    0Good job! The Boost dependency "boost/thread/thread.hpp" is no longer used.
    1Please remove it from EXPECTED_BOOST_INCLUDES in ./test/lint/lint-includes.sh
    2to 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:
  25. 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…

    0template<typename Callable>
    1function(int x, Callable&& function) {
    2    function(x);
    3}
    4function(1, [](int x) { return x});
    5function(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.
  26. 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:
  27. MarcoFalke approved
  28. MarcoFalke commented at 11:56 pm on April 23, 2020: member

    Approach ACK f16f7f79dcd5d6c1b55966317b8762abeb5561c3 🌘

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3Approach ACK f16f7f79dcd5d6c1b55966317b8762abeb5561c3 🌘
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUhhpwv+NPSS8v5sdXJqBUVegg4/8o1tsvoNpU9cE80q4qYqkmrP2V55QWbkG2VI
     8NE6+E0XSgTx8UuESI+9YEJ9+8gH4jCgNIqDMS4dqG+uPeeTXJUKn39Jn59YuaJGQ
     9yWCCO4BZXqW/DWCLVpcDINXGtlZgFR3sv53RiFPWw+NNU5aJYTFssv9KJ8nBQVko
    10SXNKSNzFxqx2oafuIaF+Ikrp+HbPzwE7Xrk2byS9Od1sA8d/LGkbhxBB4j32L4NT
    118NNUBKdata4zjzkQCXHIrBYNxJxy8/qK45lMO4WjiApxyA5kbbOZ20v9eyh8oF5I
    124hsvQN1Bpvdm8hK3oqxcLzZ2/QO6SjkNnVslNlFeYubasFMoTGS7n0SMqgmqgIbW
    13qi9sMpsuMEBov6wq5kCIpWTBwHIuDMeRbjo/dOkJcTNqJHu8+s83aqD8P3MbTa0y
    14ykeCbWwB8k0v5SPGhKMRx5sUMOGHQBWboDRzDJmNF909W+Yd3DL+C0qONk6vvMSy
    1503UYQCgR
    16=16Sm
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash fd6cc8b78bfb432d1fffbc1706dd13c7f3563a0d2caef6be9b45688ccd1b15ad -

  29. MarcoFalke added this to the milestone 0.21.0 on Apr 24, 2020
  30. hebasto force-pushed on Apr 24, 2020
  31. hebasto commented at 1:25 pm on April 24, 2020: member

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

  32. 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?
  33. hebasto force-pushed on Apr 24, 2020
  34. 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?

  35. hebasto commented at 4:50 pm on April 24, 2020: member
  36. hebasto force-pushed on Apr 24, 2020
  37. 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

  38. hebasto marked this as a draft on Apr 25, 2020
  39. hebasto renamed this:
    Add local thread pool to CCheckQueue
    [WIP] Add local thread pool to CCheckQueue
    on Apr 25, 2020
  40. hebasto force-pushed on Apr 26, 2020
  41. hebasto marked this as ready for review on Apr 26, 2020
  42. 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
  43. hebasto renamed this:
    [WIP] Add local thread pool to CCheckQueue
    Add local thread pool to CCheckQueue
    on Apr 26, 2020
  44. 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?

  45. 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?

  46. hebasto force-pushed on Apr 28, 2020
  47. 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
  48. hebasto force-pushed on May 26, 2020
  49. hebasto commented at 5:45 pm on May 26, 2020: member
    Rebased 0b5e2a5528fae627e7be98ac231bfb9ae24cd504 -> 82d5e650ee2b72d1447cbfc7bf1bb107dfd390b6 (pr18710.09 -> pr18710.10) on top of the #18881.
  50. DrahtBot added the label Needs rebase on May 28, 2020
  51. hebasto force-pushed on May 28, 2020
  52. hebasto commented at 8:22 am on May 28, 2020: member
    Rebased 82d5e650ee2b72d1447cbfc7bf1bb107dfd390b6 -> 46838e94da7c54389bce1fb7c0951ab338dcc304 (pr18710.10 -> pr18710.11) on top of the #16127.
  53. DrahtBot removed the label Needs rebase on May 28, 2020
  54. DrahtBot added the label Needs rebase on Jun 2, 2020
  55. hebasto force-pushed on Jun 4, 2020
  56. hebasto commented at 9:34 am on June 4, 2020: member
    Rebased 46838e94da7c54389bce1fb7c0951ab338dcc304 -> 8457827f784e0e2586b19e78785d143b8eeb9513 (pr18710.11 -> pr18710.12) on top of the #18792.
  57. DrahtBot removed the label Needs rebase on Jun 4, 2020
  58. DrahtBot added the label Needs rebase on Jun 4, 2020
  59. hebasto force-pushed on Jun 4, 2020
  60. hebasto commented at 2:37 pm on June 4, 2020: member
    Rebased 8457827f784e0e2586b19e78785d143b8eeb9513 -> b392ef178725795d9e38a4dd000b20ee47c0d60a (pr18710.12 -> pr18710.13) due to the conflict with #19142.
  61. DrahtBot removed the label Needs rebase on Jun 4, 2020
  62. DrahtBot added the label Needs rebase on Jun 5, 2020
  63. hebasto force-pushed on Jun 5, 2020
  64. hebasto commented at 5:12 am on June 5, 2020: member
    Rebased b392ef178725795d9e38a4dd000b20ee47c0d60a -> eee80a1c36d886583e387934abce6dac9b3117b5 (pr18710.13 -> pr18710.14) due to the conflict with #18758.
  65. fanquake removed the label Needs rebase on Jun 5, 2020
  66. 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.

  67. hebasto force-pushed on Jun 6, 2020
  68. 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
  69. 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.

  70. 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.

  71. hebasto closed this on Jun 23, 2020

  72. hebasto reopened this on Jun 23, 2020

  73. laanwj commented at 2:50 pm on July 1, 2020: member
    Concept ACK, will review
  74. laanwj added this to the "Blockers" column in a project

  75. 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)

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

    this PR (b02bc25 - pre-rebase)

    0# Benchmark, evals, iterations, total, min, max, median
    1CCheckQueueSpeedPrevectorJob, 100, 1400, 77.4393, 0.000545271, 0.00057892, 0.000552496
    
  76. DrahtBot added the label Needs rebase on Jul 28, 2020
  77. hebasto force-pushed on Jul 29, 2020
  78. 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.
  79. hebasto commented at 9:01 am on July 29, 2020: member

    Updated benchmarks (Linux Mint 20, x86_64):

    • master (2f71a1ea35667b3873197201531e7ae198ec5bf4)
    0# Benchmark, evals, iterations, total, min, max, median
    1CCheckQueueSpeedPrevectorJob, 5, 1400, 4.31038, 0.000612868, 0.000620909, 0.000614335
    
    • this PR (e7893d2e522477374ef9bf01997e9776c86b9813)
    0# Benchmark, evals, iterations, total, min, max, median
    1CCheckQueueSpeedPrevectorJob, 5, 1400, 3.67213, 0.000517622, 0.000531811, 0.000523883
    
  80. DrahtBot removed the label Needs rebase on Jul 29, 2020
  81. DrahtBot added the label Needs rebase on Jul 30, 2020
  82. hebasto force-pushed on Jul 31, 2020
  83. DrahtBot removed the label Needs rebase on Jul 31, 2020
  84. 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)
    0|              ns/job |               job/s |    err% |     total | benchmark
    1|--------------------:|--------------------:|--------:|----------:|:----------
    2|              189.96 |        5,264,153.75 |    4.1% |      0.01 | `CCheckQueueSpeedPrevectorJob`
    
    • this PR (a57a0e526c94b35b1b018fde5a8a2ea46fca8899)
    0|              ns/job |               job/s |    err% |     total | benchmark
    1|--------------------:|--------------------:|--------:|----------:|:----------
    2|              157.27 |        6,358,598.51 |    1.9% |      0.01 | `CCheckQueueSpeedPrevectorJob
    
  85. 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:
  86. 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.
  87. 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:
  88. 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

    0std::ofstream html("pr.html");
    1bench.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.

  89. 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)

  90. hebasto force-pushed on Aug 2, 2020
  91. 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)
    0|              ns/job |               job/s |    err% |     total | benchmark
    1|--------------------:|--------------------:|--------:|----------:|:----------
    2|              191.58 |        5,219,878.03 |    2.1% |      0.01 | `CCheckQueueSpeedPrevectorJob`
    
    • master + b8e267134431db97e853cddd32fdc41716d3414e (without thread oversubscription)
    0|              ns/job |               job/s |    err% |     total | benchmark
    1|--------------------:|--------------------:|--------:|----------:|:----------
    2|              182.46 |        5,480,666.18 |    2.0% |      0.01 | `CCheckQueueSpeedPrevectorJob`
    
    • this PR (e084c3b6051fc596d0b9a38ae7a5da58e3637a31)
    0|              ns/job |               job/s |    err% |     total | benchmark
    1|--------------------:|--------------------:|--------:|----------:|:----------
    2|              150.84 |        6,629,325.36 |    1.1% |      0.01 | `CCheckQueueSpeedPrevectorJob`
    
  92. 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?

  93. 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)

  94. 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?

  95. 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:

    0bool operator()()  {
    1    return true;
    2}
    

    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.

  96. 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?

  97. hebasto commented at 2:30 pm on August 13, 2020: member
    To make reviewing easier, the first commit is split out to #19710.
  98. laanwj removed this from the "Blockers" column in a project

  99. hebasto force-pushed on Aug 21, 2020
  100. 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.
  101. MarcoFalke referenced this in commit afffbb1bc6 on Aug 31, 2020
  102. DrahtBot added the label Needs rebase on Aug 31, 2020
  103. hebasto force-pushed on Aug 31, 2020
  104. hebasto commented at 9:00 am on August 31, 2020: member
    Rebased fa815a305108bc8b25ac468abaec7fa60c261f41 -> 89c4f7591e02df4fd36071995740113c1c06db3d (pr18710.19 -> pr18710.20) due to the conflict with #19710.
  105. DrahtBot removed the label Needs rebase on Aug 31, 2020
  106. sidhujag referenced this in commit bfafd05ac3 on Aug 31, 2020
  107. laanwj added this to the "Blockers" column in a project

  108. DrahtBot added the label Needs rebase on Sep 23, 2020
  109. refactor: Use member initializers in CCheckQueue 0ef938685b
  110. Add local thread pool to CCheckQueue 01511776ac
  111. test: Use CCheckQueue local thread pool dba30695fc
  112. bench: Use CCheckQueue local thread pool 6784ac471b
  113. refactor: Drop boost::thread stuff in CCheckQueue bb6fcc75d1
  114. hebasto force-pushed on Sep 24, 2020
  115. hebasto commented at 4:04 am on September 24, 2020: member
    Rebased 89c4f7591e02df4fd36071995740113c1c06db3d -> bb6fcc75d1ec94b733d1477c816351c50be5faf9 (pr18710.20 -> pr18710.21) due to the conflict with #19927.
  116. DrahtBot removed the label Needs rebase on Sep 24, 2020
  117. laanwj removed this from the milestone 0.21.0 on Oct 8, 2020
  118. laanwj added this to the milestone 0.22.0 on Oct 8, 2020
  119. jamesob commented at 5:12 am on December 11, 2020: member
    Concept ACK, will plan to review.
  120. LarryRuane commented at 0: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

  121. 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.

  122. 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.

  123. 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

  124. jonatack commented at 8:53 am on January 11, 2021: member
    Code review ACK bb6fcc75d1ec94b733d1477c816351c50be5faf9 and verified rebase to master builds cleanly with unit/functional tests green
  125. laanwj merged this on Jan 25, 2021
  126. laanwj closed this on Jan 25, 2021

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

  128. sidhujag referenced this in commit af159bf7a7 on Jan 25, 2021
  129. hebasto deleted the branch on Jan 25, 2021
  130. fanquake referenced this in commit f827e151a2 on Jan 26, 2021
  131. MarcoFalke referenced this in commit 280d0bd0bd on Jan 26, 2021
  132. remyers referenced this in commit 3edbc4f0ad on Jan 26, 2021
  133. laanwj referenced this in commit d0d256536c on Feb 1, 2021
  134. fanquake moved this from the "In progress" to the "Done" column in a project

  135. kittywhiskers referenced this in commit 15b2b65089 on Jun 4, 2021
  136. kittywhiskers referenced this in commit b0f9dfafe1 on Jun 5, 2021
  137. kittywhiskers referenced this in commit 0261427826 on Jun 6, 2021
  138. kittywhiskers referenced this in commit 70109da016 on Jun 6, 2021
  139. kittywhiskers referenced this in commit 25227a72f6 on Jun 7, 2021
  140. kittywhiskers referenced this in commit a1271b1b36 on Jun 8, 2021
  141. kittywhiskers referenced this in commit 0bdeee66bd on Jun 8, 2021
  142. kittywhiskers referenced this in commit 2759ad03ab on Jun 9, 2021
  143. kittywhiskers referenced this in commit 347135080a on Jun 10, 2021
  144. kittywhiskers referenced this in commit 7a72b35ac0 on Jun 11, 2021
  145. kittywhiskers referenced this in commit d27e5467d3 on Jun 16, 2021
  146. kittywhiskers referenced this in commit 972af32631 on Jun 16, 2021
  147. kittywhiskers referenced this in commit 076356fa3b on Jun 16, 2021
  148. kittywhiskers referenced this in commit 78e9bd547f on Jun 24, 2021
  149. kittywhiskers referenced this in commit c9d0d92b2d on Jun 25, 2021
  150. UdjinM6 referenced this in commit c5cc285d0e on Jun 26, 2021
  151. ftrader referenced this in commit 0e94c77f6e on Aug 13, 2021
  152. Fabcien referenced this in commit 83a6f76099 on Feb 4, 2022
  153. Fabcien referenced this in commit 8b2338aa87 on Feb 4, 2022
  154. Fabcien referenced this in commit 21d559eb1d on Feb 4, 2022
  155. Fabcien referenced this in commit e376425680 on Feb 4, 2022
  156. Fabcien referenced this in commit 5d1d773738 on Feb 4, 2022
  157. gades referenced this in commit 7cd576f4c1 on May 1, 2022
  158. DrahtBot 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: 2024-12-18 18:12 UTC

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