Skip to content

Commit

Permalink
add load-wallet benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
arielgabizon committed Sep 18, 2017
1 parent d1bba6f commit 2e8aefd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
7 changes: 5 additions & 2 deletions qa/zcash/performance-measurements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function use_200k_benchmark {

function zcashd_start {
case "$1" in
sendtoaddress)
sendtoaddress|loadwallet)
case "$2" in
200k-recv)
use_200k_benchmark 0
Expand Down Expand Up @@ -86,7 +86,7 @@ function zcashd_stop {

function zcashd_massif_start {
case "$1" in
sendtoaddress)
sendtoaddress|loadwallet)
case "$2" in
200k-recv)
use_200k_benchmark 0
Expand Down Expand Up @@ -203,6 +203,9 @@ case "$1" in
sendtoaddress)
zcash_rpc zcbenchmark sendtoaddress 10 "${@:4}"
;;
loadwallet)
zcash_rpc zcbenchmark loadwallet 10
;;
*)
zcashd_stop
echo "Bad arguments."
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,11 @@ UniValue zc_benchmark(const UniValue& params, bool fHelp)
}
auto amount = AmountFromValue(params[2]);
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 {
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid benchmarktype");
}
Expand Down
45 changes: 45 additions & 0 deletions src/zcbenchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@
#include "zcash/IncrementalMerkleTree.hpp"

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)
{
Expand Down Expand Up @@ -420,3 +453,15 @@ double benchmark_sendtoaddress(CAmount amount)
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;
}
1 change: 1 addition & 0 deletions src/zcbenchmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_connectblock_slow();
extern double benchmark_sendtoaddress(CAmount amount);
extern double benchmark_loadwallet();

#endif

0 comments on commit 2e8aefd

Please sign in to comment.