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

Possible performance improvement with tokio spawn inside main #6212

Open
yanns opened this issue Oct 30, 2024 · 0 comments
Open

Possible performance improvement with tokio spawn inside main #6212

yanns opened this issue Oct 30, 2024 · 0 comments

Comments

@yanns
Copy link
Contributor

yanns commented Oct 30, 2024

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(),
        )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant