From 6adf03cdc516a9236aac6dbd6f289750761b8d24 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 14 Jun 2022 21:23:23 +0200 Subject: [PATCH] Second thread pool for IO --- src/common/dns_utils.cpp | 2 +- src/common/threadpool.h | 6 +++++- src/cryptonote_core/blockchain.cpp | 4 ++-- src/cryptonote_core/cryptonote_core.cpp | 2 +- src/ringct/rctSigs.cpp | 6 +++--- src/wallet/wallet2.cpp | 6 +++--- src/wallet/wallet_rpc_payments.cpp | 2 +- tests/core_tests/chaingen.h | 2 +- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 6ab6ff4fe..7bb1781d4 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -521,7 +521,7 @@ bool load_txt_records_from_dns(std::vector &good_records, const std // send all requests in parallel std::deque avail(dns_urls.size(), false), valid(dns_urls.size(), false); - tools::threadpool& tpool = tools::threadpool::getInstance(); + tools::threadpool& tpool = tools::threadpool::getInstanceForIO(); tools::threadpool::waiter waiter(tpool); for (size_t n = 0; n < dns_urls.size(); ++n) { diff --git a/src/common/threadpool.h b/src/common/threadpool.h index ce1bc5799..53421e18b 100644 --- a/src/common/threadpool.h +++ b/src/common/threadpool.h @@ -42,10 +42,14 @@ namespace tools class threadpool { public: - static threadpool& getInstance() { + static threadpool& getInstanceForCompute() { static threadpool instance; return instance; } + static threadpool& getInstanceForIO() { + static threadpool instance(8); + return instance; + } static threadpool *getNewForUnitTests(unsigned max_threads = 0) { return new threadpool(max_threads); } diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index b4abde1ad..eee27987f 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3434,7 +3434,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc, std::vector < uint64_t > results; results.resize(tx.vin.size(), 0); - tools::threadpool& tpool = tools::threadpool::getInstance(); + tools::threadpool& tpool = tools::threadpool::getInstanceForCompute(); tools::threadpool::waiter waiter(tpool); int threads = tpool.get_max_concurrency(); @@ -5137,7 +5137,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector::const_iterator it = tx_blobs.begin(); for (size_t i = 0; i < tx_blobs.size(); i++, ++it) { diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp index 21040317c..477a7907d 100644 --- a/src/ringct/rctSigs.cpp +++ b/src/ringct/rctSigs.cpp @@ -1333,7 +1333,7 @@ namespace rct { try { if (semantics) { - tools::threadpool& tpool = tools::threadpool::getInstance(); + tools::threadpool& tpool = tools::threadpool::getInstanceForCompute(); tools::threadpool::waiter waiter(tpool); std::deque results(rv.outPk.size(), false); DP("range proofs verified?"); @@ -1383,7 +1383,7 @@ namespace rct { { PERF_TIMER(verRctSemanticsSimple); - tools::threadpool& tpool = tools::threadpool::getInstance(); + tools::threadpool& tpool = tools::threadpool::getInstanceForCompute(); tools::threadpool::waiter waiter(tpool); std::deque results; std::vector bp_proofs; @@ -1536,7 +1536,7 @@ namespace rct { const size_t threads = std::max(rv.outPk.size(), rv.mixRing.size()); std::deque results(threads); - tools::threadpool& tpool = tools::threadpool::getInstance(); + tools::threadpool& tpool = tools::threadpool::getInstanceForCompute(); tools::threadpool::waiter waiter(tpool); const keyV &pseudoOuts = bulletproof || bulletproof_plus ? rv.p.pseudoOuts : rv.pseudoOuts; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 588ddd572..931d6d900 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2724,7 +2724,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector short_chain_history; - tools::threadpool& tpool = tools::threadpool::getInstance(); + tools::threadpool& tpool = tools::threadpool::getInstanceForCompute(); tools::threadpool::waiter waiter(tpool); uint64_t blocks_start_height; std::vector blocks; diff --git a/src/wallet/wallet_rpc_payments.cpp b/src/wallet/wallet_rpc_payments.cpp index 61eaa8070..8474fb568 100644 --- a/src/wallet/wallet_rpc_payments.cpp +++ b/src/wallet/wallet_rpc_payments.cpp @@ -144,7 +144,7 @@ bool wallet2::search_for_rpc_payment(uint64_t credits_target, uint32_t n_threads n_threads = boost::thread::hardware_concurrency(); std::vector hash(n_threads); - tools::threadpool& tpool = tools::threadpool::getInstance(); + tools::threadpool& tpool = tools::threadpool::getInstanceForCompute(); tools::threadpool::waiter waiter(tpool); const uint32_t local_nonce = nonce += n_threads; // wrapping's OK diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 5c8c9f79f..d5c9edc55 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -778,7 +778,7 @@ inline bool do_replay_events_get_core(std::vector& events, cry t_test_class validator; bool ret = replay_events_through_core(c, events, validator); - tools::threadpool::getInstance().recycle(); + tools::threadpool::getInstanceForCompute().recycle(); // c.deinit(); return ret; }