Possible performance improvement with tokio spawn inside main
Opened this issue · 0 comments
yanns commented
From https://users.rust-lang.org/t/why-tonic-not-good-in-beckmark-of-multi-core/70025/6
One of the things that's hurting Rust's performance in that particular benchmark is that the accept loop is running directly inside a call to block_on. This can be a performance problem because a tokio::spawn task will never run on the same thread as a block_on task, which means that all connections must be transferred to another Tokio thread before they can be processed.
As far as I understand the code, I think that we're good here, but I just want to make sure it's how I understand it.
The main is using block_on
as excepted:
let runtime = builder.build()?;
runtime.block_on(Executable::builder().start())
This is waiting for RouterHttpServer
let router = RouterHttpServer::builder()
.is_telemetry_disabled(opt.is_telemetry_disabled())
.configuration(configuration)
.and_uplink(uplink_config)
.schema(schema_source)
.license(license)
.shutdown(shutdown.unwrap_or(ShutdownSource::CtrlC))
.start();
if let Err(err) = router.await {
and this is using spawn
:
let listen_addresses = state_machine.listen_addresses.clone();
let result = spawn(
async move { state_machine.process_events(event_stream).await }
.with_current_subscriber(),
)