Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove thread hop to producer thread for trx signature recovery #1859

Merged
merged 6 commits into from
Nov 7, 2023

Conversation

heifner
Copy link
Member

@heifner heifner commented Nov 2, 2023

Remove the use of a std::future and wait in producer thread pool. Now after signature recovery is complete the chain thread posts directly to the main application thread. This improves the eosio token transfer per second (TPS) tests from ~31K TPS to ~36K TPS.

Transaction now transitions from net-thread => chain-thread => main-thread.

Removing the thread hop to chain-thread and performing key recovery on the net thread is possible (net-thread => main-thread), but testing shows it easily overwhelms the main-thread. Instead I think we need to create a memory pool of trxs that the main thread can pull from instead of pushing low priority tasks for trx execution to the main thread. That would greatly reduce the contention on the app post call and on the main thread priority queue. See #1860

This builds off the improvement of #1846.

Removes --producer-threads option as there is now no use for the producer thread pool.

Issue #1690

@heifner heifner requested review from greg7mdp and linh2931 November 2, 2023 19:57
@heifner heifner added the OCI Work exclusive to OCI team label Nov 2, 2023
Comment on lines 819 to 868
[this, trx{trx}, &chain, time_limit{max_trx_cpu_usage}, trx_type,
api_trx, is_transient, next{std::move(next)}, return_failure_traces]() mutable {

transaction_metadata_ptr trx_meta;
try {
trx_meta = transaction_metadata::recover_keys( trx, chain.get_chain_id(), time_limit, trx_type, chain.configured_subjective_signature_length_limit() );
} catch(...) {
// use read_write when read is likely fine; this maintains previous behavior of next() always being called from the main thread
app().executor().post(priority::low, exec_queue::read_write,
[ex_ptr = std::current_exception(), this, trx{std::move(trx)}, is_transient, next{std::move(next)}]() {
auto start = fc::time_point::now();
auto idle_time = this->_time_tracker.add_idle_time(start);
auto trx_tracker = this->_time_tracker.start_trx(is_transient, start);
fc_tlog(_log, "Time since last trx: ${t}us", ("t", idle_time));
auto ex_handler =
[this, is_transient, &next, &trx](fc::exception_ptr ex) {
this->log_trx_results(trx, nullptr, ex, 0, is_transient);
next(std::move(ex));
};
try {
std::rethrow_exception(ex_ptr);
} CATCH_AND_CALL(ex_handler)
});
return;
}

app().executor().post(priority::low, exec_queue::read_write,
[this, trx_meta{std::move(trx_meta)}, api_trx, is_transient, next{std::move(next)}, return_failure_traces]() mutable {
auto start = fc::time_point::now();
auto idle_time = this->_time_tracker.add_idle_time(start);
auto trx_tracker = this->_time_tracker.start_trx(is_transient, start);
fc_tlog(_log, "Time since last trx: ${t}us", ("t", idle_time));

auto exception_handler =
[this, is_transient, &next, &trx_meta](fc::exception_ptr ex) {
this->log_trx_results(trx_meta->packed_trx(), nullptr, ex, 0, is_transient);
next(std::move(ex));
};
try {
if (!this->process_incoming_transaction_async(trx_meta, api_trx, return_failure_traces, trx_tracker, next)) {
if (this->in_producing_mode()) {
this->schedule_maybe_produce_block(true);
} else {
this->restart_speculative_block();
}
}
}
CATCH_AND_CALL(exception_handler);
});
} );
Copy link
Contributor

@greg7mdp greg7mdp Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to remove all occurences of this-> in this code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

});
}
});
boost::asio::post( chain.get_thread_pool(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section of code is deep nested and becomes complicated. Can more comments be added and/or it be refactored a bit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned it up some.

@heifner heifner merged commit 1612650 into main Nov 7, 2023
29 checks passed
@heifner heifner deleted the GH-1690-performance branch November 7, 2023 13:03
@heifner heifner linked an issue Nov 7, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCI Work exclusive to OCI team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance: Validate Expected Throughput
3 participants