From cbb5e640ef6646abf8244570c9a6f803fe9f1891 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 18 May 2015 00:26:09 +0200 Subject: [PATCH 1/2] more blockchain import optimizations --- libethcore/EthashAux.cpp | 4 ++-- libethcore/EthashAux.h | 2 +- libethereum/BlockChain.cpp | 2 +- libethereum/BlockQueue.cpp | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index 9bb2c4aa9..e01372452 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -101,13 +101,13 @@ uint64_t EthashAux::number(h256 const& _seedHash) void EthashAux::killCache(h256 const& _s) { - RecursiveGuard l(x_lights); + WriteGuard l(x_lights); m_lights.erase(_s); } EthashAux::LightType EthashAux::light(h256 const& _seedHash) { - RecursiveGuard l(get()->x_lights); + ReadGuard l(get()->x_lights); LightType ret = get()->m_lights[_seedHash]; return ret ? ret : (get()->m_lights[_seedHash] = make_shared(_seedHash)); } diff --git a/libethcore/EthashAux.h b/libethcore/EthashAux.h index 92ca52097..3f876f442 100644 --- a/libethcore/EthashAux.h +++ b/libethcore/EthashAux.h @@ -88,7 +88,7 @@ private: static EthashAux* s_this; - RecursiveMutex x_lights; + SharedMutex x_lights; std::unordered_map> m_lights; Mutex x_fulls; diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index cbde3f14e..7838e432d 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -317,7 +317,7 @@ tuple BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st { try { - auto r = import(block.first, block.second, _stateDB); + auto r = import(block.first, block.second, _stateDB, ImportRequirements::Default & ~ImportRequirements::ValidNonce); fresh += r.first; dead += r.second; } diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index 43a3d1caf..8fa7b6cca 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -38,7 +38,8 @@ const char* BlockQueueChannel::name() { return EthOrange "▣┅▶"; } BlockQueue::BlockQueue() { - for (unsigned i = 0; i < thread::hardware_concurrency(); ++i) + unsigned verifierThreads = std::max(thread::hardware_concurrency(), 3U) - 2U; + for (unsigned i = 0; i < verifierThreads; ++i) m_verifiers.emplace_back([=](){ setThreadName("verifier" + toString(i)); this->verifierBody(); From 8f9f7d9a6f96aef61bd7fdaf2ec027be906f97f1 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 18 May 2015 11:34:11 +0200 Subject: [PATCH 2/2] comments --- libethereum/BlockChain.cpp | 1 + libethereum/BlockQueue.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 7838e432d..f4a1dcec2 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -317,6 +317,7 @@ tuple BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st { try { + // Nonce is already verified thread at this point. auto r = import(block.first, block.second, _stateDB, ImportRequirements::Default & ~ImportRequirements::ValidNonce); fresh += r.first; dead += r.second; diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index 8fa7b6cca..df134b246 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -38,6 +38,7 @@ const char* BlockQueueChannel::name() { return EthOrange "▣┅▶"; } BlockQueue::BlockQueue() { + // Allow some room for other activity unsigned verifierThreads = std::max(thread::hardware_concurrency(), 3U) - 2U; for (unsigned i = 0; i < verifierThreads; ++i) m_verifiers.emplace_back([=](){