add load-wallet benchmark

This commit is contained in:
Ariel Gabizon
2017-09-18 21:54:53 +02:00
parent d1bba6f1b6
commit 2e8aefdce1
4 changed files with 56 additions and 2 deletions

View File

@@ -56,7 +56,7 @@ function use_200k_benchmark {
function zcashd_start { function zcashd_start {
case "$1" in case "$1" in
sendtoaddress) sendtoaddress|loadwallet)
case "$2" in case "$2" in
200k-recv) 200k-recv)
use_200k_benchmark 0 use_200k_benchmark 0
@@ -86,7 +86,7 @@ function zcashd_stop {
function zcashd_massif_start { function zcashd_massif_start {
case "$1" in case "$1" in
sendtoaddress) sendtoaddress|loadwallet)
case "$2" in case "$2" in
200k-recv) 200k-recv)
use_200k_benchmark 0 use_200k_benchmark 0
@@ -203,6 +203,9 @@ case "$1" in
sendtoaddress) sendtoaddress)
zcash_rpc zcbenchmark sendtoaddress 10 "${@:4}" zcash_rpc zcbenchmark sendtoaddress 10 "${@:4}"
;; ;;
loadwallet)
zcash_rpc zcbenchmark loadwallet 10
;;
*) *)
zcashd_stop zcashd_stop
echo "Bad arguments." echo "Bad arguments."

View File

@@ -2602,6 +2602,11 @@ UniValue zc_benchmark(const UniValue& params, bool fHelp)
} }
auto amount = AmountFromValue(params[2]); auto amount = AmountFromValue(params[2]);
sample_times.push_back(benchmark_sendtoaddress(amount)); sample_times.push_back(benchmark_sendtoaddress(amount));
} else if (benchmarktype == "loadwallet") {
if (Params().NetworkIDString() != "regtest") {
throw JSONRPCError(RPC_TYPE_ERROR, "Benchmark must be run in regtest mode");
}
sample_times.push_back(benchmark_loadwallet());
} else { } else {
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid benchmarktype"); throw JSONRPCError(RPC_TYPE_ERROR, "Invalid benchmarktype");
} }

View File

@@ -31,6 +31,39 @@
#include "zcash/IncrementalMerkleTree.hpp" #include "zcash/IncrementalMerkleTree.hpp"
using namespace libzcash; using namespace libzcash;
// This method is based on Shutdown from init.cpp
void pre_wallet_load()
{
LogPrintf("%s: In progress...\n", __func__);
if (ShutdownRequested())
throw new std::runtime_error("The node is shutting down");
if (pwalletMain)
pwalletMain->Flush(false);
#ifdef ENABLE_MINING
GenerateBitcoins(false, NULL, 0);
#endif
UnregisterNodeSignals(GetNodeSignals());
if (pwalletMain)
pwalletMain->Flush(true);
UnregisterValidationInterface(pwalletMain);
delete pwalletMain;
pwalletMain = NULL;
bitdb.Reset();
RegisterNodeSignals(GetNodeSignals());
LogPrintf("%s: done\n", __func__);
}
void post_wallet_load(){
RegisterValidationInterface(pwalletMain);
#ifdef ENABLE_MINING
// Generate coins in the background
if (pwalletMain || !GetArg("-mineraddress", "").empty())
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1));
#endif
}
void timer_start(timeval &tv_start) void timer_start(timeval &tv_start)
{ {
@@ -420,3 +453,15 @@ double benchmark_sendtoaddress(CAmount amount)
return timer_stop(tv_start); return timer_stop(tv_start);
} }
double benchmark_loadwallet()
{
pre_wallet_load();
struct timeval tv_start;
bool fFirstRunRet=true;
timer_start(tv_start);
pwalletMain = new CWallet("wallet.dat");
DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRunRet);
auto res = timer_stop(tv_start);
post_wallet_load();
return res;
}

View File

@@ -17,5 +17,6 @@ extern double benchmark_try_decrypt_notes(size_t nAddrs);
extern double benchmark_increment_note_witnesses(size_t nTxs); extern double benchmark_increment_note_witnesses(size_t nTxs);
extern double benchmark_connectblock_slow(); extern double benchmark_connectblock_slow();
extern double benchmark_sendtoaddress(CAmount amount); extern double benchmark_sendtoaddress(CAmount amount);
extern double benchmark_loadwallet();
#endif #endif