-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use tokio runtime handle instead of TaskExecutor
abstraction
#9737
Conversation
Before this pr we had the `TaskExecutor` abstraction which theoretically allowed that any futures executor could have been used. However, this was never tested and is currently not really required. Anyone running a node currently only used tokio and nothing else (because this was hard coded in CLI). So, this pr removes the `TaskExecutor` abstraction and relies directly on the tokio runtime handle. Besides this changes, this pr also makes sure that the http and ws rpc server use the same tokio runtime. This fixes a panic that occurred when you drop the rpc servers inside an async function (tokio doesn't like that a tokio runtime is dropped in the async context of another tokio runtime). As we don't use any custom runtime in the http rpc server anymore, this pr also removes the `rpc-http-threads` cli argument. If external parties complain that there aren't enough threads for the rpc server, we could bring support for increasing the thread count of the tokio runtime.
f774459
to
01b5a3f
Compare
client/rpc-servers/src/lib.rs
Outdated
.threads(1) | ||
.event_loop_executor(tokio_handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read the docs and checked the code.
I'm almost sure, but can someone confirm that this is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @tomusdrw but given https://docs.rs/jsonrpc-http-server/18.0.0/jsonrpc_http_server/struct.ServerBuilder.html#method.threads sounds correct to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By correct I mean that we are still answering requests in parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I was referring to
So it’s also possible to run a multi-threaded server by passing the default tokio::runtime executor to this builder and setting threads to 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my second comment was just to make my first one more clear xD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I believe so too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to review this properly. Ideally, this PR could use a burnin on a RPC node, but I'm not sure it's warranted.
I understand that we lose the TaskExecutor
abstraction here, that might worth adding back later, but that's probably out of scope here .
Other than that, looks good to me.
This custom http thread number wasn't used by us, I will ping the people that requested it.
It was currently not used anyway and I think it may also not worked with other executors, because hyper for example requires Tokio. However, as we will refactor a lot of things, this is one of the first things that would have been gone anyway.
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but yeah would good check with users of the --rpc http threads
bot merge |
Trying merge. |
* Remove event pallet::metadata attributes * Add scale-info deps, TypeInfo derives, update call variants * Update metadata runtime APIs * Add missing scale_info dependency, update rococo runtime API * Add missing scale_info dependency * Remove pushed diener patches * Cargo.lock * Add missing scale-info dependencies * Fixes * Statemint runtime fixes * Call struct variant empty matches * Add missing scale-info dependency * Fixes * scale-info 1.0 * cargo update -p xcm * update lock * Update Cargo.lock * update to latest polkadot * remove rpc_http_threads paritytech/substrate#9737 * replace task executor with tokio handler paritytech/substrate#9737 * fix test compilation? * Update Cargo.lock * cargo update * remove unused * Update substrate and polkadot * Update test/client/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Remove event pallet::metadata attributes * Add scale-info deps, TypeInfo derives, update call variants * Update metadata runtime APIs * Add missing scale_info dependency, update rococo runtime API * Add missing scale_info dependency * Remove pushed diener patches * Cargo.lock * Add missing scale-info dependencies * Fixes * Statemint runtime fixes * Call struct variant empty matches * Add missing scale-info dependency * Fixes * scale-info 1.0 * cargo update -p xcm * update lock * Update Cargo.lock * update to latest polkadot * remove rpc_http_threads paritytech/substrate#9737 * replace task executor with tokio handler paritytech/substrate#9737 * fix test compilation? * Update Cargo.lock * cargo update * remove unused * Update substrate and polkadot * Update test/client/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Remove event pallet::metadata attributes * Add scale-info deps, TypeInfo derives, update call variants * Update metadata runtime APIs * Add missing scale_info dependency, update rococo runtime API * Add missing scale_info dependency * Remove pushed diener patches * Cargo.lock * Add missing scale-info dependencies * Fixes * Statemint runtime fixes * Call struct variant empty matches * Add missing scale-info dependency * Fixes * scale-info 1.0 * cargo update -p xcm * update lock * Update Cargo.lock * update to latest polkadot * remove rpc_http_threads paritytech/substrate#9737 * replace task executor with tokio handler paritytech/substrate#9737 * fix test compilation? * Update Cargo.lock * cargo update * remove unused * Update substrate and polkadot * Update test/client/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Remove event pallet::metadata attributes * Add scale-info deps, TypeInfo derives, update call variants * Update metadata runtime APIs * Add missing scale_info dependency, update rococo runtime API * Add missing scale_info dependency * Remove pushed diener patches * Cargo.lock * Add missing scale-info dependencies * Fixes * Statemint runtime fixes * Call struct variant empty matches * Add missing scale-info dependency * Fixes * scale-info 1.0 * cargo update -p xcm * update lock * Update Cargo.lock * update to latest polkadot * remove rpc_http_threads paritytech/substrate#9737 * replace task executor with tokio handler paritytech/substrate#9737 * fix test compilation? * Update Cargo.lock * cargo update * remove unused * Update substrate and polkadot * Update test/client/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Before this pr we had the
TaskExecutor
abstraction which theoreticallyallowed that any futures executor could have been used. However, this
was never tested and is currently not really required. Anyone running a
node currently only used tokio and nothing else (because this was hard
coded in CLI). So, this pr removes the
TaskExecutor
abstraction andrelies directly on the tokio runtime handle.
Besides this changes, this pr also makes sure that the http and ws rpc
server use the same tokio runtime. This fixes a panic that occurred when
you drop the rpc servers inside an async function (tokio doesn't like
that a tokio runtime is dropped in the async context of another tokio
runtime).
As we don't use any custom runtime in the http rpc server anymore, this
pr also removes the
rpc-http-threads
cli argument. If external partiescomplain that there aren't enough threads for the rpc server, we could
bring support for increasing the thread count of the tokio runtime.
polkadot companion: paritytech/polkadot#3830