Skip to content

tokio bad performance #3155

Answered by luben
FH0 asked this question in Q&A
Discussion options

You must be logged in to vote

You are measuring different things here: your C example is single-threaded, your rust example is multi-threaded, and your test uses just 1 connection, so it cannot take advantage of the threads. Also the work on each connection is so small that I don't think it will change anything with using the multi-threaded runtime. So you are basically measuring the synchronization overhead. Try this one:

use tokio::net::TcpListener;
use tokio::prelude::*;
use tokio::runtime;

async fn accept_loop() {
    let listener = TcpListener::bind("0.0.0.0:8887").await.unwrap();

    loop {
        let (mut socket, _) = listener.accept().await.unwrap();

        tokio::spawn(async move {
            let mut bu…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by FH0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3155 on November 19, 2020 18:20.