mempool for front page is in its own async call now.

This commit is contained in:
moneroexamples 2017-05-25 14:00:16 +08:00
parent e9143c523c
commit 91739483ad
3 changed files with 30 additions and 15 deletions

View file

@ -55,8 +55,8 @@ namespace xmreg
"you can specify mainnet url, if you run it on testnet. link will show on front page to mainnet explorer") "you can specify mainnet url, if you run it on testnet. link will show on front page to mainnet explorer")
("no-blocks-on-index", value<string>()->default_value("10"), ("no-blocks-on-index", value<string>()->default_value("10"),
"number of last blocks to be shown on index page") "number of last blocks to be shown on index page")
("network-info-timeout", value<string>()->default_value("5000"), ("network-info-timeout", value<string>()->default_value("3000"),
"maximum time, in milliseconds, to wait for network and mempool data availability") "maximum time, in milliseconds, to wait for mempool data availability")
("bc-path,b", value<string>(), ("bc-path,b", value<string>(),
"path to lmdb folder of the blockchain, e.g., ~/.bitmonero/lmdb") "path to lmdb folder of the blockchain, e.g., ~/.bitmonero/lmdb")
("ssl-crt-file", value<string>(), ("ssl-crt-file", value<string>(),

View file

@ -427,12 +427,17 @@ namespace xmreg
j_info["fee_per_kb"] = fee_estimated; j_info["fee_per_kb"] = fee_estimated;
// get memory pool rendered template
j_info["mempool_html"] = mempool(false, no_of_mempool_tx_of_frontpage);
return j_info; return j_info;
}); });
// get mempool for the front page also using async future
std::future<string> mempool_ftr = std::async(std::launch::async, [&]
{
// get memory pool rendered template
return mempool(false, no_of_mempool_tx_of_frontpage);
});
//get current server timestamp //get current server timestamp
server_timestamp = std::time(nullptr); server_timestamp = std::time(nullptr);
@ -744,13 +749,11 @@ namespace xmreg
context["cache_misses"] = cache_misses; context["cache_misses"] = cache_misses;
// now time to check if we have our networkinfo from network_info future // now time to check if we have our networkinfo from network_info future
// wait a bit (network_info_timeout millisecond max) if not, just in case, but we dont wait more. // wait a bit (300 millisecond max) if not, just in case, but we dont wait more.
// if its not ready by now, forget about it. // if its not ready by now, forget about it.
string mempool_html {"Cant get mempool_pool"};
std::future_status ftr_status = network_info_ftr.wait_for( std::future_status ftr_status = network_info_ftr.wait_for(
std::chrono::milliseconds(network_info_timeout)); std::chrono::milliseconds(300));
if (ftr_status == std::future_status::ready) if (ftr_status == std::future_status::ready)
{ {
@ -775,15 +778,27 @@ namespace xmreg
{"fee_per_kb" , print_money(j_network_info["fee_per_kb"])}, {"fee_per_kb" , print_money(j_network_info["fee_per_kb"])},
{"alt_blocks_no" , j_network_info["alt_blocks_count"].get<uint64_t>()} {"alt_blocks_no" , j_network_info["alt_blocks_count"].get<uint64_t>()}
}; };
mempool_html = j_network_info["mempool_html"];
} }
} }
else else
{ {
mempool_html = template_file["mempool_error"]; cerr << "network_info future not ready yet, skipping." << endl;
}
cerr << "network_info and mempool future not ready yet, skipping." << endl; string mempool_html {"Cant get mempool_pool"};
// get mempool data for the front page, if ready. If not, then just skip.
std::future_status mempool_ftr_status = mempool_ftr.wait_for(
std::chrono::milliseconds(network_info_timeout));
if (mempool_ftr_status == std::future_status::ready)
{
mempool_html = mempool_ftr.get();
}
else
{
cerr << "mempool future not ready yet, skipping." << endl;
mempool_html = template_file["mempool_error"];
} }
if (CurrentBlockchainStatus::is_thread_running()) if (CurrentBlockchainStatus::is_thread_running())

View file

@ -4,7 +4,7 @@
<h4 style="font-size: 14px; margin-top: 0px"></h4> <h4 style="font-size: 14px; margin-top: 0px"></h4>
<div class="center info" style="text-align: center;width:80%;color:#949490"> <div class="center info" style="text-align: center;width:80%;color:#949490">
<p>Newtork info and mempool data preparation for the front page failed. <p>Mempool data preparation for the front page failed.
Its processing took longer than expected and it timed out. Its processing took longer than expected and it timed out.
To view mempool without time constrain, To view mempool without time constrain,
go to dedicated mempool page: <a href="/mempool">memory pool</a> go to dedicated mempool page: <a href="/mempool">memory pool</a>