-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread pool for checking verifications #1614
Conversation
b4ac0e3
to
59bdcab
Compare
Could |
I actually didn't know there was a thread pool in boost, always heard that they wouldn't add one. Guess they did! Although it looks pretty basic, there's no support for futures so I'd have to roll my own way of getting results from the async operations in the thread pool (the true/false from all those async I'll see if I can get away with a smaller code footprint by using it. |
I will take a look at it today @termoose as it is something of high priority and is needed asap, thanks! |
Thanks, seems like it works as well as the custom thread pool. I changed the cut-off to 10k based on the feedback from @guilhermelawless. I was considering adding this to |
Getting the same results with the new thread pool as well. Also a good thing is that results don't change much with higher batch sizes, so that's one less thing to parametrize. Not sure I agree with the cut-off change. Setting to 512 (2x batch_size) already gets me a 1.7x speedup, so why not enjoy that? |
Have you checked on live whether it goes into your |
@wezrule @termoose TEST (sanity, thread_pool)
{
boost::asio::thread_pool thread_pool (4);
std::vector<bool> v(4, false);
for (int i=0; i<=1; ++i)
boost::asio::post (thread_pool, [i, &v] { v[i] = true; });
thread_pool.join ();
for (int i=2; i<=3; ++i)
boost::asio::post (thread_pool, [i, &v] { v[i] = true; });
thread_pool.join ();
ASSERT_EQ (4, v.size ());
ASSERT_EQ (true, v[0]);
ASSERT_EQ (true, v[1]);
ASSERT_EQ (true, v[2]);
ASSERT_EQ (true, v[3]);
} This test fails:
It seems to me that once a thread_pool has been joined, it cannot be reused. But to solve we only need to instance it inside verify_threaded, not class wide. |
See guilhermelawless#1 for a more realistic case with the following adds (repeated until 100k): It gets me a 2x speedup in total. Also fixed the thread_pool re-use, and the number of batches sometimes being 1 extra due to overflow = 0. Cut-off lowered to 512. @termoose feel free to take code from there and modify this PR, i won't be PRing myself. |
Good catch on not being able to reuse the thread pool! I assumed it would be reused as long as
Won't there be an overhead of initialising the thread pool every time? I could try to implement something with a @wezrule I agree it would be cool to accumulate verifications in |
Made it so that the thread pool does not have to be instantiated inside |
About 3% improvement over instantiating every time 👍 Ran test 50 times and no failures. |
Hi @termoose @guilhermelawless thanks for your contributions so far! Now I have a few comments:
When more messages of a greater size are used it greatly favours the higher cores, however we want tests to run fairly quickly irrespective of the number of cores so this test is not meant to be representative of a benchmark, it just checks functionality is working correctly for a wide range of sizes.
Can you guys have a look here and give any comments: https://github.com/wezrule/raiblocks/tree/multithread_signature_checker @termoose feel free to modify your PR with any of these changes, otherwise I will mine as a PR some point tomorrow. |
Indentation and syntax fix
then we're wait for the corresponding futures to fold the result
770760a
to
1838bfa
Compare
There are a number of changes here though that I find confusing but I don't have time to figure out all the details until you merge it in tomorrow.
Waiting for each signature check to finish before |
std::vector was mentioned in an earlier version, I've changed how it works quite a bit which is why you may be finding it confusing. I got rid of the queue (there's no The std::vector was for thread safety yes, there is no overhead in converting char -> bool. I don't know about benchmarks between this and using a vector of promises, but I no longer use this anymore now, and just assert the result after each thread. Good point about the I am going to run TSAN on these changes on the live network for a while to see if it picks up anything. Ok we appreciate all the time and effort you have put into this and look forward to any future contributions. I will create a PR after some more testing. Thanks again. |
It looks good, All I would add is a |
@guilhermelawless done. I will close this off and we can use: #1651 |
Added a
thread_pool
class for submitting work into one of thehardware_concurrency
number of threads (default value). Class is somewhat general and can be used for other threading use-cases.Added a test case for doing 100k verifications multi-threaded.
Batching
256
verifications in one thread, hard cut-off of1000
for running the single threaded version.