Clean up and add comment

This commit is contained in:
Ryo Onodera 2021-01-17 14:38:19 +09:00 committed by Michael Vines
parent 5cf9094bb9
commit 8d4ab1bab1
1 changed files with 11 additions and 5 deletions

View File

@ -358,10 +358,16 @@ impl JsonRpcService {
let ledger_path = ledger_path.to_path_buf();
let runtime01 = {
use tokio_01::runtime::{Builder as RuntimeBuilder, Runtime, TaskExecutor};
RuntimeBuilder::new()
.name_prefix("rpc")
// sadly, some parts of our current rpc implemention block the jsonrpc's
// _socket-listening_ event loop for too long, due to (blocking) long IO or intesive CPU,
// causing no further processing of incoming requests and ultimatily innocent clients timing-out.
// So create a (shared) multi-threaded event_loop for jsonrpc and set its .threads() to 1,
// so that we avoid the single-threaded event loops from being created automatically by
// jsonrpc for threads when .threads(N > 1) is given.
let event_loop = {
tokio_01::runtime::Builder::new()
.core_threads(rpc_threads)
.name_prefix("sol-rpc-el")
.build()
.unwrap()
};
@ -384,7 +390,7 @@ impl JsonRpcService {
io,
move |_req: &hyper::Request<hyper::Body>| request_processor.clone(),
)
.event_loop_executor(runtime01.executor())
.event_loop_executor(event_loop.executor())
.threads(1)
.cors(DomainsValidation::AllowOnly(vec![
AccessControlAllowOrigin::Any,