Skip to content

Add local thread pool to CCheckQueue#18710

Merged
laanwj merged 5 commits intobitcoin:masterfrom
hebasto:200419-thread-pool
Jan 25, 2021
Merged

Add local thread pool to CCheckQueue#18710
laanwj merged 5 commits intobitcoin:masterfrom
hebasto:200419-thread-pool

Conversation

@hebasto
Copy link
Member

@hebasto hebasto commented Apr 20, 2020

This PR:

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

Related: #17307

@maflcko
Copy link
Member

maflcko commented Apr 20, 2020

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

@maflcko
Copy link
Member

maflcko commented Apr 20, 2020

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

cc @JeremyRubin

@hebasto
Copy link
Member Author

hebasto commented Apr 20, 2020

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 20, 2020

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

Conflicts

No conflicts as of last run.

@hebasto
Copy link
Member Author

hebasto commented Apr 20, 2020

Updated 9764d81 -> f4cd37e (pr18710.01 -> pr18710.02, diff):

  • fixed linter issue with boost headers

@JeremyRubin
Copy link
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.

@hebasto
Copy link
Member Author

hebasto commented Apr 21, 2020

@MarcoFalke

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

The differences from #14464 are:

  • absence of Interrupt() function
  • an additional atomic m_destruction_in_progress that replaces the boost "interrupt" feature:

    bitcoin/src/checkqueue.h

    Lines 96 to 97 in f4cd37e

    if (m_destruction_in_progress) return;
    cond.wait(lock); // wait
    and

    bitcoin/src/checkqueue.h

    Lines 172 to 173 in f4cd37e

    m_destruction_in_progress = true;
    m_worker_cv.notify_all();

@hebasto hebasto force-pushed the 200419-thread-pool branch from f4cd37e to b02bc25 Compare April 21, 2020 21:08
@hebasto
Copy link
Member Author

hebasto commented Apr 21, 2020

Updated f4cd37e -> b02bc25 (pr18710.02 -> pr18710.03, diff):

@hebasto
Copy link
Member Author

hebasto commented Apr 21, 2020

Benchmark results on my machine:

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

@hebasto
Copy link
Member Author

hebasto commented Apr 22, 2020

Rebased b02bc25 -> f16f7f7 (pr18710.03 -> pr18710.04) due to the conflict with #18575.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK f16f7f7 🌘

Show signature and timestamp

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 -

@maflcko maflcko added this to the 0.21.0 milestone Apr 24, 2020
@hebasto hebasto force-pushed the 200419-thread-pool branch from f16f7f7 to 7a7e346 Compare April 24, 2020 13:21
@hebasto
Copy link
Member Author

hebasto commented Apr 24, 2020

Updated f16f7f7 -> 7a7e346 (pr18710.04 -> pr18710.05, diff):

@maflcko
Copy link
Member

maflcko commented Apr 24, 2020

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?

@hebasto hebasto force-pushed the 200419-thread-pool branch from 7a7e346 to 6173917 Compare April 24, 2020 14:34
@hebasto
Copy link
Member Author

hebasto commented Apr 24, 2020

Updated 7a7e346 -> 6173917 (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?

@hebasto
Copy link
Member Author

hebasto commented Apr 24, 2020

@jamesob
Copy link
Contributor

jamesob commented Dec 11, 2020

Concept ACK, will plan to review.

Copy link
Contributor

@LarryRuane LarryRuane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bb6fcc7

@hebasto
Copy link
Member Author

hebasto commented Dec 16, 2020

@LarryRuane

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

boost::thread_group is still used in the test_CheckQueueControl_Locks.

@LarryRuane
Copy link
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.

@laanwj
Copy link
Member

laanwj commented Jan 7, 2021

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

Code review ACK bb6fcc7

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jonatack jonatack mentioned this pull request Jan 11, 2021
@laanwj laanwj merged commit b386d37 into bitcoin:master Jan 25, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 25, 2021
bb6fcc7 refactor: Drop boost::thread stuff in CCheckQueue (Hennadii Stepanov)
6784ac4 bench: Use CCheckQueue local thread pool (Hennadii Stepanov)
dba3069 test: Use CCheckQueue local thread pool (Hennadii Stepanov)
0151177 Add local thread pool to CCheckQueue (Hennadii Stepanov)
0ef9386 refactor: Use member initializers in CCheckQueue (Hennadii Stepanov)

Pull request description:

  This PR:
  - gets rid of `boost::thread_group` in the `CCheckQueue` class
  - allows thread safety annotation usage in the `CCheckQueue` class
  - is alternative to bitcoin#14464 (bitcoin#18710 (comment), bitcoin#18710 (comment))

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

  Related: bitcoin#17307

ACKs for top commit:
  laanwj:
    Code review ACK bb6fcc7
  LarryRuane:
    ACK bb6fcc7
  jonatack:
    Code review ACK bb6fcc7 and verified rebase to master builds cleanly with unit/functional tests green

Tree-SHA512: fddeb720d5a391b48bb4c6fa58ed34ccc3f57862fdb8e641745c021841c8340e35c5126338271446cbd98f40bd5484f27926aa6c3e76fa478ba1efafe72e73c1
@hebasto hebasto deleted the 200419-thread-pool branch January 25, 2021 21:31
fanquake added a commit to fanquake/bitcoin that referenced this pull request Jan 26, 2021
After the merge of bitcoin#18710, the linter is warning:
```bash
A new Boost dependency in the form of "boost/thread/mutex.hpp" appears to have been introduced:
src/sync.cpp:#include <boost/thread/mutex.hpp>
src/test/sync_tests.cpp:#include <boost/thread/mutex.hpp>

^---- failure generated from test/lint/lint-includes.sh
```

the interim bitcoin#19337 was merged, which introduced more `boost::mutex` usage.

Given we no longer use `boost::mutex`, just remove the double lock test
and remaining includes.
maflcko pushed a commit that referenced this pull request Jan 26, 2021
f827e15 refactor: remove straggling boost::mutex usage (fanquake)

Pull request description:

  After the merge of #18710, the linter is warning:
  ```bash
  A new Boost dependency in the form of "boost/thread/mutex.hpp" appears to have been introduced:
  src/sync.cpp:#include <boost/thread/mutex.hpp>
  src/test/sync_tests.cpp:#include <boost/thread/mutex.hpp>

  ^---- failure generated from test/lint/lint-includes.sh
  ```

  #18710 removed `boost/thread/mutex.hpp` from lint-includes, however in the interim #19337 was merged, which introduced more `boost::mutex` usage.

  Given we no longer use `boost::mutex`, just remove the double lock test and remaining includes.

ACKs for top commit:
  laanwj:
    Code review ACK f827e15
  hebasto:
    ACK f827e15

Tree-SHA512: f738b12189fe5b39db3e8f8231e9002714413a962eaf98adc84a6614fa474df5616358cfb1c89b92a2b0564efa9b704a774c49d4a25dca18a0ccc3cd9eabfc0a
laanwj added a commit that referenced this pull request Feb 1, 2021
dc8be12 refactor: remove boost::thread_group usage (fanquake)

Pull request description:

  Post #18710, there isn't much left using `boost::thread_group`, so should just be able to replace it with the standard library. This also removes the last use of `boost::thread_interrupted`.

  After this change, last piece of Boost Thread we'd be using is `boost::shared_mutex`. See the commentary [here](#16684 (comment)) as to why it may be non-trivial to swap that for `std::shared_mutex` in the near future.

  Closes #17307

ACKs for top commit:
  laanwj:
    Code review re-ACK dc8be12
  MarcoFalke:
    review ACK dc8be12 🔁
  jonatack:
    Non-expert code review ACK dc8be12, also checked range-diff since last review and that local debug build is clean with gcc 10.2.1-6 on Debian

Tree-SHA512: 5510e2d760cce824234207dc86b1551ca8f21cbf3a2ce753c0254a0d03ffd83c94e449aec202fb7bd76e6fc64df783a6b70a736b0add9ece3734bb9c8ce8fc2f
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.