Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Update txn_test_gen_plugin to overlap transaction submit @taokayan
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Dec 14, 2018
1 parent f64da40 commit 22ab63c
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,38 @@ using namespace eosio::chain;
api_handle->call_name(vs.at(0).as<in_param0>(), vs.at(1).as<in_param1>(), result_handler);

struct txn_test_gen_plugin_impl {
static void push_next_transaction(const std::shared_ptr<std::vector<signed_transaction>>& trxs, size_t index, const std::function<void(const fc::exception_ptr&)>& next ) {

uint64_t _total_us = 0;
uint64_t _txcount = 0;

int _remain = 0;

void push_next_transaction(const std::shared_ptr<std::vector<signed_transaction>>& trxs, size_t index, const std::function<void(const fc::exception_ptr&)>& next ) {
chain_plugin& cp = app().get_plugin<chain_plugin>();
cp.accept_transaction( packed_transaction(trxs->at(index)), [=](const fc::static_variant<fc::exception_ptr, transaction_trace_ptr>& result){
if (result.contains<fc::exception_ptr>()) {
next(result.get<fc::exception_ptr>());
} else {
if (index + 1 < trxs->size()) {
push_next_transaction(trxs, index + 1, next);

const int overlap = 20;
int end = std::min(index + overlap, trxs->size());
_remain = end - index;
for (int i = index; i < end; ++i) {
cp.accept_transaction( packed_transaction(trxs->at(i)), [=](const fc::static_variant<fc::exception_ptr, transaction_trace_ptr>& result){
if (result.contains<fc::exception_ptr>()) {
next(result.get<fc::exception_ptr>());
} else {
next(nullptr);
if (result.contains<transaction_trace_ptr>() && result.get<transaction_trace_ptr>()->receipt) {
_total_us += result.get<transaction_trace_ptr>()->receipt->cpu_usage_us;
++_txcount;
}
--_remain;
if (_remain == 0 ) {
if (end < trxs->size()) {
push_next_transaction(trxs, index + overlap, next);
} else {
next(nullptr);
}
}
}
}
});
});
}
}

void push_transactions( std::vector<signed_transaction>&& trxs, const std::function<void(fc::exception_ptr)>& next ) {
Expand Down Expand Up @@ -295,13 +314,11 @@ struct txn_test_gen_plugin_impl {
try {
controller& cc = app().get_plugin<chain_plugin>().chain();
auto chainid = app().get_plugin<chain_plugin>().get_chain_id();
auto abi_serializer_max_time = app().get_plugin<chain_plugin>().get_abi_serializer_max_time();

fc::crypto::private_key a_priv_key = fc::crypto::private_key::regenerate(fc::sha256(std::string(64, 'a')));
fc::crypto::private_key b_priv_key = fc::crypto::private_key::regenerate(fc::sha256(std::string(64, 'b')));
static fc::crypto::private_key a_priv_key = fc::crypto::private_key::regenerate(fc::sha256(std::string(64, 'a')));
static fc::crypto::private_key b_priv_key = fc::crypto::private_key::regenerate(fc::sha256(std::string(64, 'b')));

static uint64_t nonce = static_cast<uint64_t>(fc::time_point::now().sec_since_epoch()) << 32;
abi_serializer eosio_serializer(cc.db().find<account_object, by_name>(config::system_account_name)->get_abi(), abi_serializer_max_time);

uint32_t reference_block_num = cc.last_irreversible_block_num();
if (txn_reference_block_lag >= 0) {
Expand Down Expand Up @@ -351,6 +368,11 @@ struct txn_test_gen_plugin_impl {
timer.cancel();
running = false;
ilog("Stopping transaction generation test");

if (_txcount) {
ilog("${d} transactions executed, ${t}us / transaction", ("d", _txcount)("t", _total_us / (double)_txcount));
_txcount = _total_us = 0;
}
}

boost::asio::high_resolution_timer timer{app().get_io_service()};
Expand Down

0 comments on commit 22ab63c

Please sign in to comment.